routes.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. AnnexService := services.NewAnnexService()
  29. SafeAuditService := services.NewSafeAuditService()
  30. QualityService := services.NewQualityService()
  31. QualityAuditService := services.NewQualityAuditService()
  32. //CSRF相关
  33. b.Use(middleware.SetCsrf)
  34. //b.Party("/", protect)
  35. //protect := NewCsrf()
  36. //登录相关
  37. //login := mvc.New(b.Party("/", protect))
  38. login := mvc.New(b.Party("/"))
  39. login.Register(ProjectAccountService)
  40. login.Register(LoginService)
  41. login.Handle(new(controllers.LoginController))
  42. // todolist相关
  43. todo := mvc.New(b.Party("/todolist"))
  44. todo.Router.Use(middleware.SessionsAuth)
  45. todo.Handle(new(controllers.TodoController))
  46. // // 合同管理
  47. // contract := mvc.New(b.Party("/contract"))
  48. // contract.Router.Use(middleware.SessionsAuth)
  49. // contract.Handle(new(controllers.ContractController))
  50. // 安全巡检
  51. //用户相关
  52. account := mvc.New(b.Party("/account"))
  53. account.Register(ProjectAccountService)
  54. account.Router.Use(middleware.SessionsAuth)
  55. account.Handle(new(controllers.AccountController))
  56. // 项目相关
  57. project := mvc.New(b.Party("/project"))
  58. project.Router.Use(middleware.SessionsAuth)
  59. project.Register(TreeService)
  60. project.Register(ProjectService)
  61. project.Handle(new(controllers.ProjectController))
  62. //标段相关
  63. bidsection := mvc.New(b.Party("/bidsection"))
  64. bidsection.Register(ProjectService)
  65. bidsection.Router.Use(middleware.SessionsAuth)
  66. bidsection.Handle(new(controllers.BidsectionController))
  67. // apiTree.Router.Use(middleware.JwtAuth().Serve)
  68. // 接口相关
  69. // 登陆接口
  70. apiLogin := mvc.New(b.Party("/api/login"))
  71. apiLogin.Register(ProjectAccountService)
  72. apiLogin.Register(LoginService)
  73. apiLogin.Register(ProjectService)
  74. apiLogin.Handle(new(api.LoginApi))
  75. // 项目相关接口
  76. apiProject := mvc.New(b.Party("/api/project"))
  77. apiProject.Register(ProjectService)
  78. apiProject.Router.Use(middleware.SessionsAuth)
  79. apiProject.Router.Use(middleware.AccessAuth)
  80. apiProject.Handle(new(api.ProjectApi))
  81. // 项目账号相关接口
  82. apiProjectAccount := mvc.New(b.Party("/api/projectAccount"))
  83. apiProjectAccount.Register(ProjectAccountService)
  84. apiProjectAccount.Router.Use(middleware.SessionsAuth)
  85. apiProjectAccount.Router.Use(middleware.AccessAuth)
  86. apiProjectAccount.Handle(new(api.ProjectAccountApi))
  87. // 标段相关接口
  88. apiBidsection := mvc.New(b.Party("/api/bidsection"))
  89. apiBidsection.Register(BidsectionService)
  90. apiBidsection.Router.Use(middleware.SessionsAuth)
  91. apiBidsection.Router.Use(middleware.AccessAuth)
  92. apiBidsection.Handle(new(api.BidsectionApi))
  93. // 项目设置接口
  94. apiSetting := mvc.New(b.Party("/api/projectSetting"))
  95. apiSetting.Register(ProjectAccountService)
  96. apiSetting.Register(ProjectService)
  97. apiSetting.Register(BidAccountService)
  98. apiSetting.Router.Use(middleware.SessionsAuth)
  99. apiSetting.Router.Use(middleware.AccessAuth)
  100. apiSetting.Handle(new(api.ProjectSettingApi))
  101. // TreeNode相关接口
  102. apiTree := mvc.New(b.Party("/api/tree"))
  103. apiTree.Register(TreeService)
  104. apiTree.Router.Use(middleware.SessionsAuth)
  105. apiTree.Router.Use(middleware.AccessAuth)
  106. apiTree.Handle(new(api.TreeApi))
  107. // 合同管理
  108. apiContract := mvc.New(b.Party("/api/contract"))
  109. apiContract.Register(TreeService)
  110. apiContract.Register(ContractService)
  111. // 中间件
  112. apiContract.Router.Use(middleware.SessionsAuth)
  113. apiContract.Router.Use(middleware.AccessAuth)
  114. apiContract.Handle(new(api.ContractApi))
  115. // oss相关
  116. apiOss := mvc.New(b.Party("/api/oss"))
  117. apiOss.Router.Use(middleware.SessionsAuth)
  118. apiOss.Router.Use(middleware.AccessAuth)
  119. apiOss.Handle(new(api.OssApi))
  120. // rpc相关
  121. // rpc := mvc.New(b.Party("/api/rpc/test"))
  122. // rpc.Register(RpcService)
  123. // rpc.Router.Use(middleware.SessionsAuth)
  124. // rpc.Router.Use(middleware.AccessAuth)
  125. // rpc.Handle(new(api.RpcApi))
  126. // safe
  127. apiSafe := mvc.New(b.Party("/api/safe"))
  128. apiSafe.Register(SafeService)
  129. apiSafe.Router.Use(middleware.SessionsAuth)
  130. apiSafe.Router.Use(middleware.AccessAuth)
  131. apiSafe.Handle(new(api.SafeApi))
  132. apiSafeAudit := mvc.New(b.Party("/api/safe_audit"))
  133. apiSafeAudit.Register(SafeAuditService)
  134. apiSafeAudit.Router.Use(middleware.SessionsAuth)
  135. apiSafeAudit.Router.Use(middleware.AccessAuth)
  136. apiSafeAudit.Handle(new(api.SafeAuditApi))
  137. // quality
  138. apiQuality := mvc.New(b.Party("/api/quality"))
  139. apiQuality.Register(QualityService)
  140. apiQuality.Router.Use(middleware.SessionsAuth)
  141. apiQuality.Router.Use(middleware.AccessAuth)
  142. apiQuality.Handle(new(api.QualityApi))
  143. apiQualityAudit := mvc.New(b.Party("/api/quality_audit"))
  144. apiQualityAudit.Register(QualityAuditService)
  145. apiQualityAudit.Router.Use(middleware.SessionsAuth)
  146. apiQualityAudit.Router.Use(middleware.AccessAuth)
  147. apiQualityAudit.Handle(new(api.QualityAuditApi))
  148. // rule
  149. apiRule := mvc.New(b.Party("/api/rule"))
  150. apiRule.Register(RuleService)
  151. apiRule.Router.Use(middleware.SessionsAuth)
  152. apiRule.Router.Use(middleware.AccessAuth)
  153. apiRule.Handle(new(api.RuleApi))
  154. // file
  155. apiAnnex := mvc.New(b.Party("/api/file"))
  156. apiAnnex.Register(AnnexService)
  157. apiAnnex.Router.Use(middleware.SessionsAuth)
  158. apiAnnex.Router.Use(middleware.AccessAuth)
  159. apiAnnex.Handle(new(api.AnnexApi))
  160. apiDashboard := mvc.New(b.Party("/api/dashboard"))
  161. apiDashboard.Register(SafeService)
  162. apiDashboard.Register(QualityService)
  163. apiDashboard.Router.Use(middleware.SessionsAuth)
  164. apiDashboard.Router.Use(middleware.AccessAuth)
  165. apiDashboard.Handle(new(api.DashboardApi))
  166. }