RemoveComment remove comment @Summary remove comment @Description remove comment @Tags Comment @Accept json @Produce json @Security ApiKeyAuth @Param data body schema.RemoveCommentReq true "comment" @Success 200 {object} handler.RespBody @Router /answer/api/v1/comment [delete]
(ctx *gin.Context)
| 142 | // @Success 200 {object} handler.RespBody |
| 143 | // @Router /answer/api/v1/comment [delete] |
| 144 | func (cc *CommentController) RemoveComment(ctx *gin.Context) { |
| 145 | req := &schema.RemoveCommentReq{} |
| 146 | if handler.BindAndCheck(ctx, req) { |
| 147 | return |
| 148 | } |
| 149 | |
| 150 | req.UserID = middleware.GetLoginUserIDFromContext(ctx) |
| 151 | isAdmin := middleware.GetUserIsAdminModerator(ctx) |
| 152 | if !isAdmin { |
| 153 | captchaPass := cc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionDelete, req.UserID, req.CaptchaID, req.CaptchaCode) |
| 154 | if !captchaPass { |
| 155 | errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ |
| 156 | ErrorField: "captcha_code", |
| 157 | ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.CaptchaVerificationFailed), |
| 158 | }) |
| 159 | handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields) |
| 160 | return |
| 161 | } |
| 162 | } |
| 163 | can, err := cc.rankService.CheckOperationPermission(ctx, req.UserID, permission.CommentDelete, req.CommentID) |
| 164 | if err != nil { |
| 165 | handler.HandleResponse(ctx, err, nil) |
| 166 | return |
| 167 | } |
| 168 | if !can { |
| 169 | handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil) |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | err = cc.commentService.RemoveComment(ctx, req) |
| 174 | if !isAdmin { |
| 175 | cc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionDelete, req.UserID) |
| 176 | } |
| 177 | handler.HandleResponse(ctx, err, nil) |
| 178 | } |
| 179 | |
| 180 | // UpdateComment update comment |
| 181 | // @Summary update comment |
nothing calls this directly
no test coverage detected