summaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-09-07 21:51:31 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-09-07 21:51:31 -0700
commitd2070ba3718978a9615ae2aa3d81825803522a91 (patch)
treef62fe241fdbbd32180e582bd5533582558c6b979 /rust/src
parent20c5cf5a8b9acf98db7487ab49de8dcbc1ddb2f9 (diff)
parent8cccbcdef11e7ddc761ec494cb894a8d49a0d510 (diff)
downloadfatcat-d2070ba3718978a9615ae2aa3d81825803522a91.tar.gz
fatcat-d2070ba3718978a9615ae2aa3d81825803522a91.zip
Merge branch 'autoaccept' into http-verbs
Started resolving conflicts in: TODO notes/cloud_instances.txt rust/fatcat-api/README.md rust/src/api_server.rs
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_server.rs31
-rw-r--r--rust/src/api_wrappers.rs6
2 files changed, 34 insertions, 3 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 57aeebea..602fbfb7 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -25,11 +25,40 @@ macro_rules! entity_batch_handler {
pub fn $post_batch_handler(
&self,
entity_list: &[models::$model],
+ autoaccept: bool,
+ editgroup: Option<String>,
conn: &DbConn,
) -> Result<Vec<EntityEdit>> {
- let edit_context = make_edit_context(conn, None)?;
+ // editgroup override logic based on parameters
+ let eg_id: Option<Uuid> = match (editgroup, autoaccept) {
+ (Some(eg_string), _) => Some(fcid2uuid(&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();
+ // 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)?);
+ }
+ let mut edit_context = make_edit_context(conn, eg_id)?;
+ edit_context.autoaccept = autoaccept;
let model_list: Vec<&models::$model> = entity_list.iter().map(|e| e).collect();
let edits = $model::db_create_batch(conn, &edit_context, model_list.as_slice())?;
+ if autoaccept {
+ // if autoaccept, eg_id is always Some
+ let _clr: ChangelogRow = diesel::insert_into(changelog::table)
+ .values((changelog::editgroup_id.eq(eg_id.unwrap()),))
+ .get_result(conn)?;
+ }
edits.into_iter().map(|e| e.into_model()).collect()
}
}
diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs
index de1fc9da..6272814e 100644
--- a/rust/src/api_wrappers.rs
+++ b/rust/src/api_wrappers.rs
@@ -61,7 +61,7 @@ macro_rules! wrap_entity_handlers {
_context: &Context,
) -> Box<Future<Item = $post_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let ret = match conn.transaction(|| self.$post_handler(entity, &conn)) {
+ let ret = match conn.transaction(|| self.$post_handler(entity, false, &conn)) {
Ok(edit) =>
$post_resp::CreatedEntity(edit),
Err(Error(ErrorKind::Diesel(e), _)) =>
@@ -84,10 +84,12 @@ macro_rules! wrap_entity_handlers {
fn $post_batch_fn(
&self,
entity_list: &Vec<models::$model>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
_context: &Context,
) -> Box<Future<Item = $post_batch_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let ret = match conn.transaction(|| self.$post_batch_handler(entity_list, &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), _)) =>