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)
| 200 | // @Success 200 |
| 201 | // @Router /api/memo/remove [post] |
| 202 | func (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 | // |
nothing calls this directly
no test coverage detected