From 55f8a495354d233f7a68128b2f3c21dbe7395427 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 26 May 2018 17:08:21 -0700 Subject: tweak schema (api and sql) --- rust/fatcat-api/src/client.rs | 6 +++--- rust/fatcat-api/src/lib.rs | 8 ++++---- rust/fatcat-api/src/models.rs | 45 +++++++++++++++++++++++++++++++++---------- rust/fatcat-api/src/server.rs | 12 ++++++------ 4 files changed, 48 insertions(+), 23 deletions(-) (limited to 'rust/fatcat-api/src') diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index 517d9705..23f6dd21 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -221,11 +221,11 @@ impl Api for Client { Box::new(futures::done(result)) } - fn container_lookup_get(&self, param_issn: String, context: &Context) -> Box + Send> { + fn container_lookup_get(&self, param_issnl: String, context: &Context) -> Box + Send> { // Query parameters - let query_issn = format!("issn={issn}&", issn = param_issn.to_string()); + let query_issnl = format!("issnl={issnl}&", issnl = param_issnl.to_string()); - let url = format!("{}/v0/container/lookup?{issn}", self.base_path, issn = utf8_percent_encode(&query_issn, QUERY_ENCODE_SET)); + let url = format!("{}/v0/container/lookup?{issnl}", self.base_path, issnl = utf8_percent_encode(&query_issnl, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index 94633e00..a21a0751 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -258,7 +258,7 @@ pub enum WorkPostResponse { pub trait Api { fn container_id_get(&self, id: String, context: &Context) -> Box + Send>; - fn container_lookup_get(&self, issn: String, context: &Context) -> Box + Send>; + fn container_lookup_get(&self, issnl: String, context: &Context) -> Box + Send>; fn container_post(&self, body: models::ContainerEntity, context: &Context) -> Box + Send>; @@ -299,7 +299,7 @@ pub trait Api { pub trait ApiNoContext { fn container_id_get(&self, id: String) -> Box + Send>; - fn container_lookup_get(&self, issn: String) -> Box + Send>; + fn container_lookup_get(&self, issnl: String) -> Box + Send>; fn container_post(&self, body: models::ContainerEntity) -> Box + Send>; @@ -356,8 +356,8 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().container_id_get(id, &self.context()) } - fn container_lookup_get(&self, issn: String) -> Box + Send> { - self.api().container_lookup_get(issn, &self.context()) + fn container_lookup_get(&self, issnl: String) -> Box + Send> { + self.api().container_lookup_get(issnl, &self.context()) } fn container_post(&self, body: models::ContainerEntity) -> Box + Send> { diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index 68242058..b05c0fc1 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -94,9 +94,17 @@ impl ChangelogentriesInner { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ContainerEntity { - #[serde(rename = "issn")] + #[serde(rename = "coden")] #[serde(skip_serializing_if = "Option::is_none")] - pub issn: Option, + pub coden: Option, + + #[serde(rename = "abbrev")] + #[serde(skip_serializing_if = "Option::is_none")] + pub abbrev: Option, + + #[serde(rename = "issnl")] + #[serde(skip_serializing_if = "Option::is_none")] + pub issnl: Option, #[serde(rename = "publisher")] #[serde(skip_serializing_if = "Option::is_none")] @@ -134,7 +142,9 @@ pub struct ContainerEntity { impl ContainerEntity { pub fn new(name: String) -> ContainerEntity { ContainerEntity { - issn: None, + coden: None, + abbrev: None, + issnl: None, publisher: None, name: name, state: None, @@ -153,8 +163,8 @@ pub struct CreatorEntity { #[serde(skip_serializing_if = "Option::is_none")] pub orcid: Option, - #[serde(rename = "name")] - pub name: String, + #[serde(rename = "full_name")] + pub full_name: String, #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] @@ -183,10 +193,10 @@ pub struct CreatorEntity { } impl CreatorEntity { - pub fn new(name: String) -> CreatorEntity { + pub fn new(full_name: String) -> CreatorEntity { CreatorEntity { orcid: None, - name: name, + full_name: full_name, extra: None, editgroup_id: None, redirect: None, @@ -337,6 +347,10 @@ pub struct FileEntity { #[serde(skip_serializing_if = "Option::is_none")] pub url: Option, + #[serde(rename = "md5")] + #[serde(skip_serializing_if = "Option::is_none")] + pub md5: Option, + #[serde(rename = "sha1")] #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option, @@ -376,6 +390,7 @@ impl FileEntity { FileEntity { releases: None, url: None, + md5: None, sha1: None, size: None, extra: None, @@ -402,9 +417,9 @@ pub struct ReleaseContrib { #[serde(skip_serializing_if = "Option::is_none")] pub creator_stub: Option, - #[serde(rename = "contrib_type")] + #[serde(rename = "role")] #[serde(skip_serializing_if = "Option::is_none")] - pub contrib_type: Option, + pub role: Option, } impl ReleaseContrib { @@ -413,7 +428,7 @@ impl ReleaseContrib { index: None, creator_id: None, creator_stub: None, - contrib_type: None, + role: None, } } } @@ -428,6 +443,10 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub contribs: Option>, + #[serde(rename = "publisher")] + #[serde(skip_serializing_if = "Option::is_none")] + pub publisher: Option, + #[serde(rename = "issue")] #[serde(skip_serializing_if = "Option::is_none")] pub issue: Option, @@ -440,6 +459,10 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub volume: Option, + #[serde(rename = "isbn13")] + #[serde(skip_serializing_if = "Option::is_none")] + pub isbn13: Option, + #[serde(rename = "doi")] #[serde(skip_serializing_if = "Option::is_none")] pub doi: Option, @@ -493,9 +516,11 @@ impl ReleaseEntity { ReleaseEntity { refs: None, contribs: None, + publisher: None, issue: None, pages: None, volume: None, + isbn13: None, doi: None, date: None, release_type: None, diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index 95829602..ed012478 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -190,15 +190,15 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_issn = query_params - .get("issn") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issn".to_string())))? + let param_issnl = query_params + .get("issnl") + .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issnl".to_string())))? .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issn was empty".to_string())))? + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issnl was empty".to_string())))? .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issn - doesn't match schema: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issnl - doesn't match schema: {}", e))))?; - match api.container_lookup_get(param_issn, context).wait() { + match api.container_lookup_get(param_issnl, context).wait() { Ok(rsp) => match rsp { ContainerLookupGetResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); -- cgit v1.2.3