RemoveComment godoc @Tags Comment @Summary 删除评论 @Accept json @Produce json @Param id query int true "评论ID" @Param x-api-token header string true "登录TOKEN" @Success 200 @Router /api/comment/remove [post]
(ctx echo.Context)
| 41 | // @Success 200 |
| 42 | // @Router /api/comment/remove [post] |
| 43 | func (c CommentHandler) RemoveComment(ctx echo.Context) error { |
| 44 | context := ctx.(CustomContext) |
| 45 | currentUser := context.CurrentUser() |
| 46 | id, err := strconv.Atoi(ctx.QueryParam("id")) |
| 47 | if err != nil { |
| 48 | return FailResp(ctx, ParamError) |
| 49 | } |
| 50 | var ( |
| 51 | comment db.Comment |
| 52 | memo db.Memo |
| 53 | ) |
| 54 | if err = c.base.db.First(&comment, id).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| 55 | return FailResp(ctx, ParamError) |
| 56 | } |
| 57 | if err = c.base.db.First(&memo, comment.MemoId).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| 58 | return FailResp(ctx, ParamError) |
| 59 | } |
| 60 | |
| 61 | if currentUser.Id != memo.UserId && currentUser.Id != 1 { |
| 62 | return FailRespWithMsg(ctx, Fail, "没有权限") |
| 63 | } |
| 64 | if c.base.db.Delete(&comment).RowsAffected != 1 { |
| 65 | return FailRespWithMsg(ctx, Fail, "删除失败") |
| 66 | } |
| 67 | return SuccessResp(ctx, h{}) |
| 68 | } |
| 69 | |
| 70 | func checkGoogleRecaptcha(logger zerolog.Logger, sysConfigVO vo.FullSysConfigVO, token string) error { |
| 71 | if sysConfigVO.EnableGoogleRecaptcha { |
nothing calls this directly
no test coverage detected