relaxcore / shopping-list

Phoenix test project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heroku link

https://block-compare-test-app.herokuapp.com

Project Setup

Install Elixir

brew install elixir

Clone the repository

git@github.com:relaxcoredev/shopping-list.git
cd shopping-list

Update ENV variables

cp .env.example .env
# set all variables correctly
source .env

Install dependencies and setup Ecto

mix deps.get
mix ecto.setup

Start Your Pheonix server

mix phx.server

Now you can visit localhost:4000 from your browser.

Endpoints

All Items

GET /api/v1/items

Params:

filter[category] - category name

filter[bought] - true/false

sort[name] - asc/desc

sort[price] - asc/desc

Success Response:

{
  "data": [
    {
      "bought": false,
      "category": {
        "id": "d7c2f78f-c804-43d7-a20f-8c2ab8498fb7",
        "name": "Beverages"
      },
      "id": "631a4570-295c-4b0c-bc2d-4db0b5aace08",
      "name": "Coca-Cola",
      "price": 2.5
    }
  ]
}

Show Item

GET /api/v1/items/:item_id

Success Response:

{
  "data": {
    "bought": false,
    "category": {
      "id": "d7c2f78f-c804-43d7-a20f-8c2ab8498fb7",
      "name": "Beverages"
    },
    "id": "631a4570-295c-4b0c-bc2d-4db0b5aace08",
    "name": "Coca-Cola",
    "price": 2.5
  }
}

Error Response:

{
  "errors": {
    "detail": "Not Found"
  }
}

Create Item

POST /api/v1/items

Params:

name - item name

price - item price

category_id - item category_id. Categories list with IDs you can find at /api/v1/categories

Success Response:

{
  "data": {
    "bought": false,
    "category": {
      "id": "d7c2f78f-c804-43d7-a20f-8c2ab8498fb7",
      "name": "Beverages"
    },
    "id": "631a4570-295c-4b0c-bc2d-4db0b5aace08",
    "name": "Coca-Cola",
    "price": 2.5
  }
}

Error Response:

{
  "errors": {
    "name": [
      "can't be blank"
    ],
    "price": [
      "can't be blank"
    ]
  }
}

Update Item

PUT /api/v1/items/:item_id

All same as create action, except one extra param:

bought - true/false

Delete Item

DELETE /api/v1/items/:item_id

Success Response:

Status code 200 with no content

Error Response:

{
  "errors": {
    "detail": "Not Found"
  }
}

About

Phoenix test project


Languages

Language:Elixir 71.7%Language:CSS 19.8%Language:HTML 5.7%Language:JavaScript 2.8%