From b6feff6085601ed364d87428c31bfbb4c339c049 Mon Sep 17 00:00:00 2001 From: hupeh Date: Mon, 2 Jan 2023 12:09:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7=E8=B7=AF=E7=94=B1=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/rts.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/rts.go b/app/rts.go index 6e9a689..10b511c 100644 --- a/app/rts.go +++ b/app/rts.go @@ -152,7 +152,28 @@ func UpdateUser(w *ResponseWriter, r *Request) { // DeleteUser 删除用户 func DeleteUser(w *ResponseWriter, r *Request) { + id := chi.URLParam(r.Request, "id") + if len(id) == 0 { + w.Error(NewError(1, "缺少用户ID")) + } + + // 查询用户信息 + var u User + if err := DB.First(&u, "id = ?", id).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + err = NewError(1, "用户不存在") + } + w.Error(err) + return + } + // 删除用户 + if err := DB.Delete(&u).Error; err != nil { + LogError(err) + w.Error(NewError(1, "删除用户失败")) + } else { + w.Ok(nil, "删除用户成功") + } } // ListUser 用户列表