gen_router.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package router
  2. import (
  3. "github.com/gin-gonic/gin"
  4. jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
  5. "go-admin/app/admin/apis"
  6. "go-admin/app/other/apis/tools"
  7. )
  8. func init() {
  9. routerCheckRole = append(routerCheckRole, sysNoCheckRoleRouter, registerDBRouter, registerSysTableRouter)
  10. }
  11. func sysNoCheckRoleRouter(v1 *gin.RouterGroup ,authMiddleware *jwt.GinJWTMiddleware) {
  12. r1 := v1.Group("")
  13. {
  14. sys := apis.System{}
  15. r1.GET("/captcha", sys.GenerateCaptchaHandler)
  16. }
  17. r := v1.Group("").Use(authMiddleware.MiddlewareFunc())
  18. {
  19. gen := tools.Gen{}
  20. r.GET("/gen/preview/:tableId", gen.Preview)
  21. r.GET("/gen/toproject/:tableId", gen.GenCode)
  22. r.GET("/gen/apitofile/:tableId", gen.GenApiToFile)
  23. r.GET("/gen/todb/:tableId", gen.GenMenuAndApi)
  24. sysTable := tools.SysTable{}
  25. r.GET("/gen/tabletree", sysTable.GetSysTablesTree)
  26. }
  27. }
  28. func registerDBRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
  29. db := v1.Group("/db").Use(authMiddleware.MiddlewareFunc())
  30. {
  31. gen := tools.Gen{}
  32. db.GET("/tables/page", gen.GetDBTableList)
  33. db.GET("/columns/page", gen.GetDBColumnList)
  34. }
  35. }
  36. func registerSysTableRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
  37. tables := v1.Group("/sys/tables")
  38. {
  39. sysTable := tools.SysTable{}
  40. tables.Group("").Use(authMiddleware.MiddlewareFunc()).GET("/page", sysTable.GetPage)
  41. tablesInfo := tables.Group("/info").Use(authMiddleware.MiddlewareFunc())
  42. {
  43. tablesInfo.POST("", sysTable.Insert)
  44. tablesInfo.PUT("", sysTable.Update)
  45. tablesInfo.DELETE("/:tableId", sysTable.Delete)
  46. tablesInfo.GET("/:tableId", sysTable.Get)
  47. tablesInfo.GET("", sysTable.GetSysTablesInfo)
  48. }
  49. }
  50. }