diff --git a/src/database/hierarchies.rs b/src/database/hierarchies.rs index ac7ed73..65a4afb 100644 --- a/src/database/hierarchies.rs +++ b/src/database/hierarchies.rs @@ -122,22 +122,24 @@ pub fn list_orphans>(connection: &C) -> Result>( +pub async fn list_path>( connection: &C, path: &UPath, ) -> Result> { let resolved_path: Vec
= resolve_path(connection, path, false)?; - let last = resolved_path.last().unwrap(); - - let entry_addresses = query( - connection, - Query::SingleQuery(QueryPart::Matches(EntryQuery { - entity: QueryComponent::Exact(last.clone()), - attribute: QueryComponent::Exact(HIER_HAS_ATTR.to_string()), - value: QueryComponent::Any, - })), - )? - .extract_addresses(); + let entry_addresses = match resolved_path.last() { + Some(last) => + query( + connection, + Query::SingleQuery(QueryPart::Matches(EntryQuery { + entity: QueryComponent::Exact(last.clone()), + attribute: QueryComponent::Exact(HIER_HAS_ATTR.to_string()), + value: QueryComponent::Any, + })), + )? + .extract_addresses(), + None => list_orphans(connection)?, + }; Ok(bulk_retrieve_objects(connection, entry_addresses)? .into_iter() diff --git a/src/routes.rs b/src/routes.rs index c05db89..269aea6 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,6 +1,6 @@ use crate::addressing::{Address, Addressable}; use crate::database::entry::{Entry, InEntry}; -use crate::database::hierarchies::{list_node, UPath}; +use crate::database::hierarchies::{list_path, UPath}; use crate::database::lang::Query; use crate::database::{ get_latest_files, insert_entry, query, remove_object, retrieve_file, retrieve_object, DbPool, @@ -174,7 +174,7 @@ pub async fn list_hier( let connection = state.db_pool.get().map_err(ErrorInternalServerError)?; let upath: UPath = path.into_inner().parse().map_err(ErrorBadRequest)?; trace!("Listing path \"{}\"", upath); - let entries: Vec = list_node(&connection, &upath) + let entries: Vec = list_path(&connection, &upath) .await .map_err(ErrorNotFound)?; // todo: 500 if actual error occurs