package server import ( "net/http" "gcy_hpc_server/internal/middleware" "github.com/gin-gonic/gin" "go.uber.org/zap" ) type JobHandler interface { SubmitJob(c *gin.Context) GetJobs(c *gin.Context) GetJobHistory(c *gin.Context) GetJob(c *gin.Context) CancelJob(c *gin.Context) } type ClusterHandler interface { GetNodes(c *gin.Context) GetNode(c *gin.Context) GetPartitions(c *gin.Context) GetPartition(c *gin.Context) GetDiag(c *gin.Context) } type TemplateHandler interface { ListTemplates(c *gin.Context) CreateTemplate(c *gin.Context) GetTemplate(c *gin.Context) UpdateTemplate(c *gin.Context) DeleteTemplate(c *gin.Context) } // NewRouter creates a Gin engine with all API v1 routes registered with real handlers. func NewRouter(jobH JobHandler, clusterH ClusterHandler, templateH TemplateHandler, logger *zap.Logger) *gin.Engine { gin.SetMode(gin.ReleaseMode) r := gin.New() r.Use(gin.Recovery()) if logger != nil { r.Use(middleware.RequestLogger(logger)) } v1 := r.Group("/api/v1") jobs := v1.Group("/jobs") jobs.POST("/submit", jobH.SubmitJob) jobs.GET("", jobH.GetJobs) jobs.GET("/history", jobH.GetJobHistory) jobs.GET("/:id", jobH.GetJob) jobs.DELETE("/:id", jobH.CancelJob) v1.GET("/nodes", clusterH.GetNodes) v1.GET("/nodes/:name", clusterH.GetNode) v1.GET("/partitions", clusterH.GetPartitions) v1.GET("/partitions/:name", clusterH.GetPartition) v1.GET("/diag", clusterH.GetDiag) templates := v1.Group("/templates") templates.GET("", templateH.ListTemplates) templates.POST("", templateH.CreateTemplate) templates.GET("/:id", templateH.GetTemplate) templates.PUT("/:id", templateH.UpdateTemplate) templates.DELETE("/:id", templateH.DeleteTemplate) return r } // NewTestRouter creates a router for testing without real handlers. func NewTestRouter() *gin.Engine { gin.SetMode(gin.TestMode) r := gin.New() r.Use(gin.Recovery()) v1 := r.Group("/api/v1") registerPlaceholderRoutes(v1) return r } func registerPlaceholderRoutes(v1 *gin.RouterGroup) { jobs := v1.Group("/jobs") jobs.POST("/submit", notImplemented) jobs.GET("", notImplemented) jobs.GET("/history", notImplemented) jobs.GET("/:id", notImplemented) jobs.DELETE("/:id", notImplemented) v1.GET("/nodes", notImplemented) v1.GET("/nodes/:name", notImplemented) v1.GET("/partitions", notImplemented) v1.GET("/partitions/:name", notImplemented) v1.GET("/diag", notImplemented) templates := v1.Group("/templates") templates.GET("", notImplemented) templates.POST("", notImplemented) templates.GET("/:id", notImplemented) templates.PUT("/:id", notImplemented) templates.DELETE("/:id", notImplemented) } func notImplemented(c *gin.Context) { c.JSON(http.StatusNotImplemented, APIResponse{ Success: false, Error: "not implemented", }) }