package handler import ( "fmt" "net/http" "github.com/gin-gonic/gin" "spider/internal/store" "spider/internal/task" ) // SetupRouter builds and returns the Gin engine with all routes registered. func SetupRouter(s *store.Store, taskMgr *task.Manager) *gin.Engine { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "pong"}) }) api := r.Group("/api/v1") // Keywords (unified: search keywords + seeds) kw := &KeywordHandler{store: s} api.GET("/keywords", kw.List) api.POST("/keywords", kw.Create) api.PUT("/keywords/:id", kw.Update) api.DELETE("/keywords/:id", kw.Delete) // Merchants mc := &MerchantHandler{store: s} api.GET("/merchants/stats", mc.Stats) api.GET("/merchants/raw", mc.ListRaw) api.GET("/merchants/clean", mc.ListClean) api.GET("/merchants/clean/export", mc.ExportCSV) api.GET("/merchants/:id", mc.GetByID) // Tasks th := &TaskHandler{store: s, taskMgr: taskMgr} api.GET("/tasks", th.List) api.POST("/tasks/start", th.Start) api.GET("/tasks/:id", th.Get) api.POST("/tasks/:id/stop", th.Stop) api.GET("/tasks/:id/logs", th.Logs) return r } // ServerAddr returns the listen address string for the given port. func ServerAddr(port int) string { return fmt.Sprintf(":%d", port) }