Skip to content

haikalgakbar/assignment03_api_design

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

API Design for Forum App

Requirement / User Stories

  • As a user, I want to be able to Register
  • As a user, I want to be able to Log In
  • As a user, I want to be able to Create new Thread
  • As a user, I want to be able to Create new Reply (on a Thread)
  • As a user I want to be able to Update my Personal profile
  • As a user, I want to be able to Save/Bookmark Threads
  • As a user, I want to be able to UnSave/UnBM Threads

Core Entity

User

name type
_id ObjectId
__v Number
email String
password String
user_name String
display_name String
avatar_url String?
bookmarks [thread: ObjectId(Thread)]?
BSON example
{
  "_id": "66372c69cc86e6b1c94167a7",
  "__v": 0,
  "email": "haikal@mail.com",
  "password": "haikal123",
  "user_name": "haikalgakbar",
  "display_name": "haikalgakbar",
  "avatar_url": "cdn.example.com/img/1.jpg",
  "bookmarks": [
    "663734b04bebd3fa7b61d0dd",
  ],
}

Thread

name type
_id ObjectId
__v Number
sender ObjectId(User)
title String
content String
img String?
comments [user: ObjectId(User), comment: String]?
BSON example
{
  "_id": "663734b04bebd3fa7b61d0dd",
  "__v": 0,
  "sender": "66372c69cc86e6b1c94167a7",
  "title": "Ngeri! Lorem Ipsum Sit Dolor Amet",
  "content": "Lorem ipsum sit dolor amet...",
  "img": "cdn.example.com/thread/img/1.jpg",
  "comments": [
    {
      "_id": "66373770d61386f174ef3d0a",
      "user": "66372d1bde7c834bb15f809b",
      "comment": "Lorem ipsum sit dolor amet",
    },
  ],
}

Endpoint

Auth

Name Method Endpoint
Register POST /auth/register
login POST /auth/login

Register

Request Body
{
  "email": "String" (required),
  "password": "String" (required),
  "user_name": "String" (required),
  "display_name": "String" (required),
}
Example Request Body
{
  "email": "haikal@mail.com",
  "password": "123",
  "user_name": "haikalgakbar",
  "display_name": "haikalgakbar",
}
Response
Type Status Code Message
Success 201 Add new user success.
Error in client 400 Invalid data. / Data must be string.
Error in server 500 Error from server.

Login

Request Body
{
  "email": "String" (required),
  "password": "String" (required),
}
Example Request Body
{
  "email": "haikal@mail.com",
  "password": "123",
}
Response
Type Status Code Message
Success 201 Login success.
Error in client 404 Incorrect email or password
Error in server 500 Error from server.

Thread

Name Method Endpoint
Create thread POST /thread
Create reply POST /thread/:id

Create thread

Request Body
{
  "sender": "ObjectId(User)" (required),
  "title": "String" (required),
  "content": "String" (required),
}
Example Request Body
{
  "sender": "66372ee9ddc309fdfffa1666",
  "title": "Ngeri! Lorem Ipsum Sit Dolor Amet",
  "content": "Lorem ipsum sit dolor amet...",
}
Response
Type Status Code Message
Success 201 Add new thread success.
Error in client 400 Invalid sender ID. / Sender not found. / Data must be in string.
Error in server 500 Error from server.

Create reply

Request Body
{
  "user": "ObjectId(User)" (required),
  "comment": "String" (required),
}
Example Request Body
{
  "user": "66372ee9ddc309fdfffa1666",
  "comment": "Lorem ipsum sit dolor amet...",
}
Response
Type Status Code Message
Success 201 Add new comment success.
Error in client 400 Invalid thread ID. / Invalid user ID. / Must include comment. / Comment must be in string.
Error in server 500 Error from server.

User

Name Method Endpoint
Update profile PATCH /user/:id
Bookmark thread PATCH /user/:id/bookmarks
Remove bookmark PATCH /user/:id/bookmarks

Update profile

Request Body
{
  "email": "String",
  "password": "String",
  "user_name": "String",
  "display_name": "String",
  "avatar_url": "String",
}
Example Request Body
{
  "email": "haikalgakbar@gmail",
  "password": "123",
  "user_name": "haikalgakbar",
  "display_name": "haikalgakbar",
  "avatar_url": "cdn.example.com/img/1.jpg",
}
Response
Result Status Code Message
Success 201 Update user success.
Error in client 400 Invalid ID. / User not found.
Error in server 500 Error from server.

Bookmark thread

Request Body
{
  "type": "String" (required),
  "thread": "ObjectId(Thread)" (required),
}
Example Request Body
{
  "type": "add",
  "thread": "66372ee9ddc309fdfffa1666",
}
Response
Type Status Code Message
Success 201 Bookmark added.
Error in client 400 Invalid user id. / User not found. / Invalid thread id. / Thread not found
Error in server 500 Error from server.

Remove bookmark

Request Body
{
  "type": "String" (required),
  "thread": "ObjectId(Thread)" (required),
}
Example Request Body
{
  "type": "remove",
  "thread": "66372ee9ddc309fdfffa1666",
}
Response
Type Status Code Message
Success 201 Bookmark removed.
Error in client 400 Invalid user id. / User not found. / Invalid thread id. / Thread not found
Error in server 500 Error from server.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published