Skip to content

Latest commit

 

History

History
501 lines (391 loc) · 7.54 KB

api_docs.md

File metadata and controls

501 lines (391 loc) · 7.54 KB

TukarMainan API Documentation

Endpoints

List of Available Endpoints:

Admin CMS Endpoints

  • PATCH /admins/update-password
  • GET /users
  • PATCH /users/:id/suspend
  • PATCH /posts/:id/archive
  • GET /reports
  • GET /adminlogs
  • POST /categories
  • PATCH /categories/:id

Authorize User Endpoints

  • PATCH /users/update-password
  • PUT /users/:id
  • POST /posts
  • PUT /posts/:id
  • PATCH /posts/:id
  • GET /notifications
  • GET /chats
  • POST /chats
  • GET /messages
  • POST /messages
  • POST /comments
  • POST /reports

Public Endpoints

  • POST /admins/login
  • POST /admins/register
  • POST /users/login
  • POST /users/login/google
  • POST /users/register
  • GET /public/users/:id
  • GET /public/posts
  • GET /public/posts/:id
  • GET /public/posts/nearby
  • GET /public/categories
  • GET /public/categories/:id

POST /auth/users/login

Description

  • Verify an user then give jwt_token

Request

  • Body
    {
        "username": < username: String > || < email: String >,
        "password": String
    }

Response

200 - OK

  • Body
    {
        "access_token": String,
        "id": UUID,
        "username": String,
        "email": String
    }

400 - Bad Request

  • Body
    {
        "message": "Input is required"
    }

401 - Unauthorized

  • Body
    {
        "message": "Unauthorized"
    }

POST /auth/users/register

Description

  • Create new user account

Request

  • Body
    {
        "username": String,
        "email": String,
        "password": String,
        "city": String
    }

Response

201 - Created

  • Body
    {
        "message": String
    }

400 - Bad Request

  • Body
    {
        "message": < sequelize_validation_error: String >
    }

409 - Conflict

  • Body
    {
        "message": < sequelize_validation_error: String >
    }

POST /auth/users/updatePassword

Description

  • Update an existing user password

Request

  • Headers
    {
      "access_token": < user_jwt_token: String >
    }
  • Body
    {
        "newpassword": String,
        "oldpassword": String
    }

Response

200 - OK

  • Body
    {
        "message": String
    }

400 - Bad Request

  • Body
    {
        "message": < sequelize_validation_error: String >
    }

401 - Unauthorized

  • Body
    {
        "message": "Unauthorized"
    }

404 - NotFound

  • Body
    {
        "message": String
    }

POST /auth/admins/login

Description

  • Verify an admin then give jwt_token

Request

  • Body
    {
        "username": < username: String > || < email: String >,
        "password": String
    }

Response

200 - OK

  • Body
    {
        "access_token": String,
        "id": UUID,
        "username": String,
        "email": String
    }

400 - Bad Request

  • Body
    {
        "message": "Input is required"
    }

401 - Unauthorized

  • Body
    {
        "message": "Unauthorized"
    }

POST /auth/admins/register

Description

  • Create new admin account

Request

  • Headers
    {
      "access_token": < admin_jwt_token: String >
    }
  • Body
    {
        "username": String,
        "email": String,
        "password": String
    }

Response

201 - Created

  • Body
    {
        "message": String
    }

400 - Bad Request

  • Body
    {
        "message": < sequelize_validation_error: String >
    }

409 - Conflict

  • Body
    {
        "message": < sequelize_validation_error: String >
    }

POST /auth/admins/updatePassword

Description

  • Update an existing admin password

Request

  • Headers
    {
      "access_token": < admin_jwt_token: String >
    }
  • Body
    {
        "newpassword": String,
        "oldpassword": String
    }

Response

200 - OK

  • Body
    {
        "message": String
    }

400 - Bad Request

  • Body
    {
        "message": < sequelize_validation_error: String >
    }

401 - Unauthorized

  • Body
    {
        "message": "Unauthorized"
    }

404 - NotFound

  • Body
    {
        "message": String
    }

GET /users

Description

  • Get all users

Request

  • Headers
    {
      "access_token": < admin_jwt_token: String >
    }

Response

200 - OK

  • Body
    [
        {
            "id": UUID,
            "email": String,
            "username": String,
            "profileImg": String,
            "name": String,
            "notes": String,
            "phoneNumber": String,
            "status": Enum(["unverified", "verified", "suspend", "premium"]),
            "city": String,
            "ratings": Integer,
            "warningCount": Integer,
            "createdAt": Date,
            "updatedAt": Date
        },
        ...
    ]

GET /public/users/:id

Description

  • Get an user profile data based on given id

Request

Response

200 - OK

  • Body

    [
        {
            "id": UUID,
            "email": String,
            "username": String,
            "profileImg": String,
            "name": String,
            "notes": String,
            "phoneNumber": String,
            "status": Enum(["unverified", "verified", "suspend", "premium"]),
            "city": String,
            "ratings": Integer,
            "createdAt": Date,
            "updatedAt": Date,
            "Posts": [
                {
                    "id": UUID,
                    "title": String,
                    "condition": Enum(["brand new", "like new", "lightly used", "well used", "heavily used"]),
                    "status": Enum(["active", "inactive", "complete", "suspend"]),
                    "images": [ String ],
                    "price": Integer,
                    "createdAt": Date,
                    "updatedAt": Date,
                    "Category": {
                        "id": UUID,
                        "name": String
                    }
                },
                ...
            ],
            "Reviews": [
                {
                    "id": UUID,
                    "message": String,
                    "createdAt": Date,
                    "updatedAt": Date,
                    "Sender": {
                        "id": UUID,
                        "username": String,
                        "profileImg": String
                    }
                },
                ...
            ]
        },
        ...
    ]

Middlewares Authentication and Authorization Error

Response

401 - Unauthorized

  • Body
    {
        "message": "Unauthorized"
    }

403 - Forbidden

  • Body
    {
        "message": "Forbidden access"
    }

Global Error

Response

500 - Internal Server Error

  • Body
    {
        "message": "Internal Server Error"
    }