Skip to content

Commit

Permalink
Don't ignore error
Browse files Browse the repository at this point in the history
  • Loading branch information
Zokhoi committed Sep 24, 2024
1 parent 6c47b24 commit b0ae2dc
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions deepwell/src/endpoints/parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::services::parent::{
UpdateParentsOutput,
};
use crate::web::Reference;
use futures::future::try_join_all;

pub async fn parent_relationships_get(
ctx: &ServiceContext<'_>,
Expand Down Expand Up @@ -128,44 +129,47 @@ pub async fn parent_update(

let creation = match input.add {
Some(parents) => {
let mut creation = Vec::new();
for parent in parents {
if let Ok(Some(model)) = ParentService::create(
let creation = parents.iter().map(|parent| {
ParentService::create(
ctx,
ParentDescription {
site_id: input.site_id,
parent: parent.to_owned(),
child: input.child.clone(),
},
)
.await
{
creation.push(model.parent_page_id);
};
}
Some(creation)
});
Some(
try_join_all(creation)
.await?
.iter()
.flatten()
.map(|p| p.parent_page_id)
.collect(),
)
}
None => None,
};

let removal = match input.remove {
Some(parents) => {
let mut removal = Vec::new();
for parent in parents {
if let Ok(res) = ParentService::remove(
let removal = parents.iter().map(|parent| {
ParentService::remove(
ctx,
ParentDescription {
site_id: input.site_id,
parent: parent.to_owned(),
child: input.child.clone(),
},
)
.await
{
removal.push(res.was_deleted);
};
}
Some(removal)
});
Some(
try_join_all(removal)
.await?
.iter()
.map(|p| p.was_deleted)
.collect(),
)
}
None => None,
};
Expand Down

0 comments on commit b0ae2dc

Please sign in to comment.