Saiga home assignment
This is a simple tasks API. It is fully dockerized.
Table of contents
1 Response Data format
2 Authorization
3 API
3.1 Get all tasks
3.2 Get task history
3.3 Download file attached to message
4 Requirements
5 Deploy
Response data format: JSON
Sample error response:
{
"title": "invalid parameter",
"description": "task ID parameter must be positive"
}
2. Authorization
Authorization: Basic Auth
In this task we implement role based access control with basic auth in sake of simplicity.
Although there're some libraries providing a better way of handling RBAC.
For example casbin: https://github.com/casbin/casbin
3. API
3.1 Get all tasks
This endpoint is used to get a list of all tasks.
URL:
.../api/v1/tasks
METHOD: GET
Status codes:
200
- OK,
500
- server error,
Response Body
[
{
"id": 1, // id of a task, int
"user_id": 1, // id of user who created a task, int
"name": "task one", // task name, string
"category_id": "find a doctor", // id of a task category, int
"status_id": 1, // id of a task status, int
"started_at": "2022-02-02T19:41:32.213348121+03:00", // date when a task started, datetime
"updated_at": "2022-02-02T19:41:32.21334819+03:00" // date when a task was last updated, datetime
},
...
]
3.2 Get task history
This endpoint is used to receive chat history for a task.
URL:
.../api/v1/tasks/{taskID}/history
METHOD: GET
URL parameters:
taskID
- int, id of a task
Status codes:
200
- OK,
400
- bad request (invalid request body)
500
- server error,
Response Body
[
{
"id": 1, // id of a message, int
"task_id": 1, // if of a task to which the message is related, int
"from_user_id": 1, // id of a user who wrote the message, int
"message_text": "message one", // contents of message, string
"file_key": "fileone.txt", // s3 key to a file attached to the message, string
"created_at": "2022-02-02T19:52:56.115236415+03:00" // date when the message was created, datetime
},
...
]
3.3 Download file attached to message
This endpoint is used to download file attached to message.
URL:
.../api/v1/messages/{messageID}/history
METHOD: GET
URL parameters:
messageID
- int, id of a message
Status codes:
200
- OK,
400
- bad request (invalid request body)
500
- server error,
Response Body
The file that was attached to the message or nothing if there was no file attached.
4. Requirements
docker
docker-compose
5. Deploy
- Clone this repository.
- Create container with
docker-compose -f docker-compose.yml up -d
- Server will start running.