routes.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package routes
  2. import (
  3. "ems-backend/controllers"
  4. "ems-backend/middleware"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func SetupRoutes(r *gin.Engine) {
  8. // Public Routes
  9. r.POST("/api/v1/login", controllers.Login)
  10. api := r.Group("/api/v1")
  11. api.Use(middleware.AuthRequired())
  12. {
  13. // Menu & Perms
  14. api.GET("/getRouters", controllers.GetRouters)
  15. api.GET("/system/menu/tree", controllers.GetMenuTree)
  16. api.GET("/system/role/:roleId/menus", controllers.GetRoleMenuIds)
  17. // Integration Sources
  18. api.GET("/sources", controllers.GetSources)
  19. api.POST("/sources", controllers.CreateSource)
  20. api.PUT("/sources/:id", controllers.UpdateSource)
  21. api.DELETE("/sources/:id", controllers.DeleteSource)
  22. api.POST("/sources/test", controllers.TestSourceConnection) // 测试连接
  23. api.GET("/sources/:id/candidates", controllers.GetSourceCandidates) // 获取候选设备 (Legacy)
  24. api.GET("/sources/:id/devices", controllers.GetSourceDevices) // 获取HA设备列表
  25. api.GET("/sources/:id/devices/:deviceId/entities", controllers.GetSourceDeviceEntities) // 获取HA设备实体
  26. api.POST("/sources/:id/sync", controllers.SyncSource) // 立即同步
  27. // Devices
  28. api.GET("/devices", controllers.GetDevices)
  29. api.GET("/devices/history", controllers.GetDeviceHistory)
  30. api.POST("/devices", controllers.CreateDevice)
  31. api.PUT("/devices/:id", controllers.UpdateDevice)
  32. api.DELETE("/devices/:id", controllers.DeleteDevice)
  33. // Locations
  34. api.GET("/locations", controllers.GetLocations)
  35. api.POST("/locations", controllers.CreateLocation)
  36. api.PUT("/locations/:id", controllers.UpdateLocation)
  37. api.DELETE("/locations/:id", controllers.DeleteLocation)
  38. // Dashboard & Control
  39. api.GET("/dashboard/stats", controllers.GetDashboardStats)
  40. api.POST("/control/:id", controllers.ControlDevice)
  41. // Alarms
  42. api.GET("/alarms", controllers.GetAlarms)
  43. api.POST("/alarms", controllers.CreateAlarm)
  44. api.PUT("/alarms/:id/ack", controllers.AcknowledgeAlarm)
  45. // Energy Analysis
  46. api.GET("/analysis/energy", controllers.GetEnergyAnalysis)
  47. // Inspections
  48. api.GET("/inspections", controllers.GetInspections)
  49. api.POST("/inspections", controllers.CreateInspection)
  50. // System & Settings
  51. sys := api.Group("/system")
  52. {
  53. // Roles
  54. sys.GET("/roles", controllers.GetRoles)
  55. sys.POST("/roles", controllers.CreateRole)
  56. sys.PUT("/roles/:id", controllers.UpdateRole)
  57. sys.DELETE("/roles/:id", controllers.DeleteRole)
  58. // Users
  59. sys.GET("/users", controllers.GetUsers)
  60. sys.POST("/users", controllers.CreateUser)
  61. sys.PUT("/users/:id", controllers.UpdateUser)
  62. sys.DELETE("/users/:id", controllers.DeleteUser)
  63. // User Profile (Self)
  64. sys.GET("/user/profile", controllers.GetProfile)
  65. sys.PUT("/user/profile/updatePwd", controllers.UpdateProfilePwd)
  66. // Configs
  67. sys.GET("/configs", controllers.GetAllConfigs)
  68. sys.GET("/config/:key", controllers.GetConfig)
  69. sys.POST("/config", controllers.UpdateConfig)
  70. }
  71. }
  72. }