Skip to content

Commit d7066d0

Browse files
committed
add test endpoint for push notifications
1 parent fc20adb commit d7066d0

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ func New(options *Options) *API {
12031203
r.Route("/push", func(r chi.Router) {
12041204
r.Post("/subscription", api.postUserPushNotificationSubscription)
12051205
r.Delete("/subscription", api.deleteUserPushNotificationSubscription)
1206+
r.Post("/test", api.postUserPushNotificationTest)
12061207
})
12071208
})
12081209
})

coderd/notifications.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,31 @@ func (api *API) deleteUserPushNotificationSubscription(rw http.ResponseWriter, r
438438
rw.WriteHeader(http.StatusNoContent)
439439
}
440440

441+
// @Summary Send a test push notification
442+
// @ID send-a-test-push-notification
443+
// @Security CoderSessionToken
444+
// @Tags Notifications
445+
// @Param user path string true "User ID, name, or me"
446+
// @Success 204
447+
// @Router /users/{user}/notifications/push/test [post]
448+
func (api *API) postUserPushNotificationTest(rw http.ResponseWriter, r *http.Request) {
449+
ctx := r.Context()
450+
user := httpmw.UserParam(r)
451+
452+
if err := api.PushNotifier.Dispatch(ctx, user.ID, codersdk.PushNotification{
453+
Title: "It's working!",
454+
Body: "You've subscribed to push notifications.",
455+
}); err != nil {
456+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
457+
Message: "Failed to send test notification",
458+
Detail: err.Error(),
459+
})
460+
return
461+
}
462+
463+
rw.WriteHeader(http.StatusNoContent)
464+
}
465+
441466
func convertNotificationTemplates(in []database.NotificationTemplate) (out []codersdk.NotificationTemplate) {
442467
for _, tmpl := range in {
443468
out = append(out, codersdk.NotificationTemplate{

docs/reference/api/notifications.md

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)