2022-09-27 17:59:05 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/handler"
|
|
|
|
"github.com/answerdev/answer/internal/base/middleware"
|
|
|
|
"github.com/answerdev/answer/internal/schema"
|
|
|
|
"github.com/answerdev/answer/internal/service/notification"
|
2022-12-02 15:08:18 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/permission"
|
2022-11-25 17:15:02 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/rank"
|
2022-09-27 17:59:05 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NotificationController notification controller
|
|
|
|
type NotificationController struct {
|
|
|
|
notificationService *notification.NotificationService
|
2022-11-25 17:15:02 +08:00
|
|
|
rankService *rank.RankService
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewNotificationController new controller
|
2022-11-25 17:15:02 +08:00
|
|
|
func NewNotificationController(
|
|
|
|
notificationService *notification.NotificationService,
|
|
|
|
rankService *rank.RankService,
|
|
|
|
) *NotificationController {
|
|
|
|
return &NotificationController{
|
|
|
|
notificationService: notificationService,
|
|
|
|
rankService: rankService,
|
|
|
|
}
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRedDot
|
|
|
|
// @Summary GetRedDot
|
|
|
|
// @Description GetRedDot
|
|
|
|
// @Tags Notification
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/notification/status [get]
|
|
|
|
func (nc *NotificationController) GetRedDot(ctx *gin.Context) {
|
2022-11-25 17:15:02 +08:00
|
|
|
req := &schema.GetRedDot{}
|
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
canList, err := nc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
2022-12-02 15:08:18 +08:00
|
|
|
permission.QuestionAudit,
|
|
|
|
permission.AnswerAudit,
|
|
|
|
permission.TagAudit,
|
2022-12-09 17:41:23 +08:00
|
|
|
})
|
2022-11-25 17:15:02 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.CanReviewQuestion = canList[0]
|
|
|
|
req.CanReviewAnswer = canList[1]
|
|
|
|
req.CanReviewTag = canList[2]
|
|
|
|
|
2023-05-29 15:47:46 +08:00
|
|
|
resp, err := nc.notificationService.GetRedDot(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ClearRedDot
|
|
|
|
// @Summary DelRedDot
|
|
|
|
// @Description DelRedDot
|
|
|
|
// @Tags Notification
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.NotificationClearRequest true "NotificationClearRequest"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/notification/status [put]
|
|
|
|
func (nc *NotificationController) ClearRedDot(ctx *gin.Context) {
|
|
|
|
req := &schema.NotificationClearRequest{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
2022-11-25 17:15:02 +08:00
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
canList, err := nc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
2022-12-02 15:08:18 +08:00
|
|
|
permission.QuestionAudit,
|
|
|
|
permission.AnswerAudit,
|
|
|
|
permission.TagAudit,
|
2022-12-09 17:41:23 +08:00
|
|
|
})
|
2022-11-25 17:15:02 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.CanReviewQuestion = canList[0]
|
|
|
|
req.CanReviewAnswer = canList[1]
|
|
|
|
req.CanReviewTag = canList[2]
|
|
|
|
|
|
|
|
RedDot, err := nc.notificationService.ClearRedDot(ctx, req)
|
2022-09-27 17:59:05 +08:00
|
|
|
handler.HandleResponse(ctx, err, RedDot)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearUnRead
|
|
|
|
// @Summary ClearUnRead
|
|
|
|
// @Description ClearUnRead
|
|
|
|
// @Tags Notification
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.NotificationClearRequest true "NotificationClearRequest"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/notification/read/state/all [put]
|
|
|
|
func (nc *NotificationController) ClearUnRead(ctx *gin.Context) {
|
|
|
|
req := &schema.NotificationClearRequest{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
err := nc.notificationService.ClearUnRead(ctx, userID, req.TypeStr)
|
|
|
|
handler.HandleResponse(ctx, err, gin.H{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearIDUnRead
|
|
|
|
// @Summary ClearUnRead
|
|
|
|
// @Description ClearUnRead
|
|
|
|
// @Tags Notification
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.NotificationClearIDRequest true "NotificationClearIDRequest"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/notification/read/state [put]
|
|
|
|
func (nc *NotificationController) ClearIDUnRead(ctx *gin.Context) {
|
|
|
|
req := &schema.NotificationClearIDRequest{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
err := nc.notificationService.ClearIDUnRead(ctx, userID, req.ID)
|
|
|
|
handler.HandleResponse(ctx, err, gin.H{})
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:27:56 +08:00
|
|
|
// GetList get notification list
|
|
|
|
// @Summary get notification list
|
|
|
|
// @Description get notification list
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Tags Notification
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param page query int false "page size"
|
|
|
|
// @Param page_size query int false "page size"
|
2022-09-29 15:27:56 +08:00
|
|
|
// @Param type query string true "type" Enums(inbox,achievement)
|
2023-05-24 11:04:03 +08:00
|
|
|
// @Param inbox_type query string true "inbox_type" Enums(all,posts,invites,votes)
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/notification/page [get]
|
|
|
|
func (nc *NotificationController) GetList(ctx *gin.Context) {
|
|
|
|
req := &schema.NotificationSearch{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
2022-10-26 17:37:11 +08:00
|
|
|
resp, err := nc.notificationService.GetNotificationPage(ctx, req)
|
2022-09-29 15:27:56 +08:00
|
|
|
handler.HandleResponse(ctx, err, resp)
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|