Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7066d0

Browse files
committed
add test endpoint for push notifications
1 parentfc20adb commitd7066d0

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 aboutcustomizing 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 aboutcustomizing 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+
iferr:=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
funcconvertNotificationTemplates(in []database.NotificationTemplate) (out []codersdk.NotificationTemplate) {
442467
for_,tmpl:=rangein {
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 aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp