summaryrefslogtreecommitdiffstats
path: root/rust/src/api_server.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-08-30 16:52:03 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-08-30 16:52:03 -0700
commitcc11d5000910b5fd53e40bfd01056c0db60c35aa (patch)
treec1e520176b3ac88607e4b4cacc994ee0344aaaa8 /rust/src/api_server.rs
parent8528f06157b0e60842c860f81e3f2a69aa07aae9 (diff)
downloadfatcat-cc11d5000910b5fd53e40bfd01056c0db60c35aa.tar.gz
fatcat-cc11d5000910b5fd53e40bfd01056c0db60c35aa.zip
editgroup parameter for batch inserts
Diffstat (limited to 'rust/src/api_server.rs')
-rw-r--r--rust/src/api_server.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 0cb07e81..e8e7d062 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -26,21 +26,35 @@ macro_rules! entity_batch_handler {
&self,
entity_list: &[models::$model],
autoaccept: bool,
+ editgroup: Option<String>,
conn: &DbConn,
) -> Result<Vec<EntityEdit>> {
let mut ret: Vec<EntityEdit> = vec![];
let editor_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?; // TODO: auth
- let eg_row: EditgroupRow = diesel::insert_into(editgroup::table)
- .values((editgroup::editor_id.eq(editor_id),))
- .get_result(conn)?;
+ // editgroup override logic based on parameters
+ let eg_id: Option<Uuid> = match (editgroup, autoaccept) {
+ (Some(eg_string), _) => Some(Uuid::parse_str(&eg_string)?),
+ (None, true) => {
+ let eg_row: EditgroupRow = diesel::insert_into(editgroup::table)
+ .values((editgroup::editor_id.eq(editor_id),))
+ .get_result(conn)?;
+ Some(eg_row.id)
+ },
+ (None, false) => None
+ };
for entity in entity_list {
let mut e = entity.clone();
- e.editgroup_id = Some(uuid2fcid(&eg_row.id));
+ // override individual editgroup IDs (if set earlier)
+ if let Some(inner_id) = eg_id {
+ e.editgroup_id = Some(uuid2fcid(&inner_id));
+ }
+ // actual wrapped function call here
ret.push(self.$post_handler(e, autoaccept, conn)?);
}
if autoaccept {
+ // if autoaccept, eg_id is always Some
let _clr: ChangelogRow = diesel::insert_into(changelog::table)
- .values((changelog::editgroup_id.eq(eg_row.id),))
+ .values((changelog::editgroup_id.eq(eg_id.unwrap()),))
.get_result(conn)?;
}
Ok(ret)