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

Method RemoveMemo

backend/handler/memo.go:202–224  ·  view source on GitHub ↗

RemoveMemo godoc @Tags Memo @Summary 删除memos @Accept json @Produce json @Param id query int true "memoID" @Param x-api-token header string true "登录TOKEN" @Success 200 @Router /api/memo/remove [post]

(c echo.Context)

Source from the content-addressed store, hash-verified

200// @Success 200
201// @Router /api/memo/remove [post]
202func (m MemoHandler) RemoveMemo(c echo.Context) error {
203 ctx := c.(CustomContext)
204 currentUser := ctx.CurrentUser()
205 id, err := strconv.Atoi(c.QueryParam("id"))
206 if err != nil {
207 return FailResp(c, ParamError)
208 }
209 var (
210 memo db.Memo
211 )
212 if err = m.base.db.First(&memo, id).Error; errors.Is(err, gorm.ErrRecordNotFound) {
213 return FailResp(c, ParamError)
214 }
215
216 if currentUser.Id != memo.UserId && currentUser.Id != 1 {
217 return FailRespWithMsg(c, Fail, "没有权限")
218 }
219 if m.base.db.Delete(&memo).RowsAffected != 1 {
220 return FailRespWithMsg(c, Fail, "删除失败")
221 }
222
223 return SuccessResp(c, h{})
224}
225
226// LikeMemo godoc
227//

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