There should be two tables in the database: for users and posts.
The users table should have the following columns:
- id (int, primary key)
- username (string)
- display_name (string)
- email (string)
- created_at (datetime)
The posts table should have the following columns:
- id (int, primary key)
- user_id (int, foreign key to user.id)
- content (string)
- created_at (datetime)
The API is designed to make this workflow possible:
GET /posts: Get all postsGET /posts/{post_id}: Get details and content of a post
POST /signup: Create a new userPOST /login: Login
POST /posts: Create a new postPUT /posts/{post_id}: Update a postDELETE /posts/{post_id}: Delete a postGET /users: Get all users
The API should be accept and return JSON data. Specification (in Python syntax) is as follows:
-
GET /posts:- Request:
None - Good Response:
{ "status": "ok", "posts": [ ... ] } - Error Response:
{ "status": "error", "message": str }
- Request:
-
GET /posts/{post_id}:- Request:
None - Good Response:
{ "status": "ok", "post": { "id": int, "user": { "id": int, "username": str, "display_name": str | None }, "content": str, "created_at": str } }- Error Response: same as above
- Request:
-
POST /signup:- Request:
{ "username": str, "email": str, "display_name": str | None } - Good Response:
{ "status": "ok", "user_id": int, "username": str, "display_name": str | None, "token": str } - Error Response: same as above
- Request:
-
POST /login:- Request:
{ "username": str, "email": str } - Good Response:
{ "status": "ok", "user_id": int, "username": str, "display_name": str | None, "token": str } - Error Response: same as above
- Request:
-
POST /logout:- Request:
{ "user_id": int, "token": str } - Good Response:
{ "status": "ok" } - Error Response: same as above
- Request:
-
POST /posts:- Request:
{ "user_id": int, "content": str, "token": str } - Good Response:
{ "status": "ok", "post_id": int } - Error Response: same as above
- Request:
-
PUT /posts/{post_id}:- Request:
{ "user_id": int, "content": str, "token": str } - Good Response:
{ "status": "ok", "post_id": int } - Error Response: same as above
- Request:
-
DELETE /posts/{post_id}:- Request:
{ "user_id": int, "token": str } - Good Response:
{ "status": "ok", "post_id": int } - Error Response: same as above
- Request: