add endpoint to list all attributes
parent
d9259785a1
commit
091a02d530
|
@ -75,7 +75,7 @@ pub struct OpenResult {
|
|||
pub struct UpEndDatabase {
|
||||
pool: DbPool,
|
||||
pub vault_path: Arc<PathBuf>,
|
||||
pub db_path: Arc<PathBuf>
|
||||
pub db_path: Arc<PathBuf>,
|
||||
}
|
||||
|
||||
pub const UPEND_SUBDIR: &str = ".upend";
|
||||
|
@ -116,7 +116,7 @@ impl UpEndDatabase {
|
|||
let db = UpEndDatabase {
|
||||
pool,
|
||||
vault_path: Arc::new(PathBuf::from(dirpath.as_ref())),
|
||||
db_path: Arc::new(upend_path)
|
||||
db_path: Arc::new(upend_path),
|
||||
};
|
||||
let connection = db.connection().unwrap();
|
||||
|
||||
|
@ -336,6 +336,19 @@ impl UpEndConnection {
|
|||
|
||||
Ok(Address::Hash(entry.hash()?))
|
||||
}
|
||||
|
||||
// #[deprecated]
|
||||
pub fn get_all_attributes(&self) -> Result<Vec<String>> {
|
||||
use crate::database::inner::schema::data::dsl::*;
|
||||
|
||||
let result = data
|
||||
.select(attribute)
|
||||
.distinct()
|
||||
.order_by(attribute)
|
||||
.load::<String>(&self.conn)?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -155,6 +155,7 @@ fn main() -> Result<()> {
|
|||
.service(routes::get_object)
|
||||
.service(routes::put_object)
|
||||
.service(routes::delete_object)
|
||||
.service(routes::get_all_attributes)
|
||||
.service(routes::api_refresh)
|
||||
.service(routes::list_hier)
|
||||
.service(routes::list_hier_roots)
|
||||
|
|
|
@ -217,6 +217,13 @@ pub async fn delete_object(
|
|||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
#[get("/api/all/attributes")]
|
||||
pub async fn get_all_attributes(state: web::Data<State>) -> Result<HttpResponse, Error> {
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
let result = connection.get_all_attributes().map_err(ErrorInternalServerError)?;
|
||||
Ok(HttpResponse::Ok().json(result))
|
||||
}
|
||||
|
||||
#[get("/api/hier/{path:.*}")]
|
||||
pub async fn list_hier(
|
||||
state: web::Data<State>,
|
||||
|
|
Loading…
Reference in New Issue