diff options
Diffstat (limited to 'rust')
-rw-r--r-- | rust/fatcat-api/README.md | 2 | ||||
-rw-r--r-- | rust/fatcat-api/api.yaml | 23 | ||||
-rw-r--r-- | rust/fatcat-api/api/swagger.yaml | 42 | ||||
-rw-r--r-- | rust/fatcat-api/examples/client.rs | 2 | ||||
-rw-r--r-- | rust/fatcat-api/examples/server_lib/server.rs | 4 | ||||
-rw-r--r-- | rust/fatcat-api/src/client.rs | 6 | ||||
-rw-r--r-- | rust/fatcat-api/src/lib.rs | 8 | ||||
-rw-r--r-- | rust/fatcat-api/src/models.rs | 45 | ||||
-rw-r--r-- | rust/fatcat-api/src/server.rs | 12 | ||||
-rw-r--r-- | rust/fatcat-openapi2.yml | 23 | ||||
-rw-r--r-- | rust/migrations/2018-05-12-001226_init/up.sql | 39 | ||||
-rw-r--r-- | rust/src/api_server.rs | 59 | ||||
-rw-r--r-- | rust/src/database_models.rs | 17 | ||||
-rw-r--r-- | rust/src/database_schema.rs | 11 | ||||
-rw-r--r-- | rust/tests/test_api_server.rs | 4 |
15 files changed, 198 insertions, 99 deletions
diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md index 146758fb..1c409076 100644 --- a/rust/fatcat-api/README.md +++ b/rust/fatcat-api/README.md @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.1.0 -- Build date: 2018-05-26T02:33:00.709Z +- Build date: 2018-05-27T00:04:18.431Z This autogenerated project defines an API crate `fatcat` which contains: * An `Api` trait defining the API in Rust. diff --git a/rust/fatcat-api/api.yaml b/rust/fatcat-api/api.yaml index 146c11dd..585932b3 100644 --- a/rust/fatcat-api/api.yaml +++ b/rust/fatcat-api/api.yaml @@ -83,10 +83,10 @@ definitions: creator_entity: type: object required: - - name + - full_name properties: <<: *ENTITYPROPS - name: + full_name: type: string example: "Grace Hopper" orcid: @@ -105,10 +105,14 @@ definitions: publisher: type: string example: "Society of Curious Students" - issn: + issnl: type: string #format: custom example: "1234-5678" + abbrev: + type: string + coden: + type: string file_entity: type: object properties: @@ -121,6 +125,10 @@ definitions: type: string #format: custom example: "f013d66c7f6817d08b7eb2a93e6d0440c1f3e7f8" + md5: + type: string + #format: custom + example: "d41efcc592d1e40ac13905377399eb9b" url: type: string format: url @@ -155,6 +163,9 @@ definitions: type: string #format: custom example: "10.1234/abcde.789" + isbn13: + type: string + #format: custom volume: type: string pages: @@ -162,6 +173,8 @@ definitions: issue: type: string example: "12" + publisher: + type: string contribs: type: array items: @@ -271,7 +284,7 @@ definitions: #format: uuid creator_stub: type: string - contrib_type: + role: type: string x-entity-responses: &ENTITYRESPONSES @@ -359,7 +372,7 @@ paths: /container/lookup: get: parameters: - - name: issn + - name: issnl in: query type: string required: true diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml index db7b0e03..e6b4b356 100644 --- a/rust/fatcat-api/api/swagger.yaml +++ b/rust/fatcat-api/api/swagger.yaml @@ -285,12 +285,12 @@ paths: /container/lookup: get: parameters: - - name: "issn" + - name: "issnl" in: "query" required: true type: "string" formatString: "\\\"{}\\\"" - example: "\"issn_example\".to_string()" + example: "\"issnl_example\".to_string()" responses: 200: description: "Found Entity" @@ -1023,12 +1023,12 @@ definitions: creator_entity: type: "object" required: - - "name" + - "full_name" properties: orcid: type: "string" example: "0000-0002-1825-0097" - name: + full_name: type: "string" example: "Grace Hopper" extra: @@ -1056,9 +1056,9 @@ definitions: - "deleted" example: redirect: "f1f046a3-45c9-4b99-adce-000000000002" + full_name: "Grace Hopper" ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" - name: "Grace Hopper" editgroup_id: 16 orcid: "0000-0002-1825-0097" state: "wip" @@ -1069,7 +1069,11 @@ definitions: required: - "name" properties: - issn: + coden: + type: "string" + abbrev: + type: "string" + issnl: type: "string" example: "1234-5678" publisher: @@ -1103,12 +1107,14 @@ definitions: type: "object" example: redirect: "f1f046a3-45c9-4b99-adce-000000000002" - issn: "1234-5678" + coden: "coden" ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" name: "Journal of Important Results" publisher: "Society of Curious Students" editgroup_id: 16 + issnl: "1234-5678" + abbrev: "abbrev" state: "wip" revision: 42 upperCaseName: "CONTAINER_ENTITY" @@ -1123,6 +1129,9 @@ definitions: type: "string" format: "url" example: "https://example.edu/~frau/prcding.pdf" + md5: + type: "string" + example: "d41efcc592d1e40ac13905377399eb9b" sha1: type: "string" example: "f013d66c7f6817d08b7eb2a93e6d0440c1f3e7f8" @@ -1165,6 +1174,7 @@ definitions: releases: - "releases" - "releases" + md5: "d41efcc592d1e40ac13905377399eb9b" revision: 42 upperCaseName: "FILE_ENTITY" release_entity: @@ -1181,6 +1191,8 @@ definitions: type: "array" items: $ref: "#/definitions/release_contrib" + publisher: + type: "string" issue: type: "string" example: "12" @@ -1188,6 +1200,8 @@ definitions: type: "string" volume: type: "string" + isbn13: + type: "string" doi: type: "string" example: "10.1234/abcde.789" @@ -1237,14 +1251,14 @@ definitions: release_type: "preprint" title: "title" contribs: - - creator_stub: "creator_stub" + - role: "role" + creator_stub: "creator_stub" creator_id: "creator_id" index: 6 - contrib_type: "contrib_type" - - creator_stub: "creator_stub" + - role: "role" + creator_stub: "creator_stub" creator_id: "creator_id" index: 6 - contrib_type: "contrib_type" revision: 42 volume: "volume" pages: "pages" @@ -1255,7 +1269,9 @@ definitions: - target_release_id: "target_release_id" stub: "stub" index: 0 + isbn13: "isbn13" extra: "{}" + publisher: "publisher" editgroup_id: 16 state: "wip" container_id: "f1f046a3-45c9-4b99-adce-000000000001" @@ -1463,13 +1479,13 @@ definitions: type: "string" creator_stub: type: "string" - contrib_type: + role: type: "string" example: + role: "role" creator_stub: "creator_stub" creator_id: "creator_id" index: 6 - contrib_type: "contrib_type" upperCaseName: "RELEASE_CONTRIB" editgroup_edits: properties: diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs index 396cf3d1..f2eccb9e 100644 --- a/rust/fatcat-api/examples/client.rs +++ b/rust/fatcat-api/examples/client.rs @@ -70,7 +70,7 @@ fn main() { } Some("ContainerLookupGet") => { - let result = client.container_lookup_get("issn_example".to_string()).wait(); + let result = client.container_lookup_get("issnl_example".to_string()).wait(); println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } diff --git a/rust/fatcat-api/examples/server_lib/server.rs b/rust/fatcat-api/examples/server_lib/server.rs index 68670c07..a28b9c72 100644 --- a/rust/fatcat-api/examples/server_lib/server.rs +++ b/rust/fatcat-api/examples/server_lib/server.rs @@ -24,9 +24,9 @@ impl Api for Server { Box::new(futures::failed("Generic failure".into())) } - fn container_lookup_get(&self, issn: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { + fn container_lookup_get(&self, issnl: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!("container_lookup_get(\"{}\") - X-Span-ID: {:?}", issn, context.x_span_id.unwrap_or(String::from("<none>")).clone()); + println!("container_lookup_get(\"{}\") - X-Span-ID: {:?}", issnl, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } 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<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { + fn container_lookup_get(&self, param_issnl: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + 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<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send>; - fn container_lookup_get(&self, issn: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; + fn container_lookup_get(&self, issnl: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; fn container_post(&self, body: models::ContainerEntity, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>; @@ -299,7 +299,7 @@ pub trait Api { pub trait ApiNoContext { fn container_id_get(&self, id: String) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send>; - fn container_lookup_get(&self, issn: String) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; + fn container_lookup_get(&self, issnl: String) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; fn container_post(&self, body: models::ContainerEntity) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + 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<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { - self.api().container_lookup_get(issn, &self.context()) + fn container_lookup_get(&self, issnl: String) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { + self.api().container_lookup_get(issnl, &self.context()) } fn container_post(&self, body: models::ContainerEntity) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + 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<String>, + pub coden: Option<String>, + + #[serde(rename = "abbrev")] + #[serde(skip_serializing_if = "Option::is_none")] + pub abbrev: Option<String>, + + #[serde(rename = "issnl")] + #[serde(skip_serializing_if = "Option::is_none")] + pub issnl: Option<String>, #[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<String>, - #[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<String>, + #[serde(rename = "md5")] + #[serde(skip_serializing_if = "Option::is_none")] + pub md5: Option<String>, + #[serde(rename = "sha1")] #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option<String>, @@ -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<String>, - #[serde(rename = "contrib_type")] + #[serde(rename = "role")] #[serde(skip_serializing_if = "Option::is_none")] - pub contrib_type: Option<String>, + pub role: Option<String>, } 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<Vec<models::ReleaseContrib>>, + #[serde(rename = "publisher")] + #[serde(skip_serializing_if = "Option::is_none")] + pub publisher: Option<String>, + #[serde(rename = "issue")] #[serde(skip_serializing_if = "Option::is_none")] pub issue: Option<String>, @@ -440,6 +459,10 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub volume: Option<String>, + #[serde(rename = "isbn13")] + #[serde(skip_serializing_if = "Option::is_none")] + pub isbn13: Option<String>, + #[serde(rename = "doi")] #[serde(skip_serializing_if = "Option::is_none")] pub doi: Option<String>, @@ -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::<UrlEncodedQuery>().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::<String>() - .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"); diff --git a/rust/fatcat-openapi2.yml b/rust/fatcat-openapi2.yml index 146c11dd..585932b3 100644 --- a/rust/fatcat-openapi2.yml +++ b/rust/fatcat-openapi2.yml @@ -83,10 +83,10 @@ definitions: creator_entity: type: object required: - - name + - full_name properties: <<: *ENTITYPROPS - name: + full_name: type: string example: "Grace Hopper" orcid: @@ -105,10 +105,14 @@ definitions: publisher: type: string example: "Society of Curious Students" - issn: + issnl: type: string #format: custom example: "1234-5678" + abbrev: + type: string + coden: + type: string file_entity: type: object properties: @@ -121,6 +125,10 @@ definitions: type: string #format: custom example: "f013d66c7f6817d08b7eb2a93e6d0440c1f3e7f8" + md5: + type: string + #format: custom + example: "d41efcc592d1e40ac13905377399eb9b" url: type: string format: url @@ -155,6 +163,9 @@ definitions: type: string #format: custom example: "10.1234/abcde.789" + isbn13: + type: string + #format: custom volume: type: string pages: @@ -162,6 +173,8 @@ definitions: issue: type: string example: "12" + publisher: + type: string contribs: type: array items: @@ -271,7 +284,7 @@ definitions: #format: uuid creator_stub: type: string - contrib_type: + role: type: string x-entity-responses: &ENTITYRESPONSES @@ -359,7 +372,7 @@ paths: /container/lookup: get: parameters: - - name: issn + - name: issnl in: query type: string required: true diff --git a/rust/migrations/2018-05-12-001226_init/up.sql b/rust/migrations/2018-05-12-001226_init/up.sql index 1f366f90..474029d0 100644 --- a/rust/migrations/2018-05-12-001226_init/up.sql +++ b/rust/migrations/2018-05-12-001226_init/up.sql @@ -37,8 +37,10 @@ CREATE TABLE creator_rev ( id BIGSERIAL PRIMARY KEY, extra_json JSON, - name TEXT NOT NULL, + full_name TEXT NOT NULL, orcid TEXT + -- TODO: aliases/alternatives + -- TODO: sortable name? ); -- Could denormalize a "is_live" flag into revision tables, to make indices @@ -68,10 +70,12 @@ CREATE TABLE container_rev ( name TEXT NOT NULL, publisher TEXT, - issn TEXT -- TODO: varchar + issnl TEXT, -- TODO: varchar + abbrev TEXT, + coden TEXT ); -CREATE INDEX container_rev_issn_idx ON container_rev(issn) WHERE issn IS NOT NULL; +CREATE INDEX container_rev_issnl_idx ON container_rev(issnl) WHERE issnl IS NOT NULL; CREATE TABLE container_ident ( id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), @@ -96,6 +100,7 @@ CREATE TABLE file_rev ( size BIGINT, sha1 TEXT, -- TODO: varchar or bytes + md5 TEXT, -- TODO: varchar or bytes url TEXT -- TODO: URL table ); @@ -126,9 +131,11 @@ CREATE TABLE release_rev ( release_type TEXT, -- TODO: enum date DATE, doi TEXT, + isbn13 TEXT, volume TEXT, pages TEXT, - issue TEXT + issue TEXT, + publisher TEXT -- for books, NOT if container exists -- TODO: identifier table? ); @@ -187,7 +194,7 @@ CREATE TABLE release_contrib ( id BIGSERIAL PRIMARY KEY, release_rev BIGSERIAL REFERENCES release_rev(id) NOT NULL, creator_ident_id UUID REFERENCES creator_ident(id), - contrib_type TEXT, + role TEXT, -- TODO: enum? index BIGINT, stub TEXT ); @@ -237,9 +244,9 @@ INSERT INTO changelog (editgroup_id) VALUES (4), (5); -INSERT INTO container_rev (name, issn) VALUES - ('Journal of Trivial Results', '1234-5678'), - ('MySpace Blog', null); +INSERT INTO container_rev (name, issnl, abbrev, coden) VALUES + ('Journal of Trivial Results', '1234-5678', null, null), + ('MySpace Blog', null, null, null); INSERT INTO container_ident (id, is_live, rev_id, redirect_id) VALUES ('f1f046a3-45c9-4b99-cccc-000000000001', true, 1, null), @@ -249,7 +256,7 @@ INSERT INTO container_edit (ident_id, rev_id, redirect_id, editgroup_id) VALUES ('f1f046a3-45c9-4b99-cccc-000000000001', 1, null, 4), ('f1f046a3-45c9-4b99-cccc-000000000002', 2, null, 5); -INSERT INTO creator_rev (name, orcid) VALUES +INSERT INTO creator_rev (full_name, orcid) VALUES ('Grace Hopper', null), ('Emily Noethe', null), ('Christine Moran', '0000-0003-2088-7465'); @@ -266,9 +273,9 @@ INSERT INTO creator_edit (ident_id, rev_id, redirect_id, editgroup_id) VALUES ('f1f046a3-45c9-4b99-adce-000000000003', 3, null, 3), ('f1f046a3-45c9-4b99-adce-000000000004', 2, null, 4); -INSERT INTO file_rev (size, sha1, url) VALUES - (null, null, null), - (4321, '7d97e98f8af710c7e7fe703abc8f639e0ee507c4', 'http://archive.org/robots.txt'); +INSERT INTO file_rev (size, sha1, md5, url) VALUES + (null, null, null, null), + (4321, '7d97e98f8af710c7e7fe703abc8f639e0ee507c4', null, 'http://archive.org/robots.txt'); INSERT INTO file_ident (id, is_live, rev_id, redirect_id) VALUES ('f1f046a3-45c9-4b99-ffff-000000000001', true, 1, null), @@ -290,9 +297,9 @@ INSERT INTO work_edit (ident_id, rev_id, redirect_id, editgroup_id) VALUES ('f1f046a3-45c9-4b99-3333-000000000001', 1, null, 4), ('f1f046a3-45c9-4b99-3333-000000000002', 2, null, 5); -INSERT INTO release_rev (work_ident_id, container_ident_id, title, release_type, date, doi, volume, pages, issue) VALUES - ('f1f046a3-45c9-4b99-3333-000000000001', null, 'example title', null, null, null, null, null, null), - ('f1f046a3-45c9-4b99-3333-000000000002', 'f1f046a3-45c9-4b99-cccc-000000000001', 'bigger example', 'journal-article', '2018-01-01', '10.123/abc', '12', '5-9', 'IV'); +INSERT INTO release_rev (work_ident_id, container_ident_id, title, release_type, date, doi, isbn13, volume, pages, issue, publisher) VALUES + ('f1f046a3-45c9-4b99-3333-000000000001', null, 'example title', null, null, null, null, null, null, null, null), + ('f1f046a3-45c9-4b99-3333-000000000002', 'f1f046a3-45c9-4b99-cccc-000000000001', 'bigger example', 'journal-article', '2018-01-01', null, '10.123/abc', '12', '5-9', 'IV', null); INSERT INTO release_ident (id, is_live, rev_id, redirect_id) VALUES ('f1f046a3-45c9-4b99-4444-000000000001', true, 1, null), @@ -302,7 +309,7 @@ INSERT INTO release_edit (ident_id, rev_id, redirect_id, editgroup_id) VALUES ('f1f046a3-45c9-4b99-4444-000000000001', 1, null, 4), ('f1f046a3-45c9-4b99-4444-000000000002', 2, null, 5); -INSERT INTO release_contrib (release_rev, creator_ident_id, stub, contrib_type, index) VALUES +INSERT INTO release_contrib (release_rev, creator_ident_id, stub, role, index) VALUES (2, null, null, null, null), (2, 'f1f046a3-45c9-4b99-adce-000000000002', 'some contrib', 'editor', 4); diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 8311896f..42c69c00 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -94,9 +94,11 @@ impl Server { }; let entity = ContainerEntity { - issn: rev.issn, + issnl: rev.issnl, publisher: rev.publisher, name: rev.name, + abbrev: rev.abbrev, + coden: rev.coden, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), revision: ident.rev_id, @@ -107,13 +109,13 @@ impl Server { Ok(Some(entity)) } - fn container_lookup_get_handler(&self, issn: String) -> Result<Option<ContainerEntity>> { + fn container_lookup_get_handler(&self, issnl: String) -> Result<Option<ContainerEntity>> { let conn = self.db_pool.get().expect("db_pool error"); let res: ::std::result::Result<(ContainerIdentRow, ContainerRevRow), _> = container_ident::table .inner_join(container_rev::table) - .filter(container_rev::issn.eq(&issn)) + .filter(container_rev::issnl.eq(&issnl)) .filter(container_ident::is_live.eq(true)) .filter(container_ident::redirect_id.is_null()) .first(&conn); @@ -125,9 +127,11 @@ impl Server { }; let entity = ContainerEntity { - issn: rev.issn, + issnl: rev.issnl, publisher: rev.publisher, name: rev.name, + abbrev: rev.abbrev, + coden: rev.coden, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), revision: ident.rev_id, @@ -154,7 +158,7 @@ impl Server { }; let entity = CreatorEntity { - name: rev.name, + full_name: rev.full_name, orcid: rev.orcid, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), @@ -183,7 +187,7 @@ impl Server { }; let entity = CreatorEntity { - name: rev.name, + full_name: rev.full_name, orcid: rev.orcid, state: Some(ident.state().unwrap().shortname()), ident: Some(ident.id.to_string()), @@ -220,6 +224,7 @@ impl Server { let entity = FileEntity { sha1: rev.sha1, + md5: rev.md5, size: rev.size.map(|v| v as i64), url: rev.url, releases: Some(releases), @@ -260,6 +265,7 @@ impl Server { let entity = FileEntity { sha1: rev.sha1, + md5: rev.md5, size: rev.size.map(|v| v as i64), url: rev.url, releases: Some(releases), @@ -334,7 +340,7 @@ impl Server { .iter() .map(|c: &ReleaseContribRow| ReleaseContrib { index: c.index, - contrib_type: c.contrib_type.clone(), + role: c.role.clone(), creator_stub: c.stub.clone(), creator_id: c.creator_ident_id.map(|v| v.to_string()), }) @@ -346,10 +352,12 @@ impl Server { date: rev.date .map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, + isbn13: rev.isbn13, volume: rev.volume, pages: rev.pages, issue: rev.issue, container_id: rev.container_ident_id.map(|u| u.to_string()), + publisher: rev.publisher, work_id: rev.work_ident_id.to_string(), refs: Some(refs), contribs: Some(contribs), @@ -398,7 +406,7 @@ impl Server { .iter() .map(|c: &ReleaseContribRow| ReleaseContrib { index: c.index, - contrib_type: c.contrib_type.clone(), + role: c.role.clone(), creator_stub: c.stub.clone(), creator_id: c.creator_ident_id.map(|v| v.to_string()), }) @@ -410,10 +418,12 @@ impl Server { date: rev.date .map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, + isbn13: rev.isbn13, volume: rev.volume, pages: rev.pages, issue: rev.issue, container_id: rev.container_ident_id.map(|u| u.to_string()), + publisher: rev.publisher, work_id: rev.work_ident_id.to_string(), refs: Some(refs), contribs: Some(contribs), @@ -594,7 +604,7 @@ impl Api for Server { container_lookup_get, container_lookup_get_handler, ContainerLookupGetResponse, - issn, + issnl, String ); wrap_lookup_handler!( @@ -632,18 +642,20 @@ impl Api for Server { }; let edit: ContainerEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO container_rev (name, publisher, issn, extra_json) - VALUES ($1, $2, $3, $4) + "WITH rev AS ( INSERT INTO container_rev (name, publisher, issnl, abbrev, coden, extra_json) + VALUES ($1, $2, $3, $4, $5, $6) RETURNING id ), ident AS ( INSERT INTO container_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO container_edit (editgroup_id, ident_id, rev_id) VALUES - ($5, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($7, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::<diesel::sql_types::Text, _>(body.name) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.publisher) - .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.issn) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.issnl) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.abbrev) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.coden) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) .get_result(&conn) @@ -676,7 +688,7 @@ impl Api for Server { }; let edit: CreatorEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO creator_rev (name, orcid, extra_json) + "WITH rev AS ( INSERT INTO creator_rev (full_name, orcid, extra_json) VALUES ($1, $2, $3) RETURNING id ), ident AS ( INSERT INTO creator_ident (rev_id) @@ -685,7 +697,7 @@ impl Api for Server { INSERT INTO creator_edit (editgroup_id, ident_id, rev_id) VALUES ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", - ).bind::<diesel::sql_types::Text, _>(body.name) + ).bind::<diesel::sql_types::Text, _>(body.full_name) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.orcid) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) @@ -720,17 +732,18 @@ impl Api for Server { let edit: FileEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO file_rev (size, sha1, url, extra_json) - VALUES ($1, $2, $3, $4) + "WITH rev AS ( INSERT INTO file_rev (size, sha1, md5, url, extra_json) + VALUES ($1, $2, $3, $4, $5) RETURNING id ), ident AS ( INSERT INTO file_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO file_edit (editgroup_id, ident_id, rev_id) VALUES - ($5, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($6, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::<diesel::sql_types::Nullable<diesel::sql_types::Int8>, _>(body.size) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.sha1) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.md5) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.url) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) @@ -835,24 +848,26 @@ impl Api for Server { }; let edit: ReleaseEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO release_rev (title, release_type, date, doi, volume, pages, issue, work_ident_id, container_ident_id, extra_json) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) + "WITH rev AS ( INSERT INTO release_rev (title, release_type, date, doi, isbn13, volume, pages, issue, work_ident_id, container_ident_id, publisher, extra_json) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING id ), ident AS ( INSERT INTO release_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO release_edit (editgroup_id, ident_id, rev_id) VALUES - ($11, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($13, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::<diesel::sql_types::Text, _>(body.title) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.release_type) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Date>, _>(body.date.map(|v| v.naive_utc().date())) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.doi) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.isbn13) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.volume) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.pages) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.issue) .bind::<diesel::sql_types::Uuid, _>(work_id) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Uuid>, _>(container_id) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.publisher) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) .get_result(&conn) @@ -899,7 +914,7 @@ impl Api for Server { .clone() .map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")), index: c.index, - contrib_type: c.contrib_type.clone(), + role: c.role.clone(), stub: c.creator_stub.clone(), }) .collect(); diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index b27bca3f..9913b7e2 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -75,7 +75,9 @@ pub struct ContainerRevRow { pub extra_json: Option<serde_json::Value>, pub name: String, pub publisher: Option<String>, - pub issn: Option<String>, + pub issnl: Option<String>, + pub abbrev: Option<String>, + pub coden: Option<String>, } entity_structs!( @@ -90,7 +92,7 @@ entity_structs!( pub struct CreatorRevRow { pub id: i64, pub extra_json: Option<serde_json::Value>, - pub name: String, + pub full_name: String, pub orcid: Option<String>, } @@ -108,6 +110,7 @@ pub struct FileRevRow { pub extra_json: Option<serde_json::Value>, pub size: Option<i64>, pub sha1: Option<String>, + pub md5: Option<String>, pub url: Option<String>, } @@ -124,9 +127,11 @@ pub struct ReleaseRevRow { pub release_type: Option<String>, pub date: Option<chrono::NaiveDate>, pub doi: Option<String>, + pub isbn13: Option<String>, pub volume: Option<String>, pub pages: Option<String>, pub issue: Option<String>, + pub publisher: Option<String>, } entity_structs!( @@ -153,9 +158,9 @@ pub struct ReleaseContribRow { pub id: i64, pub release_rev: i64, pub creator_ident_id: Option<Uuid>, - pub stub: Option<String>, + pub role: Option<String>, pub index: Option<i64>, - pub contrib_type: Option<String>, + pub stub: Option<String>, } #[derive(Debug, Insertable)] @@ -163,9 +168,9 @@ pub struct ReleaseContribRow { pub struct ReleaseContribNewRow { pub release_rev: i64, pub creator_ident_id: Option<Uuid>, - pub stub: Option<String>, + pub role: Option<String>, pub index: Option<i64>, - pub contrib_type: Option<String>, + pub stub: Option<String>, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 7d8ff4e1..2541bcd8 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -32,7 +32,9 @@ table! { extra_json -> Nullable<Json>, name -> Text, publisher -> Nullable<Text>, - issn -> Nullable<Text>, + issnl -> Nullable<Text>, + abbrev -> Nullable<Text>, + coden -> Nullable<Text>, } } @@ -60,7 +62,7 @@ table! { creator_rev (id) { id -> Int8, extra_json -> Nullable<Json>, - name -> Text, + full_name -> Text, orcid -> Nullable<Text>, } } @@ -116,6 +118,7 @@ table! { extra_json -> Nullable<Json>, size -> Nullable<Int8>, sha1 -> Nullable<Text>, + md5 -> Nullable<Text>, url -> Nullable<Text>, } } @@ -125,7 +128,7 @@ table! { id -> Int8, release_rev -> Int8, creator_ident_id -> Nullable<Uuid>, - contrib_type -> Nullable<Text>, + role -> Nullable<Text>, index -> Nullable<Int8>, stub -> Nullable<Text>, } @@ -171,9 +174,11 @@ table! { release_type -> Nullable<Text>, date -> Nullable<Date>, doi -> Nullable<Text>, + isbn13 -> Nullable<Text>, volume -> Nullable<Text>, pages -> Nullable<Text>, issue -> Nullable<Text>, + publisher -> Nullable<Text>, } } diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs index 8eedfa2f..a973b333 100644 --- a/rust/tests/test_api_server.rs +++ b/rust/tests/test_api_server.rs @@ -117,7 +117,7 @@ fn test_lookups() { check_response( request::get( - "http://localhost:9411/v0/container/lookup?issn=1234-5678", + "http://localhost:9411/v0/container/lookup?issnl=1234-5678", headers.clone(), &router, ), @@ -170,7 +170,7 @@ fn test_post_creator() { request::post( "http://localhost:9411/v0/creator", headers, - r#"{"name": "some person"}"#, + r#"{"full_name": "some person"}"#, &router, ), status::Created, |