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>
|
// Deserialize into Vec<DbItem>
|
||||||
log!("Loading items from DB...");
|
log!("Loading items from DB...");
|
||||||
let db_items = response
|
let db_items = response
|
||||||
.json::<Vec<DbItem>>()
|
.json::<Vec<Item>>()
|
||||||
.await
|
.await
|
||||||
.map_err(|err| format!("Failed to parse items: {:?}", err))?;
|
.map_err(|err| format!("Failed to parse items: {:?}", err))?;
|
||||||
|
|
||||||
// log!("Deserialized DB items: {:?}", db_items);
|
// log!("Deserialized DB items: {:?}", db_items);
|
||||||
|
|
||||||
// Convert DbItem to Item
|
// Convert DbItem to Item
|
||||||
let items = db_items
|
let items = db_items.into_iter().map(|db_item| {
|
||||||
.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 {
|
Item {
|
||||||
id: db_item.id,
|
id: db_item.id,
|
||||||
name: db_item.name,
|
name: db_item.name,
|
||||||
description: db_item.description,
|
description: db_item.description,
|
||||||
wikidata_id: db_item.wikidata_id,
|
wikidata_id: db_item.wikidata_id,
|
||||||
custom_properties,
|
custom_properties: HashMap::new() // Now populated from joins
|
||||||
}
|
}
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
// log!("Converted items: {:?}", items);
|
// log!("Converted items: {:?}", items);
|
||||||
Ok(items)
|
Ok(items)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue