mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
* 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
This commit is contained in:
@@ -518,6 +518,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||
m.Combo("").
|
||||
Get(notify.ListNotifications).
|
||||
Put(notify.ReadNotifications)
|
||||
m.Get("/new", notify.NewAvailable)
|
||||
m.Combo("/threads/:id").
|
||||
Get(notify.GetThread).
|
||||
Patch(notify.ReadThread)
|
||||
|
33
routers/api/v1/notify/notifications.go
Normal file
33
routers/api/v1/notify/notifications.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
@@ -21,3 +21,10 @@ type swaggerNotificationThreadList struct {
|
||||
// in:body
|
||||
Body []api.NotificationThread `json:"body"`
|
||||
}
|
||||
|
||||
// Number of unread notifications
|
||||
// swagger:response NotificationCount
|
||||
type swaggerNotificationCount struct {
|
||||
// in:body
|
||||
Body api.NotificationCount `json:"body"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user