MCPcopy
hub / github.com/kingwrcy/moments / RemoveComment

Method RemoveComment

backend/handler/comment.go:43–68  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

41// @Success 200
42// @Router /api/comment/remove [post]
43func (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
70func checkGoogleRecaptcha(logger zerolog.Logger, sysConfigVO vo.FullSysConfigVO, token string) error {
71 if sysConfigVO.EnableGoogleRecaptcha {

Callers

nothing calls this directly

Calls 4

FailRespFunction · 0.85
FailRespWithMsgFunction · 0.85
SuccessRespFunction · 0.85
CurrentUserMethod · 0.80

Tested by

no test coverage detected