separate endpoint for attr overwrites, implement AttributeUpdate

feat/vaults
Tomáš Mládek 2022-02-02 00:45:05 +01:00
parent 74c8a4f539
commit cb22756a47
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
4 changed files with 35 additions and 11 deletions

View File

@ -156,6 +156,7 @@ fn main() -> Result<()> {
.service(routes::get_query)
.service(routes::get_object)
.service(routes::put_object)
.service(routes::put_object_attribute)
.service(routes::delete_object)
.service(routes::get_all_attributes)
.service(routes::api_refresh)

View File

@ -1,5 +1,5 @@
use crate::addressing::{Address, Addressable};
use crate::database::entry::{Entry, InEntry};
use crate::database::entry::{Entry, EntryValue, InEntry};
use crate::database::hierarchies::{list_roots, resolve_path, UHierPath};
use crate::database::lang::Query;
use crate::database::UpEndDatabase;
@ -273,6 +273,36 @@ pub async fn put_object(
))
}
#[put("/api/obj/{address}/{attribute}")]
pub async fn put_object_attribute(
state: web::Data<State>,
web::Path((address, attribute)): web::Path<(Address, String)>,
value: web::Json<EntryValue>,
) -> Result<HttpResponse, Error> {
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
let new_address = connection
.transaction::<_, anyhow::Error, _>(|| {
let existing_attr_entries =
connection.query(format!("(matches \"{address}\" \"{attribute}\" ?)").parse()?)?;
for eae in existing_attr_entries {
let _ = connection.remove_object(eae.address()?)?;
}
let new_attr_entry = Entry {
entity: address,
attribute,
value: value.into_inner(),
};
connection.insert_entry(new_attr_entry)
})
.map_err(ErrorInternalServerError)?;
Ok(HttpResponse::Ok().json(new_address))
}
#[delete("/api/obj/{address_str}")]
pub async fn delete_object(
state: web::Data<State>,

View File

@ -123,16 +123,10 @@
await fetch(`/api/obj/${change.address}`, { method: "DELETE" });
break;
case "update":
// TODO
await fetch(`/api/obj/${change.address}`, { method: "DELETE" });
await fetch(`/api/obj`, {
await fetch(`/api/obj/${address}/${change.attribute}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
entity: address,
attribute: change.attribute,
value: change.value,
}),
body: JSON.stringify(change.value),
});
break;
default:

View File

@ -13,8 +13,7 @@ export interface AttributeCreate {
export interface AttributeUpdate {
type: "update";
address: string;
attribute: string; // TODO: remove
attribute: string;
value: IValue;
}