@@ -161,17 +161,17 @@ func (api *API) userNotificationPreferences(rw http.ResponseWriter, r *http.Requ
161
161
162
162
prefs ,err := api .Database .GetUserNotificationPreferences (ctx ,user .ID )
163
163
if err != nil {
164
- logger .Error (ctx ,"failed to retrieve" )
164
+ logger .Error (ctx ,"failed to retrieve preferences" , slog . Error ( err ) )
165
165
166
- httpapi .Write (r . Context () ,rw ,http .StatusInternalServerError , codersdk.Response {
166
+ httpapi .Write (ctx ,rw ,http .StatusInternalServerError , codersdk.Response {
167
167
Message :"Failed to retrieve user notification preferences." ,
168
168
Detail :err .Error (),
169
169
})
170
170
return
171
171
}
172
172
173
173
out := convertNotificationPreferences (prefs )
174
- httpapi .Write (r . Context () ,rw ,http .StatusOK ,out )
174
+ httpapi .Write (ctx ,rw ,http .StatusOK ,out )
175
175
}
176
176
177
177
// @Summary Update user notification preferences
@@ -191,11 +191,13 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
191
191
logger = api .Logger .Named ("notifications.preferences" ).With (slog .F ("user_id" ,user .ID ))
192
192
)
193
193
194
+ // Parse request.
194
195
var prefs codersdk.UpdateUserNotificationPreferences
195
196
if ! httpapi .Read (ctx ,rw ,r ,& prefs ) {
196
197
return
197
198
}
198
199
200
+ // Build query params.
199
201
input := database.UpdateUserNotificationPreferencesParams {
200
202
UserID :user .ID ,
201
203
NotificationTemplateIds :make ([]uuid.UUID ,0 ,len (prefs .TemplateDisabledMap )),
@@ -204,9 +206,9 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
204
206
for tmplID ,disabled := range prefs .TemplateDisabledMap {
205
207
id ,err := uuid .Parse (tmplID )
206
208
if err != nil {
207
- logger .Warn (ctx ,"failed to parse notification template UUID" ,slog .F ("input" ,tmplID ))
209
+ logger .Warn (ctx ,"failed to parse notification template UUID" ,slog .F ("input" ,tmplID ), slog . Error ( err ) )
208
210
209
- httpapi .Write (r . Context () ,rw ,http .StatusBadRequest , codersdk.Response {
211
+ httpapi .Write (ctx ,rw ,http .StatusBadRequest , codersdk.Response {
210
212
Message :"Unable to parse notification template UUID." ,
211
213
Detail :err .Error (),
212
214
})
@@ -217,32 +219,34 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
217
219
input .Disableds = append (input .Disableds ,disabled )
218
220
}
219
221
222
+ // Update preferences with params.
220
223
updated ,err := api .Database .UpdateUserNotificationPreferences (ctx ,input )
221
224
if err != nil {
222
225
logger .Error (ctx ,"failed to update preferences" ,slog .Error (err ))
223
226
224
- httpapi .Write (r . Context () ,rw ,http .StatusInternalServerError , codersdk.Response {
227
+ httpapi .Write (ctx ,rw ,http .StatusInternalServerError , codersdk.Response {
225
228
Message :"Failed to update user notifications preferences." ,
226
229
Detail :err .Error (),
227
230
})
228
231
return
229
232
}
230
233
234
+ // Preferences updated, now fetch all preferences belonging to this user.
231
235
logger .Info (ctx ,"updated preferences" ,slog .F ("count" ,updated ))
232
236
233
237
userPrefs ,err := api .Database .GetUserNotificationPreferences (ctx ,user .ID )
234
238
if err != nil {
235
239
logger .Error (ctx ,"failed to retrieve preferences" ,slog .Error (err ))
236
240
237
- httpapi .Write (r . Context () ,rw ,http .StatusInternalServerError , codersdk.Response {
241
+ httpapi .Write (ctx ,rw ,http .StatusInternalServerError , codersdk.Response {
238
242
Message :"Failed to retrieve user notifications preferences." ,
239
243
Detail :err .Error (),
240
244
})
241
245
return
242
246
}
243
247
244
248
out := convertNotificationPreferences (userPrefs )
245
- httpapi .Write (r . Context () ,rw ,http .StatusOK ,out )
249
+ httpapi .Write (ctx ,rw ,http .StatusOK ,out )
246
250
}
247
251
248
252
func convertNotificationTemplates (in []database.NotificationTemplate ) (out []codersdk.NotificationTemplate ) {