package handler import ( "net/http" "github.com/gin-gonic/gin" "github.com/yuxingu/digital-psychology/apps/api/internal/explore" "github.com/yuxingu/digital-psychology/apps/api/internal/service/scale" "github.com/yuxingu/digital-psychology/apps/api/pkg/response" ) // ExploreHandler serves the explore catalog. type ExploreHandler struct { Scales *scale.Service } // Register mounts explore routes. func (h *ExploreHandler) Register(rg *gin.RouterGroup) { rg.GET("/explore/catalog", h.Catalog) rg.GET("/explore/catalog/:key", h.Category) } // Catalog handles GET /explore/catalog. func (h *ExploreHandler) Catalog(c *gin.Context) { cats := explore.Catalog() if h.Scales != nil { if items, err := h.Scales.List(c.Request.Context()); err == nil { cats = explore.WithPublishedScales(cats, items) } } response.OK(c, gin.H{"categories": cats}) } // Category handles GET /explore/catalog/:key. func (h *ExploreHandler) Category(c *gin.Context) { cat := explore.CategoryByKey(c.Param("key")) if cat == nil { response.Fail(c, http.StatusNotFound, 40402, "category not found") return } if cat.Key == "tests" && h.Scales != nil { if items, err := h.Scales.List(c.Request.Context()); err == nil { enriched := explore.WithPublishedScales([]explore.Category{*cat}, items) if len(enriched) > 0 { response.OK(c, enriched[0]) return } } } response.OK(c, cat) }