AddReport add report @Summary add report @Description add report source (question, answer, comment, user) @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]
(ctx *gin.Context)
| 67 | // @Success 200 {object} handler.RespBody |
| 68 | // @Router /answer/api/v1/report [post] |
| 69 | func (rc *ReportController) AddReport(ctx *gin.Context) { |
| 70 | req := &schema.AddReportReq{} |
| 71 | if handler.BindAndCheck(ctx, req) { |
| 72 | return |
| 73 | } |
| 74 | req.ObjectID = uid.DeShortID(req.ObjectID) |
| 75 | req.UserID = middleware.GetLoginUserIDFromContext(ctx) |
| 76 | isAdmin := middleware.GetUserIsAdminModerator(ctx) |
| 77 | if !isAdmin { |
| 78 | captchaPass := rc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionReport, req.UserID, req.CaptchaID, req.CaptchaCode) |
| 79 | if !captchaPass { |
| 80 | errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ |
| 81 | ErrorField: "captcha_code", |
| 82 | ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.CaptchaVerificationFailed), |
| 83 | }) |
| 84 | handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields) |
| 85 | return |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | can, err := rc.rankService.CheckOperationPermission(ctx, req.UserID, permission.ReportAdd, "") |
| 90 | if err != nil { |
| 91 | handler.HandleResponse(ctx, err, nil) |
| 92 | return |
| 93 | } |
| 94 | if !can { |
| 95 | handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | err = rc.reportService.AddReport(ctx, req) |
| 100 | if !isAdmin { |
| 101 | rc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionReport, req.UserID) |
| 102 | } |
| 103 | handler.HandleResponse(ctx, err, nil) |
| 104 | } |
| 105 | |
| 106 | // GetUnreviewedReportPostPage get unreviewed report post page |
| 107 | // @Summary get unreviewed report post page |
nothing calls this directly
no test coverage detected