/CoffeeShopAPIs_EXALT

Coffee Shop APIs Project - for EXALT Training

Primary LanguagePython

Coffee Shop APIs Project - EXALT Training

Backend service for a coffee shop that manages the employees and allows them to take customer orders.

Features

  • Authentication and Authorization via a role-based control design pattern
  • Ability to perform CRUD shop on orders, employees, customers, items, and bills.

ER Diagram

CoffeeShopProjectERD

API Reference

Register a new employee

  POST /manager/employee

Request Body:

{
  "name": "Ahmad Ahmad",
  "phone_number": 0596581120,
  "role": "cashier",
  "username": "ahmad99",
  "password": "123"
}

Response:

{
  "message": "Created new Employee."
  "Employee":
    {
      "name": "Ahmad Ahmad",
      "phone_number": 0596581120,
      "join_date":'2022-09-01',
      "role": "cashier",
      "username": "ahmad99",
      "status": "Active"
    }
  
}

Login as an Employee

  POST /auth/login

Request Body:

{
  "username": "ahmad99",
  "password": "123"
}

Response:

{
  "access_token": "secret"
}

Get all employees

  GET /manager/employees
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Response:

[
  {
    "phone_number": 555,
    "id": 1,
    "role": "cashier"
    "name": "Ahmad Ahmad"
  },
  {
    "phone_number": 444,
    "id": 2,
    "role": "manager"
    "name": "David"
  }
]

Get employee

  GET /manager/employees/${employee_id}
Parameter Type Description
employee_id integer Required. Id of employee to fetch
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "phone_number": 555,
  "id": 1,
  "role": "cashier"
  "name": "Ahmad Ahmad",
  "status": "Active"
}

Update employee

  PUT /manager/employees/${employee_id}
Parameter Type Description
employee_id integer Required. Id of employee to update
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{
  "phone_number": 111,
  "name": "Ahmad Ahmad",
  "status": "Deactivated"
}

Response:

{
  "phone_number": 111,
  "id": 1,
  "name": "Ahmad Ahmad"
}

Get all items

  GET /shop/items
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Response:

[
  {
    "id": 1,
    "name": "Curry Chicken with Onion",
    "price": "$7.00"
  },
  {
    "id": 2,
    "name": "Chicken with Black Beans",
    "price": "$7.00"
  }
]

Create item

  POST /shop/items
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{
  "name": "Curry Chicken with Onion",
  "price": "$7.00"
}

Response:

{
  "id": 1,
  "name": "Curry Chicken with Onion",
  "price": "$7.00"
}

Delete item

  DELETE /shop/items/${item_id}
Parameter Type Description
item_id integer Required. Id of item to delete
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "id": 1,
  "name": "Curry Chicken with Onion",
  "price": "$7.00"
}

Get item

  GET /shop/items/${item_id}
Parameter Type Description
item_id integer Required. Id of item to fetch
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "id": 1,
  "name": "Curry Chicken with Onion",
  "price": "$7.00"
}

Update item

  PUT /shop/employees/${item_id}
Parameter Type Description
item_id integer Required. Id of item to update
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{
  "name": "Curry Chicken with Onion",
  "price": "$10.00"
}

Response:

{
  "id": 1,
  "name": "Curry Chicken with Onion",
  "price": "$10.00"
}

Get all customers

  GET /shop/customers
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Response:

[
  {
    "phone_number": 1,
    "id": 1,
    "name": "one"
  },
  {
    "phone_number": 2,
    "id": 2,
    "name": "two"
  }
]

Create customer

  POST /shop/customers
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{
  "phone_number": 3,
  "name": "Osama"
}

Response:

{
  "id": 3,
  "phone_number": 3,
  "name": "Osama"
}

Delete customer

  DELETE /shop/customers/${customer_id}
Parameter Type Description
customer_id integer Required. Id of customer to delete
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "id": 3,
  "phone_number": 3,
  "name": "Osama"
}

Get customer

  GET /shop/customers/${employee_id}
Parameter Type Description
customer_id integer Required. Id of customer to fetch
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "id": 3,
  "phone_number": 3,
  "name": "Osama" 
}

Update customer

  PUT /shop/customers/${customer_id}
Parameter Type Description
customer_id integer Required. Id of customer to update
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{ 
  "phone_number": 4,
  "name": "David"
}

Response:

{
  "id": 4,
  "phone_number": 4,
  "name": "David"
}

Get all orders

  GET /shop/orders
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Response:

[
 {
  "customer_id": 2,
  "employee_id": 5,
  "id": 7,
  "items_ordered": [
    {
      "description": "no salt",
      "item_id": 1,
      "quantity": 1
    }
  ],
  "order_time": "2022-07-25T07:20:08.023003",
  "status": "in Progress"
},
{
  "customer_id": 1,
  "employee_id": 2,
  "id": 12,
  "items_ordered": [
    {
      "description": "A LOT OF SALT",
      "item_id": 5,
      "quantity": 2
    },
    {
      "description": "NO SUGAR",
      "item_id": 4,
      "quantity": 2
    }
  ],
  "order_time": "2022-07-25T07:20:08.023003",
  "status": "in Progress"
]

Create order

  POST /shop/orders
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{
  "customer_id": 2,
  "employee_id": 3,
  "items_ordered": [
    {
      "description": "extra salt",
      "item_id": 3,
      "quantity": 2
    }
  ],
  "status": "in Progress"
}

Response:

{
  "customer_id": 2,
  "employee_id": 1,
  "id": 19,
  "items_ordered": [
    {
      "description": "extra salt",
      "item_id": 3,
      "quantity": 2
    }
  ],
  "order_time": "2022-07-25T10:12:40.397597",
  "status": "in Progress"
}

Delete order

  DELETE /shop/orders/${order_id}
Parameter Type Description
order_id integer Required. Id of order to delete
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "customer_id": 2,
  "employee_id": 1,
  "id": 19,
  "items_ordered": [
    {
      "description": "extra salt",
      "item_id": 3,
      "quantity": 2
    }
  ],
  "order_time": "2022-07-25T10:12:40.397597",
  "status": "Canceled"
}

Get order

  GET /shop/orders/${order_id}
Parameter Type Description
order_id integer Required. Id of order to fetch
Token Bearer Token Required. JWT of an authorized employee

Response:

{
  "customer_id": 1,
  "employee_id": 2,
  "id": 12,
  "items_ordered": [
    {
      "description": "A LOT OF SALT",
      "item_id": 5,
      "quantity": 2
    },
    {
      "description": "NO SUGAR",
      "item_id": 4,
      "quantity": 2
    }
  ],
  "order_time": "2022-07-25T07:44:11.668169",
  "status": "in Progress"
}

Update order

  PUT /shop/orders/${order_id}
Parameter Type Description
order_id integer Required. Id of order to update
Token Bearer Token Required. JWT of an authorized employee

Request Body:

{
  "customer_id": 1,
  "employee_id": 2,
  "items_ordered": [
    {
      "description": "chicken tika masala",
      "item_id": 1,
      "quantity": 2
    }
  ],  
  "status": "Done"
}

Response:

{
  "customer_id": 1,
  "employee_id": 2,
  "id": 12,
  "items_ordered": [
    {
      "description": "chicken tika masala",
      "item_id": 1,
      "quantity": 2
    }
  ],
  "order_time": "2022-07-25T07:44:11.668169",
  "status": "Done"
}

Read all bills

  GET /shop/bill
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Response:

[
    {
        "customer_id": 1,
        "employee_id": 1,
        "order_id": 1,
        "price": "12"
    },
    {
        "customer_id": 1,
        "employee_id": 2,
        "order_id": 2,
        "price": "13"
    },
]

Get receipt

  GET /operation/bill/${order_id}
Parameter Type Description
Token Bearer Token Required. JWT of an authorized employee

Response:

{
    "customer_id": 1,
    "employee_id": 1,
    "order_id": 1,
    "price": "12"
}

Create receipt

  POST /shop/bill/${order_id}
Parameter Type Description
order_id integer Required. Id of order to find the receipt of
Token Bearer Token Required. JWT of an authorized employee
{
    "customer_id": 1,
    "employee_id": 1,
    "order_id": 1,
    "price": "$67.50"
}

Authors