From a14b9c82efb16acb8e6e611cc028cf1747498c50 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 1 Mar 2026 21:35:31 -0500 Subject: [PATCH] fix(dashboard): normalize nil slices to empty arrays in preferences API Ensure consistent JSON responses by converting nil slices to empty arrays in the GetPreferences handler. This prevents null values from being returned to the client for hidden_collections and collection_order fields, making the API response more predictable and easier to consume. --- internal/handlers/dashboard.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/handlers/dashboard.go b/internal/handlers/dashboard.go index 895e321..5c199e5 100644 --- a/internal/handlers/dashboard.go +++ b/internal/handlers/dashboard.go @@ -210,9 +210,20 @@ func (h *DashboardHandler) GetPreferences(c echo.Context) error { if err != nil { return c.JSON(http.StatusNotFound, map[string]string{"error": "Preferences not found"}) } + + // Normalize nil slices to empty arrays for JSON + hiddenCollections := prefs.HiddenCollections + if hiddenCollections == nil { + hiddenCollections = []string{} + } + collectionOrder := prefs.CollectionOrder + if collectionOrder == nil { + collectionOrder = []string{} + } + return c.JSON(http.StatusOK, map[string]interface{}{ - "hidden_collections": prefs.HiddenCollections, - "collection_order": prefs.CollectionOrder, + "hidden_collections": hiddenCollections, + "collection_order": collectionOrder, "items_per_section": prefs.ItemsPerSection.Int32, }) }