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