From 8dbaa8f810dfa45e61ed07c801a9f3baae98c25b Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 17 Oct 2026 17:32:11 -0400 Subject: [PATCH] =?UTF-8?q?refactor(vis):=20H4.5=20step=203=20=E2=80=94=20?= =?UTF-8?q?collections=20endpoint=20and=20the=20SSR=20helper=20on=20the=20?= =?UTF-8?q?canonical=20resolver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit collections.userVisibleLibraryIDs keeps its identity adapter and delegates; the router's visibleLibraryIDsFor likewise (its identity source is the session user_id string, the site-specific part it keeps). The SSR site made the unification slog-proof: resolveLibrary — the SSR one-of-a-kind (active selection + switcher rows + offline detection) — stays untouched per the semantic diff. --- internal/handlers/collections.go | 15 ++++----------- internal/router/helpers.go | 15 +-------------- 2 files changed, 5 insertions(+), 25 deletions(-) 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)) }