routes.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * @description: 路由配置
  3. * @Author: CP
  4. * @Date: 2020-08-23 21:32:54
  5. * @FilePath: \construction_management\web\routes\routes.go
  6. */
  7. package routes
  8. import (
  9. "github.com/kataras/iris/v12/mvc"
  10. "go.mod/bootstrap"
  11. "go.mod/services"
  12. "go.mod/web/api"
  13. "go.mod/web/controllers"
  14. "go.mod/web/middleware"
  15. )
  16. func Configure(b *bootstrap.Bootstrapper) {
  17. //service加载
  18. ProjectAccountService := services.NewProjectAccountService()
  19. LoginService := services.NewLoginService()
  20. ProjectService := services.NewProjectService()
  21. TreeService := services.NewTreeService()
  22. BidsectionService := services.NewBidsectionService()
  23. BidAccountService := services.NewBidAccountService()
  24. ContractService := services.NewContractService()
  25. RpcService := services.NewRpcService()
  26. SafeService := services.NewSafeService()
  27. //CSRF相关
  28. b.Use(middleware.SetCsrf)
  29. //b.Party("/", protect)
  30. //protect := NewCsrf()
  31. //登录相关
  32. //login := mvc.New(b.Party("/", protect))
  33. login := mvc.New(b.Party("/"))
  34. login.Register(ProjectAccountService)
  35. login.Register(LoginService)
  36. login.Handle(new(controllers.LoginController))
  37. // todolist相关
  38. todo := mvc.New(b.Party("/todolist"))
  39. todo.Router.Use(middleware.SessionsAuth)
  40. todo.Handle(new(controllers.TodoController))
  41. // // 合同管理
  42. // contract := mvc.New(b.Party("/contract"))
  43. // contract.Router.Use(middleware.SessionsAuth)
  44. // contract.Handle(new(controllers.ContractController))
  45. // 安全巡检
  46. //用户相关
  47. account := mvc.New(b.Party("/account"))
  48. account.Register(ProjectAccountService)
  49. account.Router.Use(middleware.SessionsAuth)
  50. account.Handle(new(controllers.AccountController))
  51. // 项目相关
  52. project := mvc.New(b.Party("/project"))
  53. project.Router.Use(middleware.SessionsAuth)
  54. project.Register(TreeService)
  55. project.Register(ProjectService)
  56. project.Handle(new(controllers.ProjectController))
  57. //标段相关
  58. bidsection := mvc.New(b.Party("/bidsection"))
  59. bidsection.Register(ProjectService)
  60. bidsection.Router.Use(middleware.SessionsAuth)
  61. bidsection.Handle(new(controllers.BidsectionController))
  62. // apiTree.Router.Use(middleware.JwtAuth().Serve)
  63. // 接口相关
  64. // 登陆接口
  65. apiLogin := mvc.New(b.Party("/api/login"))
  66. apiLogin.Register(ProjectAccountService)
  67. apiLogin.Register(LoginService)
  68. apiLogin.Register(ProjectService)
  69. apiLogin.Handle(new(api.LoginApi))
  70. // 项目相关接口
  71. apiProject := mvc.New(b.Party("/api/project"))
  72. apiProject.Register(ProjectService)
  73. apiProject.Router.Use(middleware.SessionsAuth)
  74. apiProject.Router.Use(middleware.AccessAuth)
  75. apiProject.Handle(new(api.ProjectApi))
  76. // 项目账号相关接口
  77. apiProjectAccount := mvc.New(b.Party("/api/projectAccount"))
  78. apiProjectAccount.Register(ProjectAccountService)
  79. apiProjectAccount.Router.Use(middleware.SessionsAuth)
  80. apiProjectAccount.Router.Use(middleware.AccessAuth)
  81. apiProjectAccount.Handle(new(api.ProjectAccountApi))
  82. // 标段相关接口
  83. apiBidsection := mvc.New(b.Party("/api/bidsection"))
  84. apiBidsection.Register(BidsectionService)
  85. apiBidsection.Router.Use(middleware.SessionsAuth)
  86. apiBidsection.Router.Use(middleware.AccessAuth)
  87. apiBidsection.Handle(new(api.BidsectionApi))
  88. // 项目设置接口
  89. apiSetting := mvc.New(b.Party("/api/projectSetting"))
  90. apiSetting.Register(ProjectAccountService)
  91. apiSetting.Register(ProjectService)
  92. apiSetting.Register(BidAccountService)
  93. apiSetting.Router.Use(middleware.SessionsAuth)
  94. apiSetting.Router.Use(middleware.AccessAuth)
  95. apiSetting.Handle(new(api.ProjectSettingApi))
  96. // TreeNode相关接口
  97. apiTree := mvc.New(b.Party("/api/tree"))
  98. apiTree.Register(TreeService)
  99. apiTree.Router.Use(middleware.SessionsAuth)
  100. apiTree.Router.Use(middleware.AccessAuth)
  101. apiTree.Handle(new(api.TreeApi))
  102. // 合同管理
  103. apiContract := mvc.New(b.Party("/api/contract"))
  104. apiContract.Register(TreeService)
  105. apiContract.Register(ContractService)
  106. // 中间件
  107. apiContract.Router.Use(middleware.SessionsAuth)
  108. apiContract.Router.Use(middleware.AccessAuth)
  109. apiContract.Handle(new(api.ContractApi))
  110. // rpc相关
  111. rpc := mvc.New(b.Party("/api/rpc/test"))
  112. rpc.Register(RpcService)
  113. rpc.Router.Use(middleware.SessionsAuth)
  114. rpc.Router.Use(middleware.AccessAuth)
  115. rpc.Handle(new(api.RpcApi))
  116. // safe
  117. apiSafe := mvc.New(b.Party("/api/safe"))
  118. apiSafe.Register(SafeService)
  119. apiSafe.Router.Use(middleware.SessionsAuth)
  120. apiSafe.Router.Use(middleware.AccessAuth)
  121. apiSafe.Handle(new(api.SafeApi))
  122. }