VoteUp godoc @Summary vote up @Description add vote @Tags Activity @Accept json @Produce json @Security ApiKeyAuth @Param data body schema.VoteReq true "vote" @Success 200 {object} handler.RespBody{data=schema.VoteResp} @Router /answer/api/v1/vote/up [post]
(ctx *gin.Context)
| 66 | // @Success 200 {object} handler.RespBody{data=schema.VoteResp} |
| 67 | // @Router /answer/api/v1/vote/up [post] |
| 68 | func (vc *VoteController) VoteUp(ctx *gin.Context) { |
| 69 | req := &schema.VoteReq{} |
| 70 | if handler.BindAndCheck(ctx, req) { |
| 71 | return |
| 72 | } |
| 73 | req.ObjectID = uid.DeShortID(req.ObjectID) |
| 74 | req.UserID = middleware.GetLoginUserIDFromContext(ctx) |
| 75 | |
| 76 | can, needRank, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, true) |
| 77 | if err != nil { |
| 78 | handler.HandleResponse(ctx, err, nil) |
| 79 | return |
| 80 | } |
| 81 | if !can { |
| 82 | lang := handler.GetLangByCtx(ctx) |
| 83 | msg := translator.TrWithData(lang, reason.NoEnoughRankToOperate, &schema.PermissionTrTplData{Rank: needRank}) |
| 84 | handler.HandleResponse(ctx, errors.Forbidden(reason.NoEnoughRankToOperate).WithMsg(msg), nil) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | isAdmin := middleware.GetUserIsAdminModerator(ctx) |
| 89 | if !isAdmin { |
| 90 | captchaPass := vc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionVote, req.UserID, req.CaptchaID, req.CaptchaCode) |
| 91 | if !captchaPass { |
| 92 | errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ |
| 93 | ErrorField: "captcha_code", |
| 94 | ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.CaptchaVerificationFailed), |
| 95 | }) |
| 96 | handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields) |
| 97 | return |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if !isAdmin { |
| 102 | vc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionVote, req.UserID) |
| 103 | } |
| 104 | resp, err := vc.VoteService.VoteUp(ctx, req) |
| 105 | if err != nil { |
| 106 | handler.HandleResponse(ctx, err, schema.ErrTypeToast) |
| 107 | } else { |
| 108 | handler.HandleResponse(ctx, err, resp) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // VoteDown godoc |
| 113 | // @Summary vote down |
nothing calls this directly
no test coverage detected