[notification] /read add types param

This commit is contained in:
Kassian Sun 2023-04-03 18:45:34 +08:00
parent 272f29403d
commit 97f5b958b3
1 changed files with 35 additions and 9 deletions

View File

@ -70,6 +70,7 @@ func (h *NotificationAPI) listNotifications(w http.ResponseWriter, req *http.Req
type SetNotificationsReadRequest struct {
Ids []string `json:"ids"`
Types []model.NotificationType `json:"types"`
}
func (h *NotificationAPI) setNotificationsRead(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
@ -97,6 +98,9 @@ func (h *NotificationAPI) setNotificationsRead(w http.ResponseWriter, req *http.
queryDsl := util.MapStr{
"query": util.MapStr{
"bool": util.MapStr{
"should": []util.MapStr{
util.MapStr{
"bool": util.MapStr{
"must": []util.MapStr{
{
@ -114,6 +118,28 @@ func (h *NotificationAPI) setNotificationsRead(w http.ResponseWriter, req *http.
},
},
},
util.MapStr{
"bool": util.MapStr{
"must": []util.MapStr{
{
"terms": util.MapStr{
"notification_type": reqData.Types,
},
},
{
"term": util.MapStr{
"status": util.MapStr{
"value": model.NotificationStatusNew,
},
},
},
},
},
},
},
"minimum_should_match": 1,
},
},
"script": util.MapStr{
"source": fmt.Sprintf("ctx._source['status'] = '%s';ctx._source['updated'] = '%s'", model.NotificationStatusRead, now),
},