package routes import ( "bugulma/backend/internal/handler" "bugulma/backend/internal/service" "github.com/gin-gonic/gin" ) // RegisterAllRoutes registers all application routes organized by domain func RegisterAllRoutes( router *gin.Engine, orgHandler *handler.OrganizationHandler, siteHandler *handler.SiteHandler, resourceHandler *handler.ResourceFlowHandler, proposalHandler *handler.ProposalHandler, matchingHandler *handler.MatchingHandler, authHandler *handler.AuthHandler, sharedAssetHandler *handler.SharedAssetHandler, geospatialHandler *handler.GeospatialHandler, analyticsHandler *handler.AnalyticsHandler, aiHandler *handler.AIHandler, heritageHandler *handler.HeritageHandler, graphHandler *handler.GraphHandler, graphTraversalHandler *handler.GraphTraversalHandler, websocketService *service.WebSocketService, // New handlers userHandler *handler.UserHandler, orgAdminHandler *handler.OrganizationAdminHandler, i18nHandler *handler.I18nHandler, contentHandler *handler.ContentHandler, adminHandler *handler.AdminHandler, settingsHandler *handler.SettingsAdminHandler, subscriptionHandler *handler.SubscriptionHandler, authService *service.AuthService, discoveryHandler *handler.DiscoveryHandler, publicTransportHandler *handler.PublicTransportHandler, ) { // Public routes (no authentication required) public := router.Group("/api/v1") // Additional public routes for compatibility apiRoutes := router.Group("/api") // Protected routes (authentication required) // Note: Authentication middleware is applied via ContextMiddleware in setupRouter // Use middleware.AuthMiddleware for routes that require JWT authentication protected := router.Group("/api/v1") // Register routes by domain RegisterAuthRoutes(public, authHandler) RegisterUserRoutes(protected, orgHandler) RegisterOrganizationRoutes(public, protected, orgHandler) RegisterSiteRoutes(public, protected, siteHandler) RegisterResourceRoutes(public, protected, resourceHandler) RegisterProposalRoutes(public, protected, proposalHandler) RegisterMatchingRoutes(public, protected, matchingHandler) RegisterSharedAssetRoutes(public, protected, sharedAssetHandler) RegisterGeospatialRoutes(public, geospatialHandler) RegisterPublicTransportRoutes(public, publicTransportHandler) RegisterAnalyticsRoutes(public, analyticsHandler) RegisterAIRoutes(public, aiHandler) RegisterHeritageRoutes(public, heritageHandler) RegisterGraphRoutes(public, protected, graphHandler, graphTraversalHandler) // Register graph routes under /api for frontend compatibility RegisterGraphRoutesForAPI(apiRoutes, graphHandler) RegisterWebSocketRoutes(protected, websocketService) // Register admin routes if userHandler != nil && orgAdminHandler != nil && i18nHandler != nil && contentHandler != nil && adminHandler != nil && authService != nil { RegisterAdminRoutes(protected, userHandler, orgAdminHandler, i18nHandler, contentHandler, adminHandler, settingsHandler, authService) } // Register subscription routes if subscriptionHandler != nil && authService != nil { RegisterSubscriptionRoutes(protected, subscriptionHandler, authService) } // Register discovery routes if discoveryHandler != nil { RegisterDiscoveryRoutes(public, protected, discoveryHandler) } } // RegisterDiscoveryRoutes registers discovery/search routes func RegisterDiscoveryRoutes(public, protected *gin.RouterGroup, discoveryHandler *handler.DiscoveryHandler) { if discoveryHandler == nil { return } discovery := public.Group("/discovery") { // Search endpoints (public) discovery.GET("/search", discoveryHandler.UniversalSearch) discovery.GET("/products", discoveryHandler.SearchProducts) discovery.GET("/services", discoveryHandler.SearchServices) discovery.GET("/community", discoveryHandler.SearchCommunity) discovery.GET("/categories", discoveryHandler.GetCategories) // Creation endpoints (protected - require authentication) discoveryProtected := protected.Group("/discovery") { discoveryProtected.POST("/products", discoveryHandler.CreateProductListing) discoveryProtected.POST("/services", discoveryHandler.CreateServiceListing) discoveryProtected.POST("/community", discoveryHandler.CreateCommunityListing) } } } // RegisterGraphRoutesForAPI registers graph routes under /api path for frontend compatibility func RegisterGraphRoutesForAPI(apiRoutes *gin.RouterGroup, graphHandler *handler.GraphHandler) { // Public read-only routes under /api for frontend compatibility if graphHandler != nil { graph := apiRoutes.Group("/graph") { graph.GET("/organizations/:organizationId/network", graphHandler.GetOrganizationNetwork) graph.GET("/shortest-path", graphHandler.FindShortestPath) graph.GET("/spatial-proximity", graphHandler.GetSpatialProximity) graph.GET("/matching-opportunities", graphHandler.GetMatchingOpportunities) graph.GET("/statistics", graphHandler.GetGraphStatistics) } } }