From bfcf13c205e7c0fd38a0fc68194f8ab9550ca0a7 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 22 Sep 2018 17:26:57 -0700 Subject: rustfmt, and implement schema tweaks --- rust/src/api_entity_crud.rs | 108 ++++++++++++++++---------------------------- rust/src/api_server.rs | 9 ++-- rust/src/api_wrappers.rs | 36 ++++++++------- rust/src/bin/fatcatd.rs | 3 +- rust/src/database_models.rs | 16 +++---- rust/src/database_schema.rs | 8 ++-- 6 files changed, 75 insertions(+), 105 deletions(-) (limited to 'rust') diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs index 461e1c7f..258355f8 100644 --- a/rust/src/api_entity_crud.rs +++ b/rust/src/api_entity_crud.rs @@ -147,10 +147,8 @@ macro_rules! generic_db_create_batch { rev_id: Some(rev_id.clone()), is_live: edit_context.autoaccept, redirect_id: None, - }) - .collect::>(), - ) - .returning($ident_table::id) + }).collect::>(), + ).returning($ident_table::id) .get_results(conn)?; let edits: Vec = insert_into($edit_table::table) .values( @@ -164,10 +162,8 @@ macro_rules! generic_db_create_batch { redirect_id: None, prev_rev: None, extra_json: edit_context.extra_json.clone(), - }) - .collect::>(), - ) - .get_results(conn)?; + }).collect::>(), + ).get_results(conn)?; Ok(edits) } }; @@ -226,8 +222,7 @@ macro_rules! generic_db_delete { $edit_table::redirect_id.eq(None::), $edit_table::prev_rev.eq(current.rev_id), $edit_table::extra_json.eq(&edit_context.extra_json), - )) - .get_result(conn)?; + )).get_result(conn)?; Ok(edit) } @@ -259,8 +254,7 @@ macro_rules! generic_db_get_history { editgroup: eg_row.into_model_partial(), changelog_entry: cl_row.into_model(), }) - }) - .collect(); + }).collect(); history } }; @@ -320,7 +314,7 @@ macro_rules! generic_db_accept_edits_batch { AND {entity}_edit.editgroup_id = $1", entity = $entity_name_str )).bind::(editgroup_id.to_uuid()) - .execute(conn)?; + .execute(conn)?; Ok(count as u64) } }; @@ -444,10 +438,8 @@ impl EntityCrud for ContainerEntity { abbrev: model.abbrev.clone(), coden: model.coden.clone(), extra_json: model.extra.clone(), - }) - .collect::>(), - ) - .returning(container_rev::id) + }).collect::>(), + ).returning(container_rev::id) .get_results(conn)?; Ok(rev_ids) } @@ -521,10 +513,8 @@ impl EntityCrud for CreatorEntity { orcid: model.orcid.clone(), wikidata_qid: model.wikidata_qid.clone(), extra_json: model.extra.clone(), - }) - .collect::>(), - ) - .returning(creator_rev::id) + }).collect::>(), + ).returning(creator_rev::id) .get_results(conn)?; Ok(rev_ids) } @@ -576,8 +566,7 @@ impl EntityCrud for FileEntity { .map(|r: FileRevUrlRow| FileEntityUrls { rel: r.rel, url: r.url, - }) - .collect(); + }).collect(); Ok(FileEntity { sha1: rev_row.sha1, @@ -608,10 +597,8 @@ impl EntityCrud for FileEntity { md5: model.md5.clone(), mimetype: model.mimetype.clone(), extra_json: model.extra.clone(), - }) - .collect::>(), - ) - .returning(file_rev::id) + }).collect::>(), + ).returning(file_rev::id) .get_results(conn)?; let mut file_release_rows: Vec = vec![]; @@ -628,8 +615,7 @@ impl EntityCrud for FileEntity { file_rev: *rev_id, target_release_ident_id: FatCatId::from_str(r)?.to_uuid(), }) - }) - .collect(); + }).collect(); file_release_rows.extend(these_release_rows?); } }; @@ -643,8 +629,7 @@ impl EntityCrud for FileEntity { file_rev: *rev_id, rel: u.rel.clone(), url: u.url.clone(), - }) - .collect(); + }).collect(); file_url_rows.extend(these_url_rows); } }; @@ -746,8 +731,7 @@ impl EntityCrud for ReleaseEntity { Some(FatCatId::from_uuid(&new_work_ids.pop().unwrap()).to_string()) } model - }) - .collect(); + }).collect(); let model_refs: Vec<&Self> = models_with_work_ids.iter().map(|s| s).collect(); let models = model_refs.as_slice(); @@ -761,10 +745,8 @@ impl EntityCrud for ReleaseEntity { rev_id: Some(*rev_id), is_live: edit_context.autoaccept, redirect_id: None, - }) - .collect::>(), - ) - .returning(release_ident::id) + }).collect::>(), + ).returning(release_ident::id) .get_results(conn)?; let edits: Vec = insert_into(release_edit::table) .values( @@ -778,10 +760,8 @@ impl EntityCrud for ReleaseEntity { redirect_id: None, prev_rev: None, extra_json: edit_context.extra_json.clone(), - }) - .collect::>(), - ) - .get_results(conn)?; + }).collect::>(), + ).get_results(conn)?; Ok(edits) } @@ -805,29 +785,27 @@ impl EntityCrud for ReleaseEntity { .get_results(conn)? .into_iter() .map(|r: ReleaseRefRow| ReleaseRef { - index: r.index_val, + index: r.index_val.map(|v| v as i64), key: r.key, extra: r.extra_json, - container_title: r.container_title, - year: r.year, + container_name: r.container_name, + year: r.year.map(|v| v as i64), title: r.title, locator: r.locator, target_release_id: r .target_release_ident_id .map(|v| FatCatId::from_uuid(&v).to_string()), - }) - .collect(); + }).collect(); let contribs: Vec = release_contrib::table .filter(release_contrib::release_rev.eq(rev_row.id)) .order(( release_contrib::role.asc(), release_contrib::index_val.asc(), - )) - .get_results(conn)? + )).get_results(conn)? .into_iter() .map(|c: ReleaseContribRow| ReleaseContrib { - index: c.index_val, + index: c.index_val.map(|v| v as i64), raw_name: c.raw_name, role: c.role, extra: c.extra_json, @@ -835,8 +813,7 @@ impl EntityCrud for ReleaseEntity { .creator_ident_id .map(|v| FatCatId::from_uuid(&v).to_string()), creator: None, - }) - .collect(); + }).collect(); let abstracts: Vec = release_rev_abstract::table .inner_join(abstracts::table) @@ -850,8 +827,7 @@ impl EntityCrud for ReleaseEntity { lang: r.0.lang, content: Some(r.1.content), }, - ) - .collect(); + ).collect(); Ok(ReleaseEntity { title: rev_row.title, @@ -961,16 +937,15 @@ impl EntityCrud for ReleaseEntity { None => None, Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()), }, - index_val: r.index, + index_val: r.index.map(|v| v as i32), key: r.key.clone(), - container_title: r.container_title.clone(), - year: r.year, + container_name: r.container_name.clone(), + year: r.year.map(|v| v as i32), title: r.title.clone(), locator: r.locator.clone(), extra_json: r.extra.clone(), }) - }) - .collect::>>()?; + }).collect::>>()?; release_ref_rows.extend(these_ref_rows); } }; @@ -988,12 +963,11 @@ impl EntityCrud for ReleaseEntity { Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()), }, raw_name: c.raw_name.clone(), - index_val: c.index, + index_val: c.index.map(|v| v as i32), role: c.role.clone(), extra_json: c.extra.clone(), }) - }) - .collect::>>()?; + }).collect::>>()?; release_contrib_rows.extend(these_contrib_rows); } }; @@ -1007,8 +981,7 @@ impl EntityCrud for ReleaseEntity { .map(|c| AbstractsRow { sha1: Sha1::from(c.content.clone().unwrap()).hexdigest(), content: c.content.clone().unwrap(), - }) - .collect(); + }).collect(); abstract_rows.extend(new_abstracts); let new_release_abstract_rows: Vec = abstract_list .into_iter() @@ -1025,8 +998,7 @@ impl EntityCrud for ReleaseEntity { lang: c.lang.clone(), mimetype: c.mimetype.clone(), }) - }) - .collect::>>()?; + }).collect::>>()?; release_abstract_rows.extend(new_release_abstract_rows); } } @@ -1108,10 +1080,8 @@ impl EntityCrud for WorkEntity { .iter() .map(|model| WorkRevNewRow { extra_json: model.extra.clone(), - }) - .collect::>(), - ) - .returning(work_rev::id) + }).collect::>(), + ).returning(work_rev::id) .get_results(conn)?; Ok(rev_ids) } diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index d9a86a3f..9562a0f2 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -175,8 +175,7 @@ impl Server { editgroup::editor_id.eq(FatCatId::from_str(&entity.editor_id)?.to_uuid()), editgroup::description.eq(entity.description), editgroup::extra_json.eq(entity.extra), - )) - .get_result(conn)?; + )).get_result(conn)?; Ok(Editgroup { id: Some(uuid2fcid(&row.id)), @@ -272,8 +271,7 @@ impl Server { editgroup: Some(eg_row.into_model_partial()), editgroup_id: uuid2fcid(&cl_row.editgroup_id), timestamp: chrono::DateTime::from_utc(cl_row.timestamp, chrono::Utc), - }) - .collect(); + }).collect(); Ok(entries) } @@ -297,8 +295,7 @@ impl Server { editgroup: Some(eg_row.into_model_partial()), editgroup_id: uuid2fcid(&cl_row.editgroup_id), timestamp: chrono::DateTime::from_utc(cl_row.timestamp, chrono::Utc), - }) - .collect(); + }).collect(); Ok(entries) } diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs index 85739ea6..0daff73b 100644 --- a/rust/src/api_wrappers.rs +++ b/rust/src/api_wrappers.rs @@ -465,15 +465,19 @@ impl Api for Server { let id = FatCatId::from_str(&id)?; self.get_editgroup_handler(id, &conn) }) { - Ok(entity) => - GetEditgroupResponse::Found(entity), - Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => - GetEditgroupResponse::NotFound( - ErrorResponse { message: format!("No such editgroup: {}", id) }), + Ok(entity) => GetEditgroupResponse::Found(entity), + Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => { + GetEditgroupResponse::NotFound(ErrorResponse { + message: format!("No such editgroup: {}", id), + }) + } Err(e) => - // TODO: dig in to error type here - GetEditgroupResponse::GenericError( - ErrorResponse { message: e.to_string() }), + // TODO: dig in to error type here + { + GetEditgroupResponse::GenericError(ErrorResponse { + message: e.to_string(), + }) + } }; Box::new(futures::done(Ok(ret))) } @@ -484,15 +488,15 @@ impl Api for Server { _context: &Context, ) -> Box + Send> { let conn = self.db_pool.get().expect("db_pool error"); - let ret = match conn.transaction(|| - self.create_editgroup_handler(entity, &conn) - ) { - Ok(eg) => - CreateEditgroupResponse::SuccessfullyCreated(eg), + let ret = match conn.transaction(|| self.create_editgroup_handler(entity, &conn)) { + Ok(eg) => CreateEditgroupResponse::SuccessfullyCreated(eg), Err(e) => - // TODO: dig in to error type here - CreateEditgroupResponse::GenericError( - ErrorResponse { message: e.to_string() }), + // TODO: dig in to error type here + { + CreateEditgroupResponse::GenericError(ErrorResponse { + message: e.to_string(), + }) + } }; Box::new(futures::done(Ok(ret))) } diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs index 57b6a3da..b40ac3c4 100644 --- a/rust/src/bin/fatcatd.rs +++ b/rust/src/bin/fatcatd.rs @@ -32,8 +32,7 @@ fn main() { Arg::with_name("https") .long("https") .help("Whether to use HTTPS or not"), - ) - .get_matches(); + ).get_matches(); let decorator = slog_term::TermDecorator::new().build(); let drain = slog_term::CompactFormat::new(decorator).build().fuse(); diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 3d41704c..e8c7ad4e 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -339,7 +339,7 @@ pub struct ReleaseContribRow { pub creator_ident_id: Option, pub raw_name: Option, pub role: Option, - pub index_val: Option, + pub index_val: Option, pub extra_json: Option, } @@ -350,7 +350,7 @@ pub struct ReleaseContribNewRow { pub creator_ident_id: Option, pub raw_name: Option, pub role: Option, - pub index_val: Option, + pub index_val: Option, pub extra_json: Option, } @@ -360,11 +360,11 @@ pub struct ReleaseRefRow { pub id: i64, pub release_rev: Uuid, pub target_release_ident_id: Option, - pub index_val: Option, + pub index_val: Option, pub key: Option, pub extra_json: Option, - pub container_title: Option, - pub year: Option, + pub container_name: Option, + pub year: Option, pub title: Option, pub locator: Option, } @@ -374,11 +374,11 @@ pub struct ReleaseRefRow { pub struct ReleaseRefNewRow { pub release_rev: Uuid, pub target_release_ident_id: Option, - pub index_val: Option, + pub index_val: Option, pub key: Option, pub extra_json: Option, - pub container_title: Option, - pub year: Option, + pub container_name: Option, + pub year: Option, pub title: Option, pub locator: Option, } diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index df14c4aa..829a21b8 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -159,7 +159,7 @@ table! { creator_ident_id -> Nullable, raw_name -> Nullable, role -> Nullable, - index_val -> Nullable, + index_val -> Nullable, extra_json -> Nullable, } } @@ -191,11 +191,11 @@ table! { id -> Int8, release_rev -> Uuid, target_release_ident_id -> Nullable, - index_val -> Nullable, + index_val -> Nullable, key -> Nullable, extra_json -> Nullable, - container_title -> Nullable, - year -> Nullable, + container_name -> Nullable, + year -> Nullable, title -> Nullable, locator -> Nullable, } -- cgit v1.2.3