From 6454ade2f77049fb682cb8ee056999c60631408b Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 2 Mar 2026 13:48:29 -0500 Subject: [PATCH] fix(dashboard): Return default preferences instead of 404 The GetPreferences API was returning 404 when no preferences existed for a library, breaking the dashboard settings modal. Now returns default preferences (empty hidden_collections, empty collection_order, 20 items_per_section) when no preferences are found, matching the behavior of the frontend dashboard page. --- internal/handlers/dashboard.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/handlers/dashboard.go b/internal/handlers/dashboard.go index aa653d5..0d834cb 100644 --- a/internal/handlers/dashboard.go +++ b/internal/handlers/dashboard.go @@ -4,6 +4,7 @@ import ( "bookhoard/internal/database" "bookhoard/internal/services" "bookhoard/internal/utils" + "log" "net/http" "strconv" @@ -200,7 +201,6 @@ func (h *DashboardHandler) GetPreferences(c echo.Context) error { userUUID := uuid.UUID(user.ID.Bytes) libraryID := c.QueryParam("library_id") - // ✅ Add validation if libraryID == "" { return c.JSON(http.StatusBadRequest, map[string]string{"error": "library_id required"}) } @@ -211,7 +211,13 @@ func (h *DashboardHandler) GetPreferences(c echo.Context) error { } prefs, err := h.dashboardService.GetDashboardPreferences(c.Request().Context(), userUUID, libUUID) if err != nil { - return c.JSON(http.StatusNotFound, map[string]string{"error": "Preferences not found"}) + // Return default preferences instead of 404 when none exist + log.Printf("GetDashboardPreferences failed: %v", err) + prefs = database.UserDashboardPreferences{ + HiddenCollections: []string{}, + CollectionOrder: []string{}, + ItemsPerSection: pgtype.Int4{Int32: 20, Valid: true}, + } } // Normalize nil slices to empty arrays for JSON