From cc11d5000910b5fd53e40bfd01056c0db60c35aa Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 30 Aug 2018 16:52:03 -0700 Subject: editgroup parameter for batch inserts --- rust/src/api_server.rs | 24 +++++++++++++++++++----- rust/src/api_wrappers.rs | 3 ++- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'rust/src') 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, conn: &DbConn, ) -> Result> { let mut ret: Vec = 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 = 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) diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs index 4f126385..da6139d2 100644 --- a/rust/src/api_wrappers.rs +++ b/rust/src/api_wrappers.rs @@ -84,10 +84,11 @@ macro_rules! wrap_entity_handlers { &self, entity_list: &Vec, autoaccept: Option, + editgroup: Option, _context: &Context, ) -> Box + Send> { let conn = self.db_pool.get().expect("db_pool error"); - let ret = match conn.transaction(|| self.$post_batch_handler(entity_list, autoaccept.unwrap_or(false), &conn)) { + let ret = match conn.transaction(|| self.$post_batch_handler(entity_list, autoaccept.unwrap_or(false), editgroup, &conn)) { Ok(edit) => $post_batch_resp::CreatedEntities(edit), Err(Error(ErrorKind::Diesel(e), _)) => -- cgit v1.2.3