From 6f54d75f644ab5f0120637b1ceb13b16a4c8534d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 25 May 2018 18:59:02 -0700 Subject: fix date on release --- rust/fatcat-api/README.md | 2 +- rust/fatcat-api/api.yaml | 3 ++- rust/fatcat-api/api/swagger.yaml | 4 ++++ rust/fatcat-api/src/models.rs | 5 +++++ rust/fatcat-openapi2.yml | 3 ++- rust/src/api_server.rs | 13 ++++++------- 6 files changed, 20 insertions(+), 10 deletions(-) (limited to 'rust') diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md index b67ad8f1..364f7271 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-26T00:48:55.047Z +- Build date: 2018-05-26T01:47:28.955Z 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 8dd4177f..cfce24d7 100644 --- a/rust/fatcat-api/api.yaml +++ b/rust/fatcat-api/api.yaml @@ -145,7 +145,8 @@ definitions: type: string example: "preprint" date: - type: date + type: string + format: date doi: type: string #format: custom diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml index ce85d813..506cb9db 100644 --- a/rust/fatcat-api/api/swagger.yaml +++ b/rust/fatcat-api/api/swagger.yaml @@ -1191,6 +1191,9 @@ definitions: doi: type: "string" example: "10.1234/abcde.789" + date: + type: "string" + format: "date" release_type: type: "string" example: "preprint" @@ -1226,6 +1229,7 @@ definitions: extra: type: "object" example: + date: "2000-01-23" redirect: "f1f046a3-45c9-4b99-adce-000000000002" work_id: "f1f046a3-45c9-4b99-adce-000000000001" issue: "12" diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index 8d3abe7d..e3ce33c3 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -442,6 +442,10 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub doi: Option, + #[serde(rename = "date")] + #[serde(skip_serializing_if = "Option::is_none")] + pub date: Option>, + #[serde(rename = "release_type")] #[serde(skip_serializing_if = "Option::is_none")] pub release_type: Option, @@ -491,6 +495,7 @@ impl ReleaseEntity { pages: None, volume: None, doi: None, + date: None, release_type: None, container_id: None, work_id: work_id, diff --git a/rust/fatcat-openapi2.yml b/rust/fatcat-openapi2.yml index 8dd4177f..cfce24d7 100644 --- a/rust/fatcat-openapi2.yml +++ b/rust/fatcat-openapi2.yml @@ -145,7 +145,8 @@ definitions: type: string example: "preprint" date: - type: date + type: string + format: date doi: type: string #format: custom diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 6fbce00b..b29dae69 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -342,7 +342,7 @@ impl Server { let entity = ReleaseEntity { title: rev.title, release_type: rev.release_type, - // XXX: date: rev.date, + date: rev.date.map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, volume: rev.volume, pages: rev.pages, @@ -405,7 +405,7 @@ impl Server { let entity = ReleaseEntity { title: rev.title, release_type: rev.release_type, - // XXX: date: rev.date, + date: rev.date.map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, volume: rev.volume, pages: rev.pages, @@ -740,20 +740,19 @@ impl Api for Server { None => None, }; - println!("{:?}", container_id); let edit: ReleaseEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO release_rev (title, release_type, doi, volume, pages, issue, work_ident_id, container_ident_id) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8) + "WITH rev AS ( INSERT INTO release_rev (title, release_type, date, doi, volume, pages, issue, work_ident_id, container_ident_id) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) 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 - ($9, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($10, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::(body.title) .bind::, _>(body.release_type) - //XXX .bind::, _>(body.date) + .bind::, _>(body.date.map(|v| v.naive_utc().date())) .bind::, _>(body.doi) .bind::, _>(body.volume) .bind::, _>(body.pages) -- cgit v1.2.3