hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
182 stars 105 forks source link

[FEAT] - API endpoint to [GET] user notifications. #49

Closed iamhammyboi19 closed 2 weeks ago

iamhammyboi19 commented 1 month ago

Description

Create an API endpoint to get user notifications.

Acceptance Criteria

1.⁠ ⁠The endpoint must accept a HTTP GET method. 2.⁠ ⁠The user must be authenticated. 3.⁠ ⁠The endpoint must retrieve user notifications from the database using the provided user's ID. 4.⁠ ⁠The endpoint should return a 200 OK status code with the notifications in the body. 5.⁠ ⁠The endpoint should support pagination via parameter page and page size

Authorization

{ headers : Bearer {{token}}}

Request Example

GET /api/user/{userId}/notifications?page=1&page_size=5 No request body is needed for this endpoint.

Responses

Successful response

{
  status: "success",
  message: "Notification fetched successfully",
  data: {
    notification: [
      {
        id: "string",
        description: "string",
        is_viewed: boolean,
        created_at: Date,
      },
      // other notifications
    ],
    paginations: {
      current_page: 1,
      page_size: 5,
      total_size: 10,
      total_items_fetched: 100,
    },
  },
};

Error response

{
“status”:”failed”,
“message”:”failed to fetch user’s notifications”,
“statusCode”: 400,
“error”:”bad request”
}

Purpose

Provides a backend service that allows a user to access notifications when the user performs an activity.

Requirements

Expected Outcome

The endpoint ensures that users receive notifications at the end of an activity.

Status codes

Testing

markessien commented 1 month ago

Data models are not tickets