aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/src/api_entity_crud.rs108
-rw-r--r--rust/src/api_server.rs9
-rw-r--r--rust/src/api_wrappers.rs36
-rw-r--r--rust/src/bin/fatcatd.rs3
-rw-r--r--rust/src/database_models.rs16
-rw-r--r--rust/src/database_schema.rs8
6 files changed, 75 insertions, 105 deletions
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::<Vec<Self::IdentNewRow>>(),
- )
- .returning($ident_table::id)
+ }).collect::<Vec<Self::IdentNewRow>>(),
+ ).returning($ident_table::id)
.get_results(conn)?;
let edits: Vec<Self::EditRow> = 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::<Vec<Self::EditNewRow>>(),
- )
- .get_results(conn)?;
+ }).collect::<Vec<Self::EditNewRow>>(),
+ ).get_results(conn)?;
Ok(edits)
}
};
@@ -226,8 +222,7 @@ macro_rules! generic_db_delete {
$edit_table::redirect_id.eq(None::<Uuid>),
$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::<diesel::sql_types::Uuid, _>(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::<Vec<ContainerRevNewRow>>(),
- )
- .returning(container_rev::id)
+ }).collect::<Vec<ContainerRevNewRow>>(),
+ ).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::<Vec<CreatorRevNewRow>>(),
- )
- .returning(creator_rev::id)
+ }).collect::<Vec<CreatorRevNewRow>>(),
+ ).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::<Vec<FileRevNewRow>>(),
- )
- .returning(file_rev::id)
+ }).collect::<Vec<FileRevNewRow>>(),
+ ).returning(file_rev::id)
.get_results(conn)?;
let mut file_release_rows: Vec<FileReleaseRow> = 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::<Vec<Self::IdentNewRow>>(),
- )
- .returning(release_ident::id)
+ }).collect::<Vec<Self::IdentNewRow>>(),
+ ).returning(release_ident::id)
.get_results(conn)?;
let edits: Vec<Self::EditRow> = 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::<Vec<Self::EditNewRow>>(),
- )
- .get_results(conn)?;
+ }).collect::<Vec<Self::EditNewRow>>(),
+ ).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<ReleaseContrib> = 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<ReleaseEntityAbstracts> = 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::<Result<Vec<ReleaseRefNewRow>>>()?;
+ }).collect::<Result<Vec<ReleaseRefNewRow>>>()?;
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::<Result<Vec<ReleaseContribNewRow>>>()?;
+ }).collect::<Result<Vec<ReleaseContribNewRow>>>()?;
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<ReleaseRevAbstractNewRow> = abstract_list
.into_iter()
@@ -1025,8 +998,7 @@ impl EntityCrud for ReleaseEntity {
lang: c.lang.clone(),
mimetype: c.mimetype.clone(),
})
- })
- .collect::<Result<Vec<ReleaseRevAbstractNewRow>>>()?;
+ }).collect::<Result<Vec<ReleaseRevAbstractNewRow>>>()?;
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::<Vec<WorkRevNewRow>>(),
- )
- .returning(work_rev::id)
+ }).collect::<Vec<WorkRevNewRow>>(),
+ ).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<Future<Item = CreateEditgroupResponse, Error = ApiError> + 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<Uuid>,
pub raw_name: Option<String>,
pub role: Option<String>,
- pub index_val: Option<i64>,
+ pub index_val: Option<i32>,
pub extra_json: Option<serde_json::Value>,
}
@@ -350,7 +350,7 @@ pub struct ReleaseContribNewRow {
pub creator_ident_id: Option<Uuid>,
pub raw_name: Option<String>,
pub role: Option<String>,
- pub index_val: Option<i64>,
+ pub index_val: Option<i32>,
pub extra_json: Option<serde_json::Value>,
}
@@ -360,11 +360,11 @@ pub struct ReleaseRefRow {
pub id: i64,
pub release_rev: Uuid,
pub target_release_ident_id: Option<Uuid>,
- pub index_val: Option<i64>,
+ pub index_val: Option<i32>,
pub key: Option<String>,
pub extra_json: Option<serde_json::Value>,
- pub container_title: Option<String>,
- pub year: Option<i64>,
+ pub container_name: Option<String>,
+ pub year: Option<i32>,
pub title: Option<String>,
pub locator: Option<String>,
}
@@ -374,11 +374,11 @@ pub struct ReleaseRefRow {
pub struct ReleaseRefNewRow {
pub release_rev: Uuid,
pub target_release_ident_id: Option<Uuid>,
- pub index_val: Option<i64>,
+ pub index_val: Option<i32>,
pub key: Option<String>,
pub extra_json: Option<serde_json::Value>,
- pub container_title: Option<String>,
- pub year: Option<i64>,
+ pub container_name: Option<String>,
+ pub year: Option<i32>,
pub title: Option<String>,
pub locator: Option<String>,
}
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<Uuid>,
raw_name -> Nullable<Text>,
role -> Nullable<Text>,
- index_val -> Nullable<Int8>,
+ index_val -> Nullable<Int4>,
extra_json -> Nullable<Jsonb>,
}
}
@@ -191,11 +191,11 @@ table! {
id -> Int8,
release_rev -> Uuid,
target_release_ident_id -> Nullable<Uuid>,
- index_val -> Nullable<Int8>,
+ index_val -> Nullable<Int4>,
key -> Nullable<Text>,
extra_json -> Nullable<Jsonb>,
- container_title -> Nullable<Text>,
- year -> Nullable<Int8>,
+ container_name -> Nullable<Text>,
+ year -> Nullable<Int4>,
title -> Nullable<Text>,
locator -> Nullable<Text>,
}