handle root /hier/ query
This commit is contained in:
parent
c77bb8a425
commit
a33943bdb7
2 changed files with 16 additions and 14 deletions
|
@ -122,22 +122,24 @@ pub fn list_orphans<C: Connection<Backend = Sqlite>>(connection: &C) -> Result<V
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_node<C: Connection<Backend = Sqlite>>(
|
pub async fn list_path<C: Connection<Backend = Sqlite>>(
|
||||||
connection: &C,
|
connection: &C,
|
||||||
path: &UPath,
|
path: &UPath,
|
||||||
) -> Result<Vec<Entry>> {
|
) -> Result<Vec<Entry>> {
|
||||||
let resolved_path: Vec<Address> = resolve_path(connection, path, false)?;
|
let resolved_path: Vec<Address> = resolve_path(connection, path, false)?;
|
||||||
let last = resolved_path.last().unwrap();
|
let entry_addresses = match resolved_path.last() {
|
||||||
|
Some(last) =>
|
||||||
let entry_addresses = query(
|
query(
|
||||||
connection,
|
connection,
|
||||||
Query::SingleQuery(QueryPart::Matches(EntryQuery {
|
Query::SingleQuery(QueryPart::Matches(EntryQuery {
|
||||||
entity: QueryComponent::Exact(last.clone()),
|
entity: QueryComponent::Exact(last.clone()),
|
||||||
attribute: QueryComponent::Exact(HIER_HAS_ATTR.to_string()),
|
attribute: QueryComponent::Exact(HIER_HAS_ATTR.to_string()),
|
||||||
value: QueryComponent::Any,
|
value: QueryComponent::Any,
|
||||||
})),
|
})),
|
||||||
)?
|
)?
|
||||||
.extract_addresses();
|
.extract_addresses(),
|
||||||
|
None => list_orphans(connection)?,
|
||||||
|
};
|
||||||
|
|
||||||
Ok(bulk_retrieve_objects(connection, entry_addresses)?
|
Ok(bulk_retrieve_objects(connection, entry_addresses)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::addressing::{Address, Addressable};
|
use crate::addressing::{Address, Addressable};
|
||||||
use crate::database::entry::{Entry, InEntry};
|
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::lang::Query;
|
||||||
use crate::database::{
|
use crate::database::{
|
||||||
get_latest_files, insert_entry, query, remove_object, retrieve_file, retrieve_object, DbPool,
|
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 connection = state.db_pool.get().map_err(ErrorInternalServerError)?;
|
||||||
let upath: UPath = path.into_inner().parse().map_err(ErrorBadRequest)?;
|
let upath: UPath = path.into_inner().parse().map_err(ErrorBadRequest)?;
|
||||||
trace!("Listing path \"{}\"", upath);
|
trace!("Listing path \"{}\"", upath);
|
||||||
let entries: Vec<Entry> = list_node(&connection, &upath)
|
let entries: Vec<Entry> = list_path(&connection, &upath)
|
||||||
.await
|
.await
|
||||||
.map_err(ErrorNotFound)?; // todo: 500 if actual error occurs
|
.map_err(ErrorNotFound)?; // todo: 500 if actual error occurs
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue