Skip to content

Latest commit

 

History

History
605 lines (439 loc) · 7 KB

File metadata and controls

605 lines (439 loc) · 7 KB

API Documentation

Endpoints

Public Endpoints

  • POST /register
  • POST /login
  • POST /login/google

Protected Endpoints

Endpoints yang hanya bisa diakses oleh users yang sudah login

  • GET /monster
  • GET /monster/:id
  • GET /monster/:id/imgUrl
  • GET /favorites
  • POST /favorites
  • DELETE /favorites/:monsterId
  • POST /gemini

1. POST /register

Description:

  • Endpoint untuk mendaftarkan user baru dengan username, email, dan password.

Request:

  • body:
{
  "username": "string",
  "email": "string",
  "password": "string"
}

Response:

  • 201 - Created:
{
  "id": "integer",
  "username": "string",
  "email": "string"
}
  • 400 - BadRequest:
{
  "message": "Email is required"
}

or

{
  "message": "Password is required"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

2. POST /login

Description:

  • Endpoint untuk autentikasi user dan menghasilkan token.

Request:

  • body:
{
  "email": "string",
  "password": "string"
}

Response:

  • 200 - OK:
{
  "access_token": "string",
  "userId": "integer"
}
  • 400 - BadRequest:
{
  "message": "Email is required"
}

or

{
  "message": "Password is required"
}
  • 401 - Unauthorized:
{
  "message": "Invalid email/password"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

3. POST /login/google

Description:

  • Endpoint untuk autentikasi menggunakan akun Google.

Request:

  • body:
{
  "googleToken": "string"
}

Response:

  • 200 - OK:
{
  "access_token": "string",
  "message": "Login successful"
}
  • 400 - BadRequest:
{
  "message": "Google token is required"
}
  • 401 - Unauthorized:
{
  "message": "Invalid Google token"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

4. GET /monsters

Description:

  • Mengambil daftar monster dengan opsi pencarian, pagination, filter dan sorting.

Request:

  • headers:
{
  "Authorization": "Bearer <access_token>"
}
  • page (optional): Nomor halaman untuk pagination.
  • page (optional): Jumlah item per halaman.
  • q (optional): Query string untuk pencarian karakter.
  • sort (optional): Pengurutan monster berdasarkan abjad {name}.

Response:

  • 200 - OK:
{
  "data": [
    {
      "id": "string",
      "type": "string",
      "species": "string",
      "name": "string",
      "description": "string",
      "imageUrl": "string"
    },
    ...
  ],
  "totalPages": "integer",
  "currentPage": "integer",
  "totalData": "integer",
  "dataPerPage": "integer"
}
  • 401 - Unauthorized:
{
  "message": "Invalid Token"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

5. GET /monsters/:id

Description:

  • Mengambil detail monster berdasarkan ID.

Request:

  • headers:
{
  "Authorization": "Bearer <access_token>"
}
  • Params:
{
  "id": "integer (required)"
}

Response:

  • 200 - OK:
{
  "data": {
    "id": "integer",
    "type": "string",
    "species": "string",
    "name": "string",
    "description": "string",
    "imageUrl": "string"
  }
}
  • 401 - Unauthorized:
{
  "message": "Invalid Token"
}
  • 404 - NotFound:
{
  "message": "Monster with id: {id} is not found"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

6. PATCH /monsters/:id/imgUrl

Description:

  • Memperbarui gambar monster berdasarkan ID.

Request:

{
  "Authorization": "Bearer <access_token>"
}
  • Params:
{
  "file": "string (required)"
}
  • headers:

Response:

  • 200 - OK:
{
  "message": "Image url on monster with id: {id} has been updated"
}
  • 400 - BadRequest:
{
  "message": "Image URL is required"
}
  • 401 - Unauthorized:
{
  "message": "Invalid Token"
}
  • 404 - Not Found:
{
  "message": "Monster with id: {id} is not found"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

7. GET /favorites

Description:

  • Menampilkan monster yang ada di daftar favorite.

Request:

  • headers:
{
  "Authorization": "Bearer <access_token>"
}

Response:

  • 200 - OK:
{
  "data": [
    {
      "userId": string,
      "monsterId": string,
       "type": string,
      "species": string,
      "name": string,
      "description": string,
      "imageUrl": string
    },
    ...
  ],
  "message": "success"
}
  • 401 - Unauthorized:
{
  "message": "Invalid Token"
}
  • 404 - Not Found:
{
  "message": "User with id: {id} is not found"
}
  • 500 - Internal Server Error:
{
  "message": "ISE"
}

8. POST /favorites

Description:

  • Menambahkan monster ke daftar favorite.

Request:

  • headers:
{
  "Authorization": "Bearer <access_token>"
}
  • Params:
{
  "monsterId": "integer (required)"
}

Response:

  • 201 - Created:
{
  "message": "Monster with id:{monsterId} has been successfully added to favorites"
}
  • 400 - Bad Request:
{
  "message": "This monster with id:{monsterId} is already in your favorites"
}
  • 404 - Not Found:
{
  "message": "User with id:{id} is not found",
  "message": "Monster with id:{monsterId} is not found"
}

500 - Internal Server Error:

{
  "message": "ISE"
}

9. DELETE /favorites

Description:

  • Menghapus monster dari daftar favorite.

Request:

  • headers:
{
  "Authorization": "Bearer <access_token>"
}
  • Params:
{
  "monsterId": "integer (required)"
}

Response:

  • 200 - OK:
{
  "message": "Monster with id:{monsterId} successfully removed from favorites"
}
  • 404 - Not Found:
{
  "message": "User with id:{id} is not found"
}

or

{
  "message": "Monster with id:{monsterId} is not found"
}

500 - Internal Server Error:

{
  "message": "ISE"
}

10. POST /gemini

Description:

  • Menghasilkan deskripsi monster menggunakan layanan AI berdasarkan nama monster yang diberikan.

Request:

  • headers:
{
  "Authorization": "Bearer <access_token>"
}
  • Params:
{
  "monsterName": "string (required)"
}
  • 200 - OK:
{
  "description": "string"
}
  • 400 - Bad Request:
{
  "message": "monsterName is required"
}

500 - Internal Server Error:

{
  "message": "ISE"
}