diff --git a/internal/handlers/collections.go b/internal/handlers/collections.go index e30121b3..0093b0e5 100644 --- a/internal/handlers/collections.go +++ b/internal/handlers/collections.go @@ -741,22 +741,15 @@ func (h *CollectionHandler) GetUserCollectionsList(c *echo.Context) ([]database. // userVisibleLibraryIDs loads the requester's visible-library set (the // family lens). Smart-collection evaluation funnels every book candidate // through it so hidden libraries contribute nothing. +// userVisibleLibraryIDs adapts the collection endpoints' identity +// source to the canonical resolver (H4.5). func (h *CollectionHandler) userVisibleLibraryIDs(c *echo.Context) ([]pgtype.UUID, error) { user, ok := c.Get("user").(database.Users) if !ok { return nil, echo.NewHTTPError(http.StatusUnauthorized, "invalid user") } - rows, err := h.libraryService.GetUserVisibleLibraries(c.Request().Context(), user.ID) - if err != nil { - return nil, fmt.Errorf("failed to check library access: %w", err) - } - ids := make([]pgtype.UUID, 0, len(rows)) - for _, lib := range rows { - if lib.ID.Valid { - ids = append(ids, lib.ID) - } - } - return ids, nil + _, ids, err := h.libraryService.VisibleLibrarySet(c.Request().Context(), user.ID) + return ids, err } // UserVisibleLibraryIDs is the exported entry point for the router's diff --git a/internal/router/helpers.go b/internal/router/helpers.go index c4eeb247..a97dbaed 100644 --- a/internal/router/helpers.go +++ b/internal/router/helpers.go @@ -255,18 +255,5 @@ func visibleLibraryIDsFor(c *echo.Context, cfg *Config) (map[string]bool, []pgty if err != nil { return nil, nil, echo.NewHTTPError(http.StatusUnauthorized, "invalid user") } - libraries, err := cfg.Queries.GetUserVisibleLibraries(c.Request().Context(), uuidToPGType(userU)) - if err != nil { - return nil, nil, err - } - set := make(map[string]bool, len(libraries)) - ids := make([]pgtype.UUID, 0, len(libraries)) - for _, lib := range libraries { - if !lib.ID.Valid { - continue - } - set[lib.ID.String()] = true - ids = append(ids, lib.ID) - } - return set, ids, nil + return cfg.LibraryService.VisibleLibrarySet(c.Request().Context(), uuidToPGType(userU)) }