* refactor(api): refactor HTTP API to version 2 * refactor: remove forced site_origin check * refactor: update http client * fix * add more api description and error code * reduce nestings in response structures * separate unread * refactor(api/comments): get comments * refactor: frontend api module * chore: remove vite temporary file * chore: restore swagger file * update * 移除为管理员分配站点名的站点隔离功能,简化实现 * refactor pagesAllFetch * fix ci * remove useless codes * limiter protected paths * add test for version endpoint * rename handler code files * code file separate * fix some bug of interacting with backend * add fetch error class for handling * fix and rename * refactor: checker support both `Promise` and callback fn * fix new checker captcha iframe url * rename and add swagger id field * replace tab with spaces in go comment * chore: refine * complete the validate tag for request fields and enable `--defaultRequired` 90% of the request fields of our API are required,100% of response fields in our API are required. Each field add validate:"required" is easy to miss. * replace original api client with auto-generated codes * artalk pkg apply new api client * artalk-sidebar pkg apply new api client * fix issues * fix sidebar locale conf and refactor user login * fix and refactor captcha and limiter * fix ui testing * add script to build http client by swagger.json
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/ArtalkJS/Artalk/internal/core"
|
|
"github.com/ArtalkJS/Artalk/internal/i18n"
|
|
"github.com/ArtalkJS/Artalk/server/common"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// @Id MarkNotifyRead
|
|
// @Summary Mark Notify as Read
|
|
// @Description Mark specific notification as read for user
|
|
// @Tags Notify
|
|
// @Param comment_id path int true "The comment id of the notify you want to mark as read"
|
|
// @Param notify_key path string true "The key of the notify"
|
|
// @Produce json
|
|
// @Success 200 {object} Map{}
|
|
// @Failure 400 {object} Map{msg=string}
|
|
// @Failure 404 {object} Map{msg=string}
|
|
// @Failure 500 {object} Map{msg=string}
|
|
// @Router /notifies/{comment_id}/{notify_key} [post]
|
|
func NotifyRead(app *core.App, router fiber.Router) {
|
|
router.Post("/notifies/:comment_id/:notify_key", func(c *fiber.Ctx) error {
|
|
commentID, _ := c.ParamsInt("comment_id")
|
|
notifyKey := c.Params("notify_key")
|
|
|
|
// find notify
|
|
notify := app.Dao().FindNotifyForComment(uint(commentID), notifyKey)
|
|
if notify.IsEmpty() {
|
|
return common.RespError(c, 404, i18n.T("{{name}} not found", Map{"name": i18n.T("Notify")}))
|
|
}
|
|
|
|
if notify.IsRead {
|
|
return common.RespSuccess(c)
|
|
}
|
|
|
|
// update notify
|
|
err := app.Dao().NotifySetRead(¬ify)
|
|
if err != nil {
|
|
return common.RespError(c, 500, i18n.T("{{name}} save failed", Map{"name": i18n.T("Notify")}))
|
|
}
|
|
|
|
return common.RespSuccess(c)
|
|
})
|
|
}
|