routes.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. RuleService := services.NewRuleService()
  28. //CSRF相关
  29. b.Use(middleware.SetCsrf)
  30. //b.Party("/", protect)
  31. //protect := NewCsrf()
  32. //登录相关
  33. //login := mvc.New(b.Party("/", protect))
  34. login := mvc.New(b.Party("/"))
  35. login.Register(ProjectAccountService)
  36. login.Register(LoginService)
  37. login.Handle(new(controllers.LoginController))
  38. // todolist相关
  39. todo := mvc.New(b.Party("/todolist"))
  40. todo.Router.Use(middleware.SessionsAuth)
  41. todo.Handle(new(controllers.TodoController))
  42. // // 合同管理
  43. // contract := mvc.New(b.Party("/contract"))
  44. // contract.Router.Use(middleware.SessionsAuth)
  45. // contract.Handle(new(controllers.ContractController))
  46. // 安全巡检
  47. //用户相关
  48. account := mvc.New(b.Party("/account"))
  49. account.Register(ProjectAccountService)
  50. account.Router.Use(middleware.SessionsAuth)
  51. account.Handle(new(controllers.AccountController))
  52. // 项目相关
  53. project := mvc.New(b.Party("/project"))
  54. project.Router.Use(middleware.SessionsAuth)
  55. project.Register(TreeService)
  56. project.Register(ProjectService)
  57. project.Handle(new(controllers.ProjectController))
  58. //标段相关
  59. bidsection := mvc.New(b.Party("/bidsection"))
  60. bidsection.Register(ProjectService)
  61. bidsection.Router.Use(middleware.SessionsAuth)
  62. bidsection.Handle(new(controllers.BidsectionController))
  63. // apiTree.Router.Use(middleware.JwtAuth().Serve)
  64. // 接口相关
  65. // 登陆接口
  66. apiLogin := mvc.New(b.Party("/api/login"))
  67. apiLogin.Register(ProjectAccountService)
  68. apiLogin.Register(LoginService)
  69. apiLogin.Register(ProjectService)
  70. apiLogin.Handle(new(api.LoginApi))
  71. // 项目相关接口
  72. apiProject := mvc.New(b.Party("/api/project"))
  73. apiProject.Register(ProjectService)
  74. apiProject.Router.Use(middleware.SessionsAuth)
  75. apiProject.Router.Use(middleware.AccessAuth)
  76. apiProject.Handle(new(api.ProjectApi))
  77. // 项目账号相关接口
  78. apiProjectAccount := mvc.New(b.Party("/api/projectAccount"))
  79. apiProjectAccount.Register(ProjectAccountService)
  80. apiProjectAccount.Router.Use(middleware.SessionsAuth)
  81. apiProjectAccount.Router.Use(middleware.AccessAuth)
  82. apiProjectAccount.Handle(new(api.ProjectAccountApi))
  83. // 标段相关接口
  84. apiBidsection := mvc.New(b.Party("/api/bidsection"))
  85. apiBidsection.Register(BidsectionService)
  86. apiBidsection.Router.Use(middleware.SessionsAuth)
  87. apiBidsection.Router.Use(middleware.AccessAuth)
  88. apiBidsection.Handle(new(api.BidsectionApi))
  89. // 项目设置接口
  90. apiSetting := mvc.New(b.Party("/api/projectSetting"))
  91. apiSetting.Register(ProjectAccountService)
  92. apiSetting.Register(ProjectService)
  93. apiSetting.Register(BidAccountService)
  94. apiSetting.Router.Use(middleware.SessionsAuth)
  95. apiSetting.Router.Use(middleware.AccessAuth)
  96. apiSetting.Handle(new(api.ProjectSettingApi))
  97. // TreeNode相关接口
  98. apiTree := mvc.New(b.Party("/api/tree"))
  99. apiTree.Register(TreeService)
  100. apiTree.Router.Use(middleware.SessionsAuth)
  101. apiTree.Router.Use(middleware.AccessAuth)
  102. apiTree.Handle(new(api.TreeApi))
  103. // 合同管理
  104. apiContract := mvc.New(b.Party("/api/contract"))
  105. apiContract.Register(TreeService)
  106. apiContract.Register(ContractService)
  107. // 中间件
  108. apiContract.Router.Use(middleware.SessionsAuth)
  109. apiContract.Router.Use(middleware.AccessAuth)
  110. apiContract.Handle(new(api.ContractApi))
  111. // rpc相关
  112. // rpc := mvc.New(b.Party("/api/rpc/test"))
  113. // rpc.Register(RpcService)
  114. // rpc.Router.Use(middleware.SessionsAuth)
  115. // rpc.Router.Use(middleware.AccessAuth)
  116. // rpc.Handle(new(api.RpcApi))
  117. // safe
  118. apiSafe := mvc.New(b.Party("/api/safe"))
  119. apiSafe.Register(SafeService)
  120. apiSafe.Router.Use(middleware.SessionsAuth)
  121. apiSafe.Router.Use(middleware.AccessAuth)
  122. apiSafe.Handle(new(api.SafeApi))
  123. // rule
  124. apiRule := mvc.New(b.Party("/api/rule"))
  125. apiRule.Register(RuleService)
  126. apiRule.Router.Use(middleware.SessionsAuth)
  127. apiRule.Router.Use(middleware.AccessAuth)
  128. apiRule.Handle(new(api.RuleApi))
  129. }