fix location recursion
This commit is contained in:
parent
bfd4c1c0b9
commit
7f32f2429e
2 changed files with 44 additions and 6 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue