fix location recursion

This commit is contained in:
JMARyA 2024-09-22 02:38:03 +02:00
parent bfd4c1c0b9
commit 7f32f2429e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 44 additions and 6 deletions

View file

@ -55,6 +55,31 @@ impl Location {
}
.boxed()
}
// Get direct children
pub async fn children_direct(&self) -> Vec<Location> {
Location::find(doc! { "parent": self._id.clone()}, None, None)
.await
.unwrap()
}
// Get all children locations
pub fn children_recursive<'a>(&'a self) -> futures::future::BoxFuture<'a, Vec<Location>> {
async move {
let mut all = Vec::new();
let direct = self.children_direct().await;
all.extend_from_slice(&direct);
for loc in direct {
let sub = loc.children_recursive().await;
all.extend_from_slice(&sub);
}
all
}
.boxed()
}
}
impl ToAPI for Location {