From 5147257e72d3f63d285771cd289a929da24293cd Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 8 Jul 2024 22:45:28 +0200 Subject: [PATCH] Show direct children for item --- src/frontend/item.rs | 6 ++++++ src/manage/item.rs | 11 +++++++++++ templates/item_details.html | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/frontend/item.rs b/src/frontend/item.rs index 5c718ad..61e6f85 100644 --- a/src/frontend/item.rs +++ b/src/frontend/item.rs @@ -28,6 +28,7 @@ struct ItemDetails { item: Item, item_class: ItemClass, parents: Vec, + children: Vec, } #[get("/item/{id}")] @@ -50,11 +51,16 @@ async fn show_item( .await .map_err(error::ErrorInternalServerError)?; + let children = manage::item::get_children(&mut pool.get().await.unwrap(), item.id) + .await + .map_err(error::ErrorInternalServerError)?; + Ok(ItemDetails { req, item, item_class, parents, + children, }) } diff --git a/src/manage/item.rs b/src/manage/item.rs index d9d453e..a85cbdd 100644 --- a/src/manage/item.rs +++ b/src/manage/item.rs @@ -122,3 +122,14 @@ pub async fn get_parents_details( .load(conn) .await } + +pub async fn get_children( + conn: &mut AsyncPgConnection, + id: Uuid, +) -> Result, diesel::result::Error> { + schema::items::table + .filter(schema::items::parent.eq(id)) + .select(Item::as_select()) + .load(conn) + .await +} diff --git a/templates/item_details.html b/templates/item_details.html index 213c243..67f4263 100644 --- a/templates/item_details.html +++ b/templates/item_details.html @@ -49,4 +49,14 @@ SPDX-License-Identifier: AGPL-3.0-or-later + +{% if children.len() != 0 %} +

Direct Children

+ + +{% endif %} {% endblock %}