Show children in item class details
This commit is contained in:
parent
de65452a01
commit
52fcda5cfe
|
@ -27,19 +27,25 @@ async fn show_item_class(
|
||||||
) -> actix_web::Result<impl Responder> {
|
) -> actix_web::Result<impl Responder> {
|
||||||
let id = path.into_inner();
|
let id = path.into_inner();
|
||||||
|
|
||||||
let item_class = manage::item_class::get(&mut pool.clone().get().await.unwrap(), id)
|
let mut conn = pool.clone().get().await.unwrap();
|
||||||
|
|
||||||
|
let item_class = manage::item_class::get(&mut conn, id)
|
||||||
.await
|
.await
|
||||||
.map_err(error::ErrorInternalServerError)?;
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
// TODO: Once async closures are stable, use map_or on item_class.parent instead
|
// TODO: Once async closures are stable, use map_or on item_class.parent instead
|
||||||
let parent = match item_class.parent {
|
let parent = match item_class.parent {
|
||||||
Some(id) => manage::item_class::get(&mut pool.get().await.unwrap(), id)
|
Some(id) => manage::item_class::get(&mut conn, id)
|
||||||
.await
|
.await
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(error::ErrorInternalServerError)?,
|
.map_err(error::ErrorInternalServerError)?,
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let children = manage::item_class::children(&mut conn, id)
|
||||||
|
.await
|
||||||
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
let mut title = item_class.name.clone();
|
let mut title = item_class.name.clone();
|
||||||
title.push_str(" – Item Details");
|
title.push_str(" – Item Details");
|
||||||
|
|
||||||
|
@ -73,6 +79,18 @@ async fn show_item_class(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if !children.is_empty() {
|
||||||
|
h3 .mt-4 { "Children" }
|
||||||
|
|
||||||
|
ul {
|
||||||
|
@for child in children {
|
||||||
|
li {
|
||||||
|
a href={ "/item-class/" (child.id) } { (child.name) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,3 +83,14 @@ pub async fn delete(conn: &mut AsyncPgConnection, id: Uuid) -> Result<(), diesel
|
||||||
assert_eq!(num_deleted, 1);
|
assert_eq!(num_deleted, 1);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn children(
|
||||||
|
conn: &mut AsyncPgConnection,
|
||||||
|
id: Uuid,
|
||||||
|
) -> Result<Vec<ItemClass>, diesel::result::Error> {
|
||||||
|
schema::item_classes::table
|
||||||
|
.filter(schema::item_classes::parent.eq(id))
|
||||||
|
.select(ItemClass::as_select())
|
||||||
|
.load(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue