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.
This commit is contained in:
2026-03-01 21:35:31 -05:00
parent 4f37a13519
commit a14b9c82ef
+13 -2
View File
@@ -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,
})
}