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:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user