fix missing hier_label_attr, add trace to list_hier

feat/vaults
Tomáš Mládek 2021-08-18 11:06:38 +02:00
parent fbee24978b
commit 2944ce3d81
3 changed files with 8 additions and 4 deletions

View File

@ -11,6 +11,7 @@ pub const IS_OF_TYPE_ATTR: &str = "IS";
pub const HIER_TYPE: &str = "HIER";
pub const HIER_HAS_ATTR: &str = "HAS";
pub const HIER_LABEL_ATTR: &str = "LBL";
lazy_static! {
pub static ref TYPE_INVARIANT: InvariantEntry = InvariantEntry {

View File

@ -9,7 +9,8 @@ use uuid::Uuid;
use crate::addressing::Address;
use crate::database::constants::{
HIER_ADDR, HIER_HAS_ATTR, HIER_INVARIANT, IS_OF_TYPE_ATTR, TYPE_ADDR, TYPE_HAS_ATTR,
HIER_ADDR, HIER_HAS_ATTR, HIER_INVARIANT, HIER_LABEL_ATTR, IS_OF_TYPE_ATTR, TYPE_ADDR,
TYPE_HAS_ATTR, TYPE_ID_ATTR,
};
use crate::database::entry::{Entry, EntryValue};
use crate::database::lang::{EntryQuery, Query, QueryComponent, QueryPart};
@ -162,7 +163,7 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
connection,
Query::SingleQuery(QueryPart::Matches(EntryQuery {
entity: QueryComponent::Any,
attribute: QueryComponent::Exact(String::from(HIER_HAS_ATTR)),
attribute: QueryComponent::Exact(String::from(HIER_LABEL_ATTR)),
value: QueryComponent::Exact(EntryValue::Value(Value::String(
directory.as_ref().clone(),
))),
@ -211,7 +212,7 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
let directory_entry = Entry {
entity: new_directory_address.clone(),
attribute: String::from(HIER_HAS_ATTR),
attribute: String::from(HIER_LABEL_ATTR),
value: EntryValue::Value(Value::String(directory.as_ref().clone())),
};
insert_entry(connection, directory_entry)?;
@ -262,6 +263,7 @@ pub fn resolve_path<C: Connection<Backend = Sqlite>>(
pub fn initialize_hier(pool: &DbPool) -> Result<()> {
insert_entry(&pool.get()?, Entry::try_from(&*HIER_INVARIANT)?)?;
upend_insert_addr!(&pool.get()?, HIER_ADDR, IS_OF_TYPE_ATTR, TYPE_ADDR);
upend_insert_val!(&pool.get()?, HIER_ADDR, TYPE_ID_ATTR, HIER_LABEL_ATTR);
upend_insert_val!(&pool.get()?, HIER_ADDR, TYPE_HAS_ATTR, HIER_HAS_ATTR);
Ok(())
}

View File

@ -12,7 +12,7 @@ use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound}
use actix_web::{delete, error, get, post, put, web, Error, HttpResponse};
use anyhow::Result;
use futures_util::StreamExt;
use log::debug;
use log::{debug, trace};
use serde::Deserialize;
use serde_json::json;
use std::collections::HashMap;
@ -173,6 +173,7 @@ pub async fn list_hier(
) -> Result<HttpResponse, Error> {
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<Entry> = list_node(&connection, &upath)
.await
.map_err(ErrorNotFound)?; // todo: 500 if actual error occurs