summaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_entity_crud.rs34
-rw-r--r--rust/src/api_helpers.rs22
-rw-r--r--rust/src/api_server.rs6
-rw-r--r--rust/src/database_models.rs2
-rw-r--r--rust/src/database_schema.rs1
5 files changed, 46 insertions, 19 deletions
diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs
index 792e6f9a..ee2d4ef3 100644
--- a/rust/src/api_entity_crud.rs
+++ b/rust/src/api_entity_crud.rs
@@ -166,7 +166,9 @@ macro_rules! generic_db_create_batch {
) -> Result<Vec<Self::EditRow>> {
if models.iter().any(|m| m.redirect.is_some()) {
return Err(ErrorKind::OtherBadRequest(
- "can't create an entity that redirects from the start".to_string()).into());
+ "can't create an entity that redirects from the start".to_string(),
+ )
+ .into());
}
let rev_ids: Vec<Uuid> = Self::db_insert_revs(conn, models)?;
let ident_ids: Vec<Uuid> = insert_into($ident_table::table)
@@ -658,7 +660,9 @@ impl EntityCrud for ContainerEntity {
if models.iter().any(|m| m.name.is_none()) {
return Err(ErrorKind::OtherBadRequest(
- "name is required for all Container entities".to_string()).into());
+ "name is required for all Container entities".to_string(),
+ )
+ .into());
}
let rev_ids: Vec<Uuid> = insert_into(container_rev::table)
@@ -767,14 +771,16 @@ impl EntityCrud for CreatorEntity {
if models.iter().any(|m| m.display_name.is_none()) {
return Err(ErrorKind::OtherBadRequest(
- "display_name is required for all Creator entities".to_string()).into());
+ "display_name is required for all Creator entities".to_string(),
+ )
+ .into());
}
let rev_ids: Vec<Uuid> = insert_into(creator_rev::table)
.values(
models
.iter()
- .map(|model|CreatorRevNewRow {
+ .map(|model| CreatorRevNewRow {
display_name: model.display_name.clone().unwrap(), // unwrapped checked above
given_name: model.given_name.clone(),
surname: model.surname.clone(),
@@ -996,6 +1002,7 @@ impl EntityCrud for ReleaseEntity {
release_type: None,
release_status: None,
release_date: None,
+ release_year: None,
doi: None,
pmid: None,
pmcid: None,
@@ -1029,7 +1036,7 @@ impl EntityCrud for ReleaseEntity {
fn db_expand(&mut self, conn: &DbConn, expand: ExpandFlags) -> Result<()> {
// Don't expand deleted entities
if self.state == Some("deleted".to_string()) {
- return Ok(())
+ return Ok(());
}
// TODO: should clarify behavior here. Would hit this path, eg, expanding files on a
// release revision (not ident). Should we fail (Bad Request), or silently just not include
@@ -1062,7 +1069,8 @@ impl EntityCrud for ReleaseEntity {
contrib.creator = Some(CreatorEntity::db_get(
conn,
FatCatId::from_str(creator_id)?,
- HideFlags::none())?);
+ HideFlags::none(),
+ )?);
}
}
}
@@ -1073,7 +1081,9 @@ impl EntityCrud for ReleaseEntity {
fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result<Self::EditRow> {
if self.redirect.is_some() {
return Err(ErrorKind::OtherBadRequest(
- "can't create an entity that redirects from the start".to_string()).into());
+ "can't create an entity that redirects from the start".to_string(),
+ )
+ .into());
}
let mut edits = Self::db_create_batch(conn, edit_context, &[self])?;
// probably a more elegant way to destroy the vec and take first element
@@ -1089,7 +1099,9 @@ impl EntityCrud for ReleaseEntity {
// of the release entities passed (at least in the common case)
if models.iter().any(|m| m.redirect.is_some()) {
return Err(ErrorKind::OtherBadRequest(
- "can't create an entity that redirects from the start".to_string()).into());
+ "can't create an entity that redirects from the start".to_string(),
+ )
+ .into());
}
// Generate the set of new work entities to insert (usually one for each release, but some
@@ -1252,6 +1264,7 @@ impl EntityCrud for ReleaseEntity {
release_type: rev_row.release_type,
release_status: rev_row.release_status,
release_date: rev_row.release_date,
+ release_year: rev_row.release_year,
doi: rev_row.doi,
pmid: rev_row.pmid,
pmcid: rev_row.pmcid,
@@ -1310,7 +1323,9 @@ impl EntityCrud for ReleaseEntity {
if models.iter().any(|m| m.title.is_none()) {
return Err(ErrorKind::OtherBadRequest(
- "title is required for all Release entities".to_string()).into());
+ "title is required for all Release entities".to_string(),
+ )
+ .into());
}
let rev_ids: Vec<Uuid> = insert_into(release_rev::table)
@@ -1323,6 +1338,7 @@ impl EntityCrud for ReleaseEntity {
release_type: model.release_type.clone(),
release_status: model.release_status.clone(),
release_date: model.release_date,
+ release_year: model.release_year,
doi: model.doi.clone(),
pmid: model.pmid.clone(),
pmcid: model.pmcid.clone(),
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs
index 32750836..b837dfc2 100644
--- a/rust/src/api_helpers.rs
+++ b/rust/src/api_helpers.rs
@@ -22,7 +22,6 @@ pub struct EditContext {
}
impl EditContext {
-
/// This function should always be run within a transaction
pub fn check(&self, conn: &DbConn) -> Result<()> {
let count: i64 = changelog::table
@@ -36,7 +35,6 @@ impl EditContext {
}
}
-
#[derive(Clone, Copy, PartialEq)]
pub struct ExpandFlags {
pub files: bool,
@@ -456,11 +454,21 @@ pub fn check_sha256(raw: &str) -> Result<()> {
#[test]
fn test_check_sha256() {
- assert!(check_sha256("cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452").is_ok());
- assert!(check_sha256("gb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452").is_err());
- assert!(check_sha256("UB1C378F464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452").is_err());
- assert!(check_sha256("cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e45").is_err());
- assert!(check_sha256("cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e4522").is_err());
+ assert!(
+ check_sha256("cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452").is_ok()
+ );
+ assert!(
+ check_sha256("gb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452").is_err()
+ );
+ assert!(
+ check_sha256("UB1C378F464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e452").is_err()
+ );
+ assert!(
+ check_sha256("cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e45").is_err()
+ );
+ assert!(
+ check_sha256("cb1c378f464d5935ddaa8de28446d82638396c61f042295d7fb85e3cccc9e4522").is_err()
+ );
}
pub fn check_release_type(raw: &str) -> Result<()> {
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index adc6ab11..d06de9c1 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -186,7 +186,7 @@ impl Server {
.filter(file_ident::is_live.eq(true))
.filter(file_ident::redirect_id.is_null())
.first(conn)?
- },
+ }
(None, Some(sha1), None) => {
check_sha1(sha1)?;
file_ident::table
@@ -195,7 +195,7 @@ impl Server {
.filter(file_ident::is_live.eq(true))
.filter(file_ident::redirect_id.is_null())
.first(conn)?
- },
+ }
(None, None, Some(sha256)) => {
check_sha256(sha256)?;
file_ident::table
@@ -204,7 +204,7 @@ impl Server {
.filter(file_ident::is_live.eq(true))
.filter(file_ident::redirect_id.is_null())
.first(conn)?
- },
+ }
_ => {
return Err(ErrorKind::MissingOrMultipleExternalId("in lookup".to_string()).into());
}
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index d5daf9a4..617b150b 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -247,6 +247,7 @@ pub struct ReleaseRevRow {
pub release_type: Option<String>,
pub release_status: Option<String>,
pub release_date: Option<chrono::NaiveDate>,
+ pub release_year: Option<i64>,
pub doi: Option<String>,
pub pmid: Option<String>,
pub pmcid: Option<String>,
@@ -270,6 +271,7 @@ pub struct ReleaseRevNewRow {
pub release_type: Option<String>,
pub release_status: Option<String>,
pub release_date: Option<chrono::NaiveDate>,
+ pub release_year: Option<i64>,
pub doi: Option<String>,
pub pmid: Option<String>,
pub pmcid: Option<String>,
diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs
index 829a21b8..6c1fb929 100644
--- a/rust/src/database_schema.rs
+++ b/rust/src/database_schema.rs
@@ -211,6 +211,7 @@ table! {
release_type -> Nullable<Text>,
release_status -> Nullable<Text>,
release_date -> Nullable<Date>,
+ release_year -> Nullable<Int8>,
doi -> Nullable<Text>,
pmid -> Nullable<Text>,
pmcid -> Nullable<Text>,