mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat(coderd): add mark-all-as-read endpoint for inbox notifications (#16976)
[Resolve this issue](https://github.com/coder/internal/issues/506) Add a mark-all-as-read endpoint which is marking as read all notifications that are not read for the authenticated user. Also adds the DB logic.
This commit is contained in:
@ -344,3 +344,31 @@ func (api *API) updateInboxNotificationReadStatus(rw http.ResponseWriter, r *htt
|
||||
UnreadCount: int(unreadCount),
|
||||
})
|
||||
}
|
||||
|
||||
// markAllInboxNotificationsAsRead marks as read all unread notifications for authenticated user.
|
||||
// @Summary Mark all unread notifications as read
|
||||
// @ID mark-all-unread-notifications-as-read
|
||||
// @Security CoderSessionToken
|
||||
// @Tags Notifications
|
||||
// @Success 204
|
||||
// @Router /notifications/inbox/mark-all-as-read [put]
|
||||
func (api *API) markAllInboxNotificationsAsRead(rw http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
apikey = httpmw.APIKey(r)
|
||||
)
|
||||
|
||||
err := api.Database.MarkAllInboxNotificationsAsRead(ctx, database.MarkAllInboxNotificationsAsReadParams{
|
||||
UserID: apikey.UserID,
|
||||
ReadAt: sql.NullTime{Time: dbtime.Now(), Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
api.Logger.Error(ctx, "failed to mark all unread notifications as read", slog.Error(err))
|
||||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
||||
Message: "Failed to mark all unread notifications as read.",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
rw.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
Reference in New Issue
Block a user