1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Add subject-type filter to list notification API endpoints (#16177)

Close #15886
This commit is contained in:
6543
2021-06-16 19:04:37 +02:00
committed by GitHub
parent f4d3bf7867
commit 9273601064
5 changed files with 105 additions and 43 deletions

View File

@@ -12,7 +12,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/routers/api/v1/utils"
)
// ListNotifications list users's notification threads
@@ -29,7 +28,6 @@ func ListNotifications(ctx *context.APIContext) {
// in: query
// description: If true, show notifications marked as read. Default value is false
// type: string
// required: false
// - name: status-types
// in: query
// description: "Show notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread & pinned."
@@ -37,19 +35,24 @@ func ListNotifications(ctx *context.APIContext) {
// collectionFormat: multi
// items:
// type: string
// required: false
// - name: subject-type
// in: query
// description: "filter notifications by subject type"
// type: array
// collectionFormat: multi
// items:
// type: string
// enum: [issue,pull,commit,repository]
// - name: since
// in: query
// description: Only show notifications updated after the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
// required: false
// - name: before
// in: query
// description: Only show notifications updated before the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
// required: false
// - name: page
// in: query
// description: page number of results to return (1-based)
@@ -61,22 +64,11 @@ func ListNotifications(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/NotificationThreadList"
before, since, err := utils.GetQueryBeforeSince(ctx)
if err != nil {
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
opts := getFindNotificationOptions(ctx)
if ctx.Written() {
return
}
opts := models.FindNotificationOptions{
ListOptions: utils.GetListOptions(ctx),
UserID: ctx.User.ID,
UpdatedBeforeUnix: before,
UpdatedAfterUnix: since,
}
if !ctx.QueryBool("all") {
statuses := ctx.QueryStrings("status-types")
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread", "pinned"})
}
nl, err := models.GetNotifications(opts)
if err != nil {
ctx.InternalServerError(err)
@@ -141,7 +133,7 @@ func ReadNotifications(ctx *context.APIContext) {
lastRead = tmpLastRead.Unix()
}
}
opts := models.FindNotificationOptions{
opts := &models.FindNotificationOptions{
UserID: ctx.User.ID,
UpdatedBeforeUnix: lastRead,
}