@@ -41,6 +41,7 @@ func NewUserHandler(
4141func (h * UserHandler ) RegisterRoutes (router fiber.Router ) {
4242 router .Get ("/users/me" , h .Show )
4343 router .Put ("/users/me" , h .Update )
44+ router .Put ("/users/:userID/notifications" , h .UpdateNotifications )
4445 router .Get ("/users/subscription-update-url" , h .subscriptionUpdateURL )
4546 router .Delete ("/users/subscription" , h .cancelSubscription )
4647}
@@ -119,6 +120,43 @@ func (h *UserHandler) Update(c *fiber.Ctx) error {
119120 return h .responseOK (c , "user updated successfully" , user )
120121}
121122
123+ // UpdateNotifications an entities.User
124+ // @Summary Update notification settings
125+ // @Description Update the email notification settings for a user
126+ // @Security ApiKeyAuth
127+ // @Tags Users
128+ // @Accept json
129+ // @Produce json
130+ // @Param payload body requests.UserNotificationUpdate true "Payload of user notification details to update"
131+ // @Success 200 {object} responses.UserResponse
132+ // @Failure 400 {object} responses.BadRequest
133+ // @Failure 401 {object} responses.Unauthorized
134+ // @Failure 422 {object} responses.UnprocessableEntity
135+ // @Failure 500 {object} responses.InternalServerError
136+ // @Router /users/{userID}/notifications [put]
137+ func (h * UserHandler ) UpdateNotifications (c * fiber.Ctx ) error {
138+ ctx , span := h .tracer .StartFromFiberCtx (c )
139+ defer span .End ()
140+
141+ ctxLogger := h .tracer .CtxLogger (h .logger , span )
142+
143+ var request requests.UserNotificationUpdate
144+ if err := c .BodyParser (& request ); err != nil {
145+ msg := fmt .Sprintf ("cannot marshall params [%s] into %T" , c .OriginalURL (), request )
146+ ctxLogger .Warn (stacktrace .Propagate (err , msg ))
147+ return h .responseBadRequest (c , err )
148+ }
149+
150+ user , err := h .service .UpdateNotificationSettings (ctx , h .userIDFomContext (c ), request .ToUserNotificationUpdateParams ())
151+ if err != nil {
152+ msg := fmt .Sprintf ("cannot update notification for [%T] with ID [%s]" , user , h .userIDFomContext (c ))
153+ ctxLogger .Error (h .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg )))
154+ return h .responseInternalServerError (c )
155+ }
156+
157+ return h .responseOK (c , "user notification settings updated successfully" , user )
158+ }
159+
122160// subscriptionUpdateURL returns the subscription update URL for the authenticated entities.User
123161// @Summary Currently authenticated user subscription update URL
124162// @Description Fetches the subscription URL of the authenticated user.
0 commit comments