Skip to content

C242-PS149/CC-Path-CatLoris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TrackMate API Documentation

Endpoint

  • Prodaction
https://c242-ps149-backend-api-748662833244.asia-southeast2.run.app
  • Development
http://localhost:3000/

Account

Register

  • Path
POST /auth/register
  • Body Request
{
  "user_id": int,
  "image": varchar || null,
  "fullname": varchar,
  "email": varchar,
  "password": varchar,
  "contact": varchar,
  "gender": varchar
}
  • Example Body Request
{
  "user_id": "1",
  "image": "",
  "fullname": "edodi",
  "email": "edodi@gmail.com",
  "password": "edodi321",
  "contact": "081248249070",
  "gender": "pria"
}
  • Response
{
  "error": bool,
  "status": string,
  "message": string,
  "data": {
    "userId": string
  }
}
  • Example Response
{
  "error": false,
  "status": "success",
  "message": "User berhasil ditambahkan",
  "data": {
    "userId": "1"
  }
}

Login

Login refers to get accessToken and refreshToken

  • Path
POST /auth/login
  • Body Request
{
  "email": varchar,
  "password": varchar
}
  • Example Body Request
{
  "email": "bamban@gmail.com",
  "password": "bambang321"
}
  • Response
{
    "error": bool,
    "message": string,
    "data": {
        "accessToken": varchar,
        "refreshToken": varchar
    }
}
  • Example Response
{
    "error": false,
    "message": "Login berhasil!",
    "data": {
        "accessToken": "........eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
        "refreshToken": ".......eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
    }
}

User Login Profile

  • Path
GET /auth/profile
  • Headers

go to Headers then enter the key and value (Authorization as key and Bearer (access_token) as value) <access_token> from previos login

Authorization: Bearer <access_token>
  • Response
{
  "error": bool,
  "status": string,
  "message": string,
  "data": {
    "user_id": int,
    "image": varchar || null,
    "fullname": varchar,
    "email": varchar,
    "contact": varchar,
    "gender": varchar
    }
}
  • Example Response
{
  "error": false,
  "status": "success",
  "message": "Profil user berhasil diambil 200.",
  "data": {
    "user_id": 1,
    "image": null, //will be null if not yet edited
    "fullname": "ova",
    "email": "ova@gmail.com",
    "contact": "081248290010",
    "gender": "female"
  }
}

Edit Profile

  • Path
PUT /auth/update
  • Headers
Authorization: Bearer <access_token>
  • Body Request
{
  "image": varchar || null,
  "fullname": varchar,
  "email": varchar,
  "contact": varchar,
  "gender": varchar
}
  • Example Body Request
{
  "image": "http//profile.com",
  "fullname": "eddiynano",
  "email": "eddiynano@gmail.com",
  "contact": "0812482212",
  "gender": "male"
}
  • Response
{
  "error": bool,
  "status": string,
  "message": string
}
  • Example Response
{
  "error": false,
  "status": "success",
  "message": "Profil berhasil diperbarui"
}

Update Acces Token

for security access token will be deleted in a short time, so use update refresh token to get it again.

  • Path
PUT /auth/refresh
  • Body Request
{
  "refreshToken": varchar
}
  • Example Body Request
{
  "refreshToken": "......ExiH5PV_GPyyJdG5cI7v9FqmtPip9C0wdpYzqohjhw0"
}
  • Response
{
    "error": bool,
    "status": string,
    "message": string,
    "data": {
        "accessToken": varchar
    }
}
  • Example Response
{
  "error": false,
  "status": "success",
  "message": "Access Token berhasil diperbarui",
  "data": {
    "accessToken": "....jPdJLMZuN-MUYtc0wBItdxVbY2s9UidYxANqV560O6M"
  }
}

Logout

Logout refers to delete refreh token

  • Path
DELETE /auth/logout
  • Body Request
{
  "refreshToken": varchar
}
  • Example Body Request
{
  "refreshToken": "....ExiH5PV_GPyyJdG5cI7v9FqmtPip9C0wdpYzqohjhw0"
}
  • Response
{
  "error": bool,
  "status": string,
  "message": string
}
  • Example Response
{
  "error": false,
  "status": "success",
  "message": "Refresh token berhasil dihapus"
}

Delete account

  • Path
DELETE /auth/delete

delete acount not delete refresh token, so please send request to delete refresh token also to logout after delete account

  • Headers
Authorization: Bearer <access_token>
  • Response
{
    "error": bool,
    "status": string,
    "message": string,
    "data": {
        "userId": string
    }
}
  • Example Response
{
    "error": false,
    "status": "success",
    "message": "User berhasil ditambahkan 201.",
    "data": {
        "userId": "1"
    }
}

User Physical Metrics

Add New Metrics

  • Path
POST /metrics/user
  • Headers
Authorization: Bearer <access_token>
  • Body Request
{
  "age": int,
  "height": float,
  "weight": float,
  "fats": float
}
  • Example Body Request
{
  "age": 25,
  "height": 170.5,
  "weight": 65.3,
  "fats": 18.2
}
  • Response
{
  "error": bool,
  "message": string
}
  • Example Response
{
  "error": false,
  "message": "User berhasil ditambahkan"
}

Get All User Metrics

  • Path
GET /metrics/all
  • Response
[
  {
    "id": int,
    "user_id": int,
    "age": int,
    "height": float,
    "weight": float,
    "fats": float
  }
]
  • Example Response
[
  {
    "id": 1,
    "user_id": 101,
    "age": 25,
    "height": 170.5,
    "weight": 65.3,
    "fats": 18.2
  },
  {
    "id": 2,
    "user_id": 102,
    "age": 30,
    "height": 165.0,
    "weight": 70.0,
    "fats": 20.0
  }
]

Get User Metrics

  • Path
GET /metrics/user
  • Headers
Authorization: Bearer <access_token>
  • Response
{
  "id": int,
  "user_id": int,
  "age": int,
  "height": float,
  "weight": float,
  "fats": float
}
  • Example Response
{
  "user_id": 101,
  "age": 25,
  "height": 170.5,
  "weight": 65.3,
  "fats": 18.2
}

DELETE User Metrics

  • Path
GET /metrics/delete
  • Headers
Authorization: Bearer <access_token>
  • Response
{
  "id": int,
  "user_id": int,
  "age": int,
  "height": float,
  "weight": float,
  "fats": float
}
  • Example Response
{
  "user_id": 101,
  "age": 25,
  "height": 170.5,
  "weight": 65.3,
  "fats": 18.2
}

Users Foods

Get All User Foods

  • Path
GET /food/user
  • Response
{
  "error": bool,
  "message": string,
  "data": [
    {
      "food_id": int,
      "user_id": int,
      "food_name": string,
      "calories": float,
      "protein": float,
      "fats": float,
      "crabs": float,
      "created_at": datetime
    }
  ]
}
  • Example Response
{
  "error": false,
  "message": "User foods fetched successfully",
  "data": [
    {
      "food_id": 1,
      "user_id": 101,
      "food_name": "Grilled Chicken",
      "calories": 200,
      "protein": 25,
      "fats": 5,
      "crabs": 21
    },
    {
      "food_id": 2,
      "user_id": 102,
      "food_name": "Apple",
      "calories": 52,
      "protein": 0.3,
      "fats": 0.2,
      "crabs": 14
    }
  ]
}

GET User Food

  • Path
GET /food/user
  • Headers
Authorization: Bearer <access_token>
  • Response
{
  "error": bool,
  "message": string,
  "data": {
    "food_id": int,
    "user_id": int,
    "food_name": string,
    "calories": float,
    "protein": float,
    "fats": float,
    "crabs": float
    "created_at": datetime
  }
}
  • Example Response
{
    "error": false,
    "message": "User foods fetched successfully",
    "data": [
        {
            "food_id": 8,
            "user_id": 7,
            "food_name": "Salmon",
            "calories": 208,
            "protein": 20,
            "fats": 13,
            "crabs": 21,
            "created_at": "2024-12-01T00:47:24.000Z"
        }
    ]
}

POST a New User Food

  • Path
POST /food/user
  • Headers
Authorization: Bearer <access_token>
  • Request
{
    "food_name": string,
    "calories": decimal,
    "protein": decimal,
    "fats": decimal,
    "crabs": decimal
}
  • Example Request
{
  "user_id": 1,
  "food_name": "Salmon",
  "calories": 208,
  "protein": 20,
  "fats": 13,
  "crabs": 20
}
  • Response
{
  "error": bool,
  "message": string,
  "data": {
    "food_id": int,
    "user_id": int,
    "food_name": string,
    "calories": float,
    "protein": float,
    "fats": float,
    "crabs": float,
    "created_at": datetime
  }
}
  • Example Response
{
    "error": false,
    "message": "User food added successfully",
    "data": {
        "food_id": 8,
        "user_id": 7,
        "food_name": "Salmon",
        "calories": 208,
        "protein": 20,
        "fats": 13,
        "crabs": 21,
        "created_at": "2024-12-01T00:47:24.000Z"
    }
}

Delete User Foods

User Point

GET ALL users points

  • Path
GET /points/user
  • Response
[
  {
    "id": int,
    "user_id": int,
    "points": int,
    "reason": varchar,
    "created_at": datetime,
    "updated_at": datetime
  }
]
  • Example Response
[
  {
    "id": 1,
    "user_id": 1,
    "points": 100,
    "reason": "Referral bonus",
    "created_at": "2024-11-29T12:00:00Z",
    "updated_at": "2024-11-29T12:00:00Z"
  },
  {
    "id": 2,
    "user_id": 2,
    "points": 50,
    "reason": "Reward for completing survey",
    "created_at": "2024-11-29T13:00:00Z",
    "updated_at": "2024-11-29T13:00:00Z"
  }
]

GET User Point By ID

  • Path
GET /points/:user_id
  • Request

To display data based on the id

  • Response
[
  {
    "id": int,
    "user_id": int,
    "points": int,
    "reason": varchar,
    "created_at": datetime,
    "updated_at": datetime
  }
]
  • Example Response
[
  {
    "id": 1,
    "user_id": 1,
    "points": 100,
    "reason": "Referral bonus",
    "created_at": "2024-11-29T12:00:00Z",
    "updated_at": "2024-11-29T12:00:00Z"
  }
]

GET User Total Point By ID

Retrieves total points based on user_id

  • Path
GET /points/total/:user_id
  • Response
{
  "total_points": 150
}

POST User Points

Adds points for already authenticated users.

  • Path
POST /points/user
  • Headers
Authorization: Bearer <accessToken>
  • Request
{
  "points": int,
  "reason": varchar
}
  • Example Request
{
  "points": 100,
  "reason": "Well done !!!"
}
  • Response
{
    "message": string,
    "insertId": int
}
  • Example Response
{
    "message": "Point added successfully",
    "insertId": 7
}

PUT User Point By ID

Updates point entries based on Authorization.

  • Path
PUT /points/user
  • Headers
Authorization: Bearer <accessToken>
  • Request
{
  "points": int,
  "reason": string
}
  • Example Request
{
  "points": 120,
  "reason": "Updated reward"
}
  • Response
{
  "message": string
}
  • Example Response
{
  "message": "Point updated successfully"
}

DELETE Point

  • Path
DELETE /points/delete
  • Headers
Authorization: Bearer <accessToken>
  • Response
{
  "message": string
}
  • Example Response
{
  "message": "Point deleted successfully"
}

Public Article

Create Article

  • Path
POST /articles/health
  • Response
{
  "title": string,
  "content": string,
  "image_url": varchar
}
  • Example Response
{
  "title": "Article Title",
  "content": "Article Content",
  "image_url": "http://example.com/image.jpg"
}

Get All Article

  • Path
GET /articles/health
  • Request
{
  "error": bool,
  "message": string,
  "data": [
    {
      "article_id": int,
      "title": varchar,
      "content": varchar,
      "published_date": datetime,
      "image_url": varchar
    }
  ]
}
  • Example Request
{
  "error": false,
  "message": "Artikel berhasil diambil.",
  "data": [
    {
      "article_id": 1,
      "title": "Article 1",
      "content": "Content for article 1",
      "published_date": "2024-12-01 12:00:00",
      "image_url": "http://example.com/article1.jpg"
    },
    {
      "article_id": 2,
      "title": "Article 2",
      "content": "Content for article 2",
      "published_date": "2024-12-01 12:00:00",
      "image_url": "http://example.com/article2.jpg"
    }
  ]
}

Get Article By ID

  • Path
GET /articles/:article_id
  • Response
{
  "error": false,
  "message": "Artikel berhasil diambil.",
  "data": {
    "article_id": 1,
    "title": "Article 1",
    "content": "Content for article 1",
    "published_date": "2024-12-01 12:00:00",
    "image_url": "http://example.com/article1.jpg"
  }
}

Update Article By ID

  • Path
PUT /articles/:article_id
  • Request
{
  "title": "Updated Title",
  "content": "Updated Content",
  "published_date": "2024-12-01T12:00:00",
  "image_url": "http://example.com/updated_image.jpg"
}
  • Response
{
  "error": false,
  "message": "Artikel berhasil diperbarui."
}

Delete Article By ID

  • Path
DELETE /articles/:article_id
  • Response
{
  "error": false,
  "message": "Artikel berhasil dihapus."
}

About

Project Bangkit 2024

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors