Skip to content

Latest commit

 

History

History
182 lines (170 loc) · 3.63 KB

README.md

File metadata and controls

182 lines (170 loc) · 3.63 KB

The task descriptions

Develop a RESTful API service using your preferred web framework (such as FastAPI, Django, or Flask).
This service will offer CRUD operations for Client entities and their corresponding Requests entities.
Additionally, there will be an Operator entity responsible for
updating the Status of the Request entity.
Note that CRUD operations for the Operator entity are not required.
Utilize the Object-Relational Mapping (ORM) of your choice.
The basic structure of the entities should include the following fields:

Client:

  • Id
  • First Name
  • Last Name
  • Phone

Request:

  • Id
  • Body
  • Status (Pending, Completed, Rejected)
  • Processed By (Operator Id)

Operator:

  • Id
  • First Name
  • Last Name

Pre-requisites

Poetry is recommended to help manage the dependencies and virtualenv.

$ pip install poetry

Usage

Installing with Poetry

# Install packages with poetry
$ poetry install

Running

$ uvicorn customer_support_api.main:app

Playing around with REST API

You can make requests to API in swagger UI. open in browser http://127.0.0.1:8000/docs

REST API flow example:

Create customer

$ curl -X 'POST' \
  'http://127.0.0.1:8000/api/customers/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "first_name": "Ed",
  "last_name": "Stark",
  "phone": "+442083661171"
}
{
  "first_name": "Ed",
  "last_name": "Stark",
  "phone": "+442083661171",
  "id": 1
}

Create operator

$ curl -X 'POST' \
  'http://127.0.0.1:8000/api/operators/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "first_name": "Jennie",
  "last_name": "Lanister"
}'
{
  "first_name": "Jennie",
  "last_name": "Lanister",
  "id": 1
}

Create request

$ curl -X 'POST' \
  'http://127.0.0.1:8000/api/customers/1/requests' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "body": "Winter is coming"
}'
{
  "body": "Winter is coming",
  "id": 1,
  "created_by": 1,
  "status": "PENDING",
  "processed_by": null,
  "resolution_comment": null
}

Assign request to operator

$ curl -X 'PATCH' \
  'http://127.0.0.1:8000/api/operators/1/requests/1' \
  -H 'accept: application/json'
{
  "body": "Winter is coming",
  "id": 1,
  "created_by": 1,
  "status": "IN_PROGRESS",
  "processed_by": 1,
  "resolution_comment": null
}

Complete request

curl -X 'PATCH' \
  'http://127.0.0.1:8000/api/requests/1' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "status": "COMPLETED",
  "resolution_comment": "Keep yourself warm"
}'
{
  "body": "Winter is coming",
  "id": 1,
  "created_by": 1,
  "status": "COMPLETED",
  "processed_by": 1,
  "resolution_comment": "Keep yourself warm"
}

Get requests by customer

curl -X 'GET' \
  'http://127.0.0.1:8000/api/customers/1/requests' \
  -H 'accept: application/json'
[
  {
    "body": "Winter is coming",
    "id": 1,
    "created_by": 1,
    "status": "COMPLETED",
    "processed_by": 1,
    "resolution_comment": "Keep yourself warm"
  }
]

Delete (Archive) request

curl -X 'DELETE' \
  'http://127.0.0.1:8000/api/requests/1' \
  -H 'accept: */*'

TODOS:

There several feature to be done for production ready API:

  • Alembic migrations
  • .env configuration for different environments
  • Dockerfile for deployment into docker-compose/Kubernetes
  • API test coverage. For the moment CRUD test coverage is implemented
  • HATEOAS for endpoints that return multiple entries
  • Versioning of the API