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/base/reason"
|
|
|
|
"github.com/answerdev/answer/internal/schema"
|
2022-12-02 15:08:18 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/permission"
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/rank"
|
|
|
|
"github.com/answerdev/answer/internal/service/report"
|
2023-03-03 18:41:26 +08:00
|
|
|
"github.com/answerdev/answer/pkg/uid"
|
2022-09-27 17:59:05 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/segmentfault/pacman/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ReportController report controller
|
|
|
|
type ReportController struct {
|
|
|
|
reportService *report.ReportService
|
|
|
|
rankService *rank.RankService
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewReportController new controller
|
|
|
|
func NewReportController(reportService *report.ReportService, rankService *rank.RankService) *ReportController {
|
|
|
|
return &ReportController{reportService: reportService, rankService: rankService}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddReport add report
|
|
|
|
// @Summary add report
|
|
|
|
// @Description add report <br> source (question, answer, comment, user)
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags Report
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.AddReportReq true "report"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/report [post]
|
|
|
|
func (rc *ReportController) AddReport(ctx *gin.Context) {
|
|
|
|
req := &schema.AddReportReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
2023-03-03 18:41:26 +08:00
|
|
|
req.ObjectID = uid.DeShortID(req.ObjectID)
|
2022-09-27 17:59:05 +08:00
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
2022-12-02 15:08:18 +08:00
|
|
|
can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, permission.ReportAdd, "")
|
2022-11-24 18:00:30 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !can {
|
|
|
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-24 18:00:30 +08:00
|
|
|
err = rc.reportService.AddReport(ctx, req)
|
2022-09-27 17:59:05 +08:00
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetReportTypeList get report type list
|
|
|
|
// @Summary get report type list
|
|
|
|
// @Description get report type list
|
|
|
|
// @Tags Report
|
|
|
|
// @Produce json
|
|
|
|
// @Param source query string true "report source" Enums(question, answer, comment, user)
|
|
|
|
// @Success 200 {object} handler.RespBody{data=[]schema.GetReportTypeResp}
|
|
|
|
// @Router /answer/api/v1/report/type/list [get]
|
|
|
|
func (rc *ReportController) GetReportTypeList(ctx *gin.Context) {
|
|
|
|
req := &schema.GetReportListReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rc.reportService.GetReportTypeList(ctx, handler.GetLang(ctx), req)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|