code4moldova/voluntar-backend

VB-17: Add endpoint for updating the status of a Notification

Opened this issue · 5 comments

when the user sees the notification, the status must change

to be done after #98

PUT /api/notifications
Media type: Application/json

RequestBody(required): Notification id as json

Responses:
201: Notification object created
Example value:

{
  "notification": "notification_id"
}

400: Bad request
Example value:

{
  "code": "string",
  "message": "string"
}

401: Unauthorized Access
Example value:
Unauthorized Access

Hi! After #98 I would like to take this issue.
Thank you!

Hi!
Suppose I need little help with this task.

There is NotificationUser model where we store which notification assigned to which user in a status.
So we have to update NotificationUser object when a user sees a notification.
If we send only "notification_id" that means that we update NotificationUser like all users have seen the notification.
Suppose it is not right and we need to update status for exact user and exact notification.
To do that I see two ways:

  1. Add to PUT /api/notifications JSON one more field - "user_is"
    It will look like this
    {
    "notification": "notification_id",
    "user_id": "user_id"
    }
    So we will send from front-end to back-end which user have seen which notification.

  2. We can use "id" from NotificationUser model, but for that we need to send "notification_user_id" from front-end.

Please check and approve which solution is more suitable.

My opinion: first case is better because it is more clean, but both cases require changes in front-end.

Thank you.

hi @serghei-rubailo , first method look ok for me. Also update the swagger.

actually, you have user_id from the current_user, the user have authenticated, so the user_id is known