allow inserting multiple entries (in transaction) in /api/obj
parent
038e4fd7d2
commit
ebf48c0e5f
|
@ -249,6 +249,7 @@ pub async fn get_object(
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum InEntry {
|
pub enum InEntry {
|
||||||
Entry(Entry),
|
Entry(Entry),
|
||||||
|
EntryList(Vec<Entry>),
|
||||||
Invariant(InvariantEntry),
|
Invariant(InvariantEntry),
|
||||||
Address { entity: InAddress },
|
Address { entity: InAddress },
|
||||||
}
|
}
|
||||||
|
@ -298,8 +299,19 @@ pub async fn put_object(
|
||||||
.insert_entry(entry.clone())
|
.insert_entry(entry.clone())
|
||||||
.map_err(ErrorInternalServerError)?,
|
.map_err(ErrorInternalServerError)?,
|
||||||
),
|
),
|
||||||
entry.entity,
|
Some(entry.entity),
|
||||||
)),
|
)),
|
||||||
|
InEntry::EntryList(entries) => {
|
||||||
|
connection
|
||||||
|
.transaction::<_, anyhow::Error, _>(|| {
|
||||||
|
for entry in entries {
|
||||||
|
connection.insert_entry(entry)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.map_err(ErrorInternalServerError)?;
|
||||||
|
Ok((None, None))
|
||||||
|
}
|
||||||
InEntry::Invariant(in_entry) => {
|
InEntry::Invariant(in_entry) => {
|
||||||
let invariant = Entry::try_from(&InvariantEntry {
|
let invariant = Entry::try_from(&InvariantEntry {
|
||||||
attribute: in_entry.attribute,
|
attribute: in_entry.attribute,
|
||||||
|
@ -313,7 +325,7 @@ pub async fn put_object(
|
||||||
.insert_entry(invariant.clone())
|
.insert_entry(invariant.clone())
|
||||||
.map_err(ErrorInternalServerError)?,
|
.map_err(ErrorInternalServerError)?,
|
||||||
),
|
),
|
||||||
invariant.entity,
|
Some(invariant.entity),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
InEntry::Address { entity: in_address } => {
|
InEntry::Address { entity: in_address } => {
|
||||||
|
@ -370,7 +382,7 @@ pub async fn put_object(
|
||||||
})
|
})
|
||||||
.map_err(ErrorInternalServerError)?;
|
.map_err(ErrorInternalServerError)?;
|
||||||
|
|
||||||
Ok((None, address))
|
Ok((None, Some(address)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,7 +433,7 @@ pub async fn put_object(
|
||||||
let _ = upend_insert_val!(&connection, address, "LBL", filename);
|
let _ = upend_insert_val!(&connection, address, "LBL", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((None, address))
|
Ok((None, Some(address)))
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("Multipart contains no fields."))
|
Err(anyhow!("Multipart contains no fields."))
|
||||||
}
|
}
|
||||||
|
@ -429,7 +441,7 @@ pub async fn put_object(
|
||||||
}
|
}
|
||||||
.map_err(ErrorInternalServerError)?;
|
.map_err(ErrorInternalServerError)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json([entry_address, Some(entity_address)]))
|
Ok(HttpResponse::Ok().json([entry_address, entity_address]))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/api/obj/{address}/{attribute}")]
|
#[put("/api/obj/{address}/{attribute}")]
|
||||||
|
|
Loading…
Reference in New Issue