mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-02 04:36:35 +08:00
refactor: 后端路由定义方式&请求参数绑定重构
This commit is contained in:
@@ -11,78 +11,41 @@ import (
|
||||
|
||||
func InitMongoRouter(router *gin.RouterGroup) {
|
||||
m := router.Group("mongos")
|
||||
{
|
||||
ma := &api.Mongo{
|
||||
MongoApp: application.GetMongoApp(),
|
||||
TagApp: tagapp.GetTagTreeApp(),
|
||||
}
|
||||
|
||||
ma := &api.Mongo{
|
||||
MongoApp: application.GetMongoApp(),
|
||||
TagApp: tagapp.GetTagTreeApp(),
|
||||
}
|
||||
|
||||
reqs := [...]*req.Conf{
|
||||
// 获取所有mongo列表
|
||||
m.GET("", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
Handle(ma.Mongos)
|
||||
})
|
||||
req.NewGet("", ma.Mongos),
|
||||
|
||||
saveMongo := req.NewLogInfo("mongo-保存信息")
|
||||
m.POST("", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
WithLog(saveMongo).
|
||||
Handle(ma.Save)
|
||||
})
|
||||
req.NewPost("", ma.Save).Log(req.NewLogSave("mongo-保存信息")),
|
||||
|
||||
deleteMongo := req.NewLogInfo("mongo-删除信息")
|
||||
m.DELETE(":id", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
WithLog(deleteMongo).
|
||||
Handle(ma.DeleteMongo)
|
||||
})
|
||||
req.NewDelete(":id", ma.DeleteMongo).Log(req.NewLogSave("mongo-删除信息")),
|
||||
|
||||
// 获取mongo下的所有数据库
|
||||
m.GET(":id/databases", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
Handle(ma.Databases)
|
||||
})
|
||||
req.NewGet(":id/databases", ma.Databases),
|
||||
|
||||
// 获取mongo指定库的所有集合
|
||||
m.GET(":id/collections", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
Handle(ma.Collections)
|
||||
})
|
||||
req.NewGet(":id/collections", ma.Collections),
|
||||
|
||||
// 获取mongo runCommand
|
||||
m.POST(":id/run-command", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
Handle(ma.RunCommand)
|
||||
})
|
||||
// mongo runCommand
|
||||
req.NewPost(":id/run-command", ma.RunCommand).Log(req.NewLogSave("mongo-runCommand")),
|
||||
|
||||
// 执行mongo find命令
|
||||
m.POST(":id/command/find", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
Handle(ma.FindCommand)
|
||||
})
|
||||
req.NewPost(":id/command/find", ma.FindCommand),
|
||||
|
||||
// 执行mongo update by id命令
|
||||
updateDocById := req.NewLogInfo("mongo-更新文档").WithSave(true)
|
||||
m.POST(":id/command/update-by-id", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
WithLog(updateDocById).
|
||||
Handle(ma.UpdateByIdCommand)
|
||||
})
|
||||
req.NewPost(":id/command/update-by-id", ma.UpdateByIdCommand).Log(req.NewLogSave("mongo-更新文档")),
|
||||
|
||||
// 执行mongo delete by id命令
|
||||
deleteDoc := req.NewLogInfo("mongo-删除文档").WithSave(true)
|
||||
m.POST(":id/command/delete-by-id", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
WithLog(deleteDoc).
|
||||
Handle(ma.DeleteByIdCommand)
|
||||
})
|
||||
req.NewPost(":id/command/delete-by-id", ma.DeleteByIdCommand).Log(req.NewLogSave("mongo-删除文档")),
|
||||
|
||||
// 执行mongo insert 命令
|
||||
insertDoc := req.NewLogInfo("mongo-新增文档").WithSave(true)
|
||||
m.POST(":id/command/insert", func(c *gin.Context) {
|
||||
req.NewCtxWithGin(c).
|
||||
WithLog(insertDoc).
|
||||
Handle(ma.InsertOneCommand)
|
||||
})
|
||||
req.NewPost(":id/command/insert", ma.InsertOneCommand).Log(req.NewLogSave("mogno-插入文档")),
|
||||
}
|
||||
|
||||
req.BatchSetGroup(m, reqs[:])
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user