mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
refactor: remove api change to post request
This commit is contained in:
parent
d3fbb8c19e
commit
f86176b342
@ -10,10 +10,6 @@ WeChatBot = false
|
|||||||
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" # 注意:这个是 JWT Token 授权密钥,生产环境请务必更换
|
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" # 注意:这个是 JWT Token 授权密钥,生产环境请务必更换
|
||||||
MaxAge = 86400
|
MaxAge = 86400
|
||||||
|
|
||||||
[Manager]
|
|
||||||
Username = "admin"
|
|
||||||
Password = "admin123" # 如果是生产环境的话,这里管理员的密码记得修改
|
|
||||||
|
|
||||||
[Redis] # redis 配置信息
|
[Redis] # redis 配置信息
|
||||||
Host = "localhost"
|
Host = "localhost"
|
||||||
Port = 6379
|
Port = 6379
|
||||||
|
@ -109,10 +109,15 @@ func (h *ApiKeyHandler) Set(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApiKeyHandler) Remove(c *gin.Context) {
|
func (h *ApiKeyHandler) Remove(c *gin.Context) {
|
||||||
id := h.GetInt(c, "id", 0)
|
var data struct {
|
||||||
|
Id uint
|
||||||
if id > 0 {
|
}
|
||||||
res := h.db.Where("id = ?", id).Delete(&model.ApiKey{})
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if data.Id > 0 {
|
||||||
|
res := h.db.Where("id = ?", data.Id).Delete(&model.ApiKey{})
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, "更新数据库失败!")
|
resp.ERROR(c, "更新数据库失败!")
|
||||||
return
|
return
|
||||||
|
@ -140,10 +140,15 @@ func (h *ChatModelHandler) Sort(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ChatModelHandler) Remove(c *gin.Context) {
|
func (h *ChatModelHandler) Remove(c *gin.Context) {
|
||||||
id := h.GetInt(c, "id", 0)
|
var data struct {
|
||||||
|
Id uint
|
||||||
if id > 0 {
|
}
|
||||||
res := h.db.Where("id = ?", id).Delete(&model.ChatModel{})
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if data.Id > 0 {
|
||||||
|
res := h.db.Where("id = ?", data.Id).Delete(&model.ChatModel{})
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, "更新数据库失败!")
|
resp.ERROR(c, "更新数据库失败!")
|
||||||
return
|
return
|
||||||
|
@ -119,13 +119,18 @@ func (h *ChatRoleHandler) Set(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ChatRoleHandler) Remove(c *gin.Context) {
|
func (h *ChatRoleHandler) Remove(c *gin.Context) {
|
||||||
id := h.GetInt(c, "id", 0)
|
var data struct {
|
||||||
if id <= 0 {
|
Id uint
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
resp.ERROR(c, types.InvalidArgs)
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if data.Id <= 0 {
|
||||||
res := h.db.Where("id = ?", id).Delete(&model.ChatRole{})
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res := h.db.Where("id = ?", data.Id).Delete(&model.ChatRole{})
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, "删除失败!")
|
resp.ERROR(c, "删除失败!")
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package admin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"chatplus/core"
|
"chatplus/core"
|
||||||
|
"chatplus/core/types"
|
||||||
"chatplus/handler"
|
"chatplus/handler"
|
||||||
"chatplus/store/model"
|
"chatplus/store/model"
|
||||||
"chatplus/store/vo"
|
"chatplus/store/vo"
|
||||||
@ -57,10 +58,15 @@ func (h *RewardHandler) List(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *RewardHandler) Remove(c *gin.Context) {
|
func (h *RewardHandler) Remove(c *gin.Context) {
|
||||||
id := h.GetInt(c, "id", 0)
|
var data struct {
|
||||||
|
Id uint
|
||||||
if id > 0 {
|
}
|
||||||
res := h.db.Where("id = ?", id).Delete(&model.Reward{})
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if data.Id > 0 {
|
||||||
|
res := h.db.Where("id = ?", data.Id).Delete(&model.Reward{})
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, "更新数据库失败!")
|
resp.ERROR(c, "更新数据库失败!")
|
||||||
return
|
return
|
||||||
|
@ -154,30 +154,36 @@ func (h *UserHandler) ResetPass(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *UserHandler) Remove(c *gin.Context) {
|
func (h *UserHandler) Remove(c *gin.Context) {
|
||||||
id := h.GetInt(c, "id", 0)
|
var data struct {
|
||||||
if id > 0 {
|
Id uint
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindJSON(&data); err != nil {
|
||||||
|
resp.ERROR(c, types.InvalidArgs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if data.Id > 0 {
|
||||||
tx := h.db.Begin()
|
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 {
|
if res.Error != nil {
|
||||||
resp.ERROR(c, "删除失败")
|
resp.ERROR(c, "删除失败")
|
||||||
return
|
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 {
|
if res.Error != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
resp.ERROR(c, "删除失败")
|
resp.ERROR(c, "删除失败")
|
||||||
return
|
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 {
|
if res.Error != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
resp.ERROR(c, "删除失败")
|
resp.ERROR(c, "删除失败")
|
||||||
return
|
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 {
|
if res.Error != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
resp.ERROR(c, "删除失败")
|
resp.ERROR(c, "删除失败")
|
||||||
|
10
api/main.go
10
api/main.go
@ -273,13 +273,13 @@ func main() {
|
|||||||
group.POST("save", h.Save)
|
group.POST("save", h.Save)
|
||||||
group.GET("list", h.List)
|
group.GET("list", h.List)
|
||||||
group.POST("set", h.Set)
|
group.POST("set", h.Set)
|
||||||
group.GET("remove", h.Remove)
|
group.POST("remove", h.Remove)
|
||||||
}),
|
}),
|
||||||
fx.Invoke(func(s *core.AppServer, h *admin.UserHandler) {
|
fx.Invoke(func(s *core.AppServer, h *admin.UserHandler) {
|
||||||
group := s.Engine.Group("/api/admin/user/")
|
group := s.Engine.Group("/api/admin/user/")
|
||||||
group.GET("list", h.List)
|
group.GET("list", h.List)
|
||||||
group.POST("save", h.Save)
|
group.POST("save", h.Save)
|
||||||
group.GET("remove", h.Remove)
|
group.POST("remove", h.Remove)
|
||||||
group.GET("loginLog", h.LoginLog)
|
group.GET("loginLog", h.LoginLog)
|
||||||
group.POST("resetPass", h.ResetPass)
|
group.POST("resetPass", h.ResetPass)
|
||||||
}),
|
}),
|
||||||
@ -289,12 +289,12 @@ func main() {
|
|||||||
group.POST("save", h.Save)
|
group.POST("save", h.Save)
|
||||||
group.POST("sort", h.Sort)
|
group.POST("sort", h.Sort)
|
||||||
group.POST("set", h.Set)
|
group.POST("set", h.Set)
|
||||||
group.GET("remove", h.Remove)
|
group.POST("remove", h.Remove)
|
||||||
}),
|
}),
|
||||||
fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) {
|
fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) {
|
||||||
group := s.Engine.Group("/api/admin/reward/")
|
group := s.Engine.Group("/api/admin/reward/")
|
||||||
group.GET("list", h.List)
|
group.GET("list", h.List)
|
||||||
group.GET("remove", h.Remove)
|
group.POST("remove", h.Remove)
|
||||||
}),
|
}),
|
||||||
fx.Invoke(func(s *core.AppServer, h *admin.DashboardHandler) {
|
fx.Invoke(func(s *core.AppServer, h *admin.DashboardHandler) {
|
||||||
group := s.Engine.Group("/api/admin/dashboard/")
|
group := s.Engine.Group("/api/admin/dashboard/")
|
||||||
@ -310,7 +310,7 @@ func main() {
|
|||||||
group.GET("list", h.List)
|
group.GET("list", h.List)
|
||||||
group.POST("set", h.Set)
|
group.POST("set", h.Set)
|
||||||
group.POST("sort", h.Sort)
|
group.POST("sort", h.Sort)
|
||||||
group.GET("remove", h.Remove)
|
group.POST("remove", h.Remove)
|
||||||
}),
|
}),
|
||||||
fx.Invoke(func(s *core.AppServer, h *handler.PaymentHandler) {
|
fx.Invoke(func(s *core.AppServer, h *handler.PaymentHandler) {
|
||||||
group := s.Engine.Group("/api/payment/")
|
group := s.Engine.Group("/api/payment/")
|
||||||
|
@ -10,10 +10,6 @@ WeChatBot = false
|
|||||||
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" # 注意:这个是 JWT Token 授权密钥,生产环境请务必更换
|
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" # 注意:这个是 JWT Token 授权密钥,生产环境请务必更换
|
||||||
MaxAge = 86400
|
MaxAge = 86400
|
||||||
|
|
||||||
[Manager]
|
|
||||||
Username = "admin"
|
|
||||||
Password = "admin123" # 如果是生产环境的话,这里管理员的密码记得修改
|
|
||||||
|
|
||||||
[Redis] # redis 配置信息
|
[Redis] # redis 配置信息
|
||||||
Host = "localhost"
|
Host = "localhost"
|
||||||
Port = 6379
|
Port = 6379
|
||||||
|
Loading…
Reference in New Issue
Block a user