feat(item_list): remove JSON deserialization of custom properties in items loader
This commit is contained in:
parent
5815c9fe10
commit
af1e6d949f
1 changed files with 10 additions and 21 deletions
|
@ -38,33 +38,22 @@ pub async fn load_items_from_db(current_url: &str) -> Result<Vec<Item>, String>
|
|||
// Deserialize into Vec<DbItem>
|
||||
log!("Loading items from DB...");
|
||||
let db_items = response
|
||||
.json::<Vec<DbItem>>()
|
||||
.json::<Vec<Item>>()
|
||||
.await
|
||||
.map_err(|err| format!("Failed to parse items: {:?}", err))?;
|
||||
|
||||
// log!("Deserialized DB items: {:?}", db_items);
|
||||
|
||||
// Convert DbItem to Item
|
||||
let items = db_items
|
||||
.into_iter()
|
||||
.map(|db_item| {
|
||||
// Deserialize `custom_properties` from a JSON string to a HashMap
|
||||
let custom_properties: HashMap<String, String> =
|
||||
serde_json::from_str(&db_item.custom_properties)
|
||||
.unwrap_or_default(); // Fallback to an empty HashMap if deserialization fails
|
||||
|
||||
log!("Loaded item: {:?}", db_item.id);
|
||||
log!("Custom properties: {:?}", custom_properties);
|
||||
|
||||
Item {
|
||||
id: db_item.id,
|
||||
name: db_item.name,
|
||||
description: db_item.description,
|
||||
wikidata_id: db_item.wikidata_id,
|
||||
custom_properties,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let items = db_items.into_iter().map(|db_item| {
|
||||
Item {
|
||||
id: db_item.id,
|
||||
name: db_item.name,
|
||||
description: db_item.description,
|
||||
wikidata_id: db_item.wikidata_id,
|
||||
custom_properties: HashMap::new() // Now populated from joins
|
||||
}
|
||||
}).collect();
|
||||
// log!("Converted items: {:?}", items);
|
||||
Ok(items)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue