WIP4
This commit is contained in:
@@ -153,9 +153,37 @@ impl LibraryItemSqliteRepository {
|
|||||||
|
|
||||||
let raw_data = rows.map(Self::map_to_raw_entity).collect::<Vec<LibraryItemRawEntity>>()?;
|
let raw_data = rows.map(Self::map_to_raw_entity).collect::<Vec<LibraryItemRawEntity>>()?;
|
||||||
|
|
||||||
|
// Build a map of id to LibraryItemEntity for quick lookup
|
||||||
|
let mut entity_map: std::collections::HashMap<Uuid, LibraryItemEntity> = std::collections::HashMap::new();
|
||||||
|
|
||||||
|
// First pass: create all entities without parent relationships
|
||||||
|
for raw_entity in &raw_data {
|
||||||
|
let entity = LibraryItemEntity {
|
||||||
|
id: raw_entity.id.clone(),
|
||||||
|
name: raw_entity.name.clone(),
|
||||||
|
r#type: raw_entity.r#type,
|
||||||
|
parent_folder_id: None, // Will be set in second pass
|
||||||
|
};
|
||||||
|
entity_map.insert(raw_entity.id.clone(), entity);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(None)
|
// Second pass: set up parent-child relationships
|
||||||
|
for raw_entity in &raw_data {
|
||||||
|
if let Some(parent_id) = &raw_entity.parent_item_id {
|
||||||
|
if let Some(child_entity) = entity_map.get_mut(&raw_entity.id) {
|
||||||
|
if let Some(parent_entity) = entity_map.get(parent_id) {
|
||||||
|
child_entity.parent_folder_id = Some(Box::new(parent_entity.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the requested item and return it with its full hierarchy
|
||||||
|
if let Some(entity) = entity_map.get(library_item_id) {
|
||||||
|
Ok(Some(entity.clone()))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_to_raw_entity(row: &Row) -> Result<LibraryItemRawEntity, Error> {
|
fn map_to_raw_entity(row: &Row) -> Result<LibraryItemRawEntity, Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user