mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-10 19:23:42 +08:00
refactor: remove api change to post request
This commit is contained in:
@@ -154,30 +154,36 @@ func (h *UserHandler) ResetPass(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *UserHandler) Remove(c *gin.Context) {
|
||||
id := h.GetInt(c, "id", 0)
|
||||
if id > 0 {
|
||||
var data struct {
|
||||
Id uint
|
||||
}
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
resp.ERROR(c, types.InvalidArgs)
|
||||
return
|
||||
}
|
||||
if data.Id > 0 {
|
||||
tx := h.db.Begin()
|
||||
res := h.db.Where("id = ?", id).Delete(&model.User{})
|
||||
res := h.db.Where("id = ?", data.Id).Delete(&model.User{})
|
||||
if res.Error != nil {
|
||||
resp.ERROR(c, "删除失败")
|
||||
return
|
||||
}
|
||||
// 删除聊天记录
|
||||
res = h.db.Where("user_id = ?", id).Delete(&model.ChatItem{})
|
||||
res = h.db.Where("user_id = ?", data.Id).Delete(&model.ChatItem{})
|
||||
if res.Error != nil {
|
||||
tx.Rollback()
|
||||
resp.ERROR(c, "删除失败")
|
||||
return
|
||||
}
|
||||
// 删除聊天历史记录
|
||||
res = h.db.Where("user_id = ?", id).Delete(&model.ChatMessage{})
|
||||
res = h.db.Where("user_id = ?", data.Id).Delete(&model.ChatMessage{})
|
||||
if res.Error != nil {
|
||||
tx.Rollback()
|
||||
resp.ERROR(c, "删除失败")
|
||||
return
|
||||
}
|
||||
// 删除登录日志
|
||||
res = h.db.Where("user_id = ?", id).Delete(&model.UserLoginLog{})
|
||||
res = h.db.Where("user_id = ?", data.Id).Delete(&model.UserLoginLog{})
|
||||
if res.Error != nil {
|
||||
tx.Rollback()
|
||||
resp.ERROR(c, "删除失败")
|
||||
|
||||
Reference in New Issue
Block a user