Show direct children for item

This commit is contained in:
Simon Bruder 2024-07-08 22:45:28 +02:00
parent b736eba0a0
commit 5147257e72
Signed by: simon
GPG key ID: 347FF8699CDA0776
3 changed files with 27 additions and 0 deletions

View file

@ -28,6 +28,7 @@ struct ItemDetails {
item: Item,
item_class: ItemClass,
parents: Vec<Item>,
children: Vec<Item>,
}
#[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,
})
}

View file

@ -122,3 +122,14 @@ pub async fn get_parents_details(
.load(conn)
.await
}
pub async fn get_children(
conn: &mut AsyncPgConnection,
id: Uuid,
) -> Result<Vec<Item>, diesel::result::Error> {
schema::items::table
.filter(schema::items::parent.eq(id))
.select(Item::as_select())
.load(conn)
.await
}

View file

@ -49,4 +49,14 @@ SPDX-License-Identifier: AGPL-3.0-or-later
</tr>
</tbody>
</table>
{% if children.len() != 0 %}
<h3 class="mt-4">Direct Children</h3>
<ul>
{% for child in children %}
<li><a href="/item/{{ child.id }}">{{ child.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}