turash/bugulma/backend/internal/routes/organizations.go

46 lines
1.8 KiB
Go

package routes
import (
"bugulma/backend/internal/handler"
"github.com/gin-gonic/gin"
)
// RegisterOrganizationRoutes registers all organization-related routes
func RegisterOrganizationRoutes(public *gin.RouterGroup, protected *gin.RouterGroup, orgHandler *handler.OrganizationHandler) {
// Public read-only routes
// CRITICAL: Register specific routes BEFORE parameterized routes to ensure correct matching
public.GET("/organizations", orgHandler.GetAll)
public.GET("/organizations/search", orgHandler.Search)
public.GET("/organizations/suggestions", orgHandler.SearchSuggestions)
public.GET("/organizations/sectors/stats", orgHandler.GetSectorStats)
public.GET("/organizations/subtypes", orgHandler.GetSubtypesBySector) // Supports ?sector=healthcare query param
public.GET("/organizations/subtypes/all", orgHandler.GetAllSubtypes) // Explicit endpoint for all subtypes
// Parameterized route must come LAST
public.GET("/organizations/:id", orgHandler.GetByID)
// Organization-specific routes
org := public.Group("/organizations/:id")
{
org.GET("/similar", orgHandler.GetSimilarOrganizations)
org.GET("/proposals", orgHandler.GetOrganizationProposals)
org.GET("/resources", orgHandler.GetOrganizationResources)
org.GET("/products", orgHandler.GetOrganizationProducts)
org.GET("/services", orgHandler.GetOrganizationServices)
org.GET("/matching/direct", orgHandler.GetDirectMatches)
}
// Protected write routes
orgs := protected.Group("/organizations")
{
orgs.POST("", orgHandler.Create)
orgs.PUT("/:id", orgHandler.Update)
orgs.DELETE("/:id", orgHandler.Delete)
// Image upload routes
orgs.POST("/:id/logo", orgHandler.UploadLogo)
orgs.POST("/:id/gallery", orgHandler.UploadGalleryImage)
orgs.DELETE("/:id/gallery", orgHandler.DeleteGalleryImage)
}
}