aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/notify
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-01-14 16:37:19 +0100
committerAntoine GIRARD <sapk@users.noreply.github.com>2020-01-14 16:37:19 +0100
commit44de66bf50d1ab9a5acc298063cd942768092a19 (patch)
treefda1b76b954d720dfdfefded22883a51ab52e45e /routers/api/v1/notify
parentce274d652f2be03364bc0d0a8cb1b4d1996b16c7 (diff)
downloadgitea-44de66bf50d1ab9a5acc298063cd942768092a19.tar.gz
gitea-44de66bf50d1ab9a5acc298063cd942768092a19.zip
[API] add endpoint to check notifications [Extend #9488] (#9595)
* introduce GET /notifications/new * add TEST * use Sprintf instead of path.Join * Error more verbose * return number of notifications if unreaded exist * 200 http status for available notifications
Diffstat (limited to 'routers/api/v1/notify')
-rw-r--r--routers/api/v1/notify/notifications.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/routers/api/v1/notify/notifications.go b/routers/api/v1/notify/notifications.go
new file mode 100644
index 0000000000..847fe3313e
--- /dev/null
+++ b/routers/api/v1/notify/notifications.go
@@ -0,0 +1,33 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package notify
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/context"
+ api "code.gitea.io/gitea/modules/structs"
+)
+
+// NewAvailable check if unread notifications exist
+func NewAvailable(ctx *context.APIContext) {
+ // swagger:operation GET /notifications/new notification notifyNewAvailable
+ // ---
+ // summary: Check if unread notifications exist
+ // responses:
+ // "200":
+ // "$ref": "#/responses/NotificationCount"
+ // "204":
+ // description: No unread notification
+
+ count := models.CountUnread(ctx.User)
+
+ if count > 0 {
+ ctx.JSON(http.StatusOK, api.NotificationCount{New: count})
+ } else {
+ ctx.Status(http.StatusNoContent)
+ }
+}