From 0ec7c973417f5d120db80d1c1dd3e329711a1ca4 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 4 Jun 2018 00:19:36 -0700 Subject: update rust/api for schema extensions --- rust/src/api_server.rs | 56 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'rust/src/api_server.rs') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 0706fc22..c167c067 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -155,7 +155,9 @@ fn creator_row2entity(ident: Option, rev: CreatorRevRow) -> Res None => (None, None, None), }; Ok(CreatorEntity { - full_name: rev.full_name, + display_name: rev.display_name, + given_name: rev.given_name, + surname: rev.surname, orcid: rev.orcid, state: state, ident: ident_id, @@ -189,9 +191,11 @@ fn file_row2entity( Ok(FileEntity { sha1: rev.sha1, + sha256: rev.sha256, md5: rev.md5, size: rev.size.map(|v| v as i64), url: rev.url, + mimetype: rev.mimetype, releases: Some(releases), state: state, ident: ident_id, @@ -223,7 +227,12 @@ fn release_row2entity( .iter() .map(|r: &ReleaseRefRow| ReleaseRef { index: r.index.clone(), - stub: r.stub.clone(), + key: r.key.clone(), + raw: r.raw.clone(), + container_title: r.container_title.clone(), + year: r.year.clone(), + title: r.title.clone(), + locator: r.locator.clone(), target_release_id: r.target_release_ident_id.map(|v| v.to_string()), }) .collect(); @@ -236,7 +245,7 @@ fn release_row2entity( .map(|c: &ReleaseContribRow| ReleaseContrib { index: c.index, role: c.role.clone(), - creator_stub: c.stub.clone(), + raw: c.raw.clone(), creator_id: c.creator_ident_id.map(|v| v.to_string()), }) .collect(); @@ -244,7 +253,8 @@ fn release_row2entity( Ok(ReleaseEntity { title: rev.title, release_type: rev.release_type, - date: rev.date + release_status: rev.release_status, + release_date: rev.release_date .map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, isbn13: rev.isbn13, @@ -253,6 +263,7 @@ fn release_row2entity( issue: rev.issue, container_id: rev.container_ident_id.map(|u| u.to_string()), publisher: rev.publisher, + language: rev.language, work_id: rev.work_ident_id.to_string(), refs: Some(refs), contribs: Some(contribs), @@ -481,16 +492,18 @@ impl Server { }; let edit: CreatorEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO creator_rev (full_name, orcid, extra_json) - VALUES ($1, $2, $3) + "WITH rev AS ( INSERT INTO creator_rev (display_name, given_name, surname, orcid, extra_json) + VALUES ($1, $2, $3, $4, $5) RETURNING id ), ident AS ( INSERT INTO creator_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO creator_edit (editgroup_id, ident_id, rev_id) VALUES - ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($6, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", - ).bind::(entity.full_name) + ).bind::(entity.display_name) + .bind::, _>(entity.given_name) + .bind::, _>(entity.surname) .bind::, _>(entity.orcid) .bind::, _>(entity.extra) .bind::(editgroup_id) @@ -521,19 +534,21 @@ impl Server { let edit: FileEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO file_rev (size, sha1, md5, url, extra_json) - VALUES ($1, $2, $3, $4, $5) + "WITH rev AS ( INSERT INTO file_rev (size, sha1, sha256, md5, url, mimetype, extra_json) + VALUES ($1, $2, $3, $4, $5, $6, $7) 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 - ($6, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($8, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::, _>(entity.size) .bind::, _>(entity.sha1) + .bind::, _>(entity.sha256) .bind::, _>(entity.md5) .bind::, _>(entity.url) + .bind::, _>(entity.mimetype) .bind::, _>(entity.extra) .bind::(editgroup_id) .get_result(conn)?; @@ -590,19 +605,20 @@ impl Server { }; let edit: ReleaseEditRow = diesel::sql_query( - "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) + "WITH rev AS ( INSERT INTO release_rev (title, release_type, release_status, release_date, doi, isbn13, volume, pages, issue, work_ident_id, container_ident_id, publisher, language, extra_json) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) 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 - ($13, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($15, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::(entity.title) .bind::, _>(entity.release_type) + .bind::, _>(entity.release_status) .bind::, _>( - entity.date.map(|v| v.naive_utc().date())) + entity.release_date.map(|v| v.naive_utc().date())) .bind::, _>(entity.doi) .bind::, _>(entity.isbn13) .bind::, _>(entity.volume) @@ -611,6 +627,7 @@ impl Server { .bind::(work_id) .bind::, _>(container_id) .bind::, _>(entity.publisher) + .bind::, _>(entity.language) .bind::, _>(entity.extra) .bind::(editgroup_id) .get_result(conn)?; @@ -629,7 +646,12 @@ impl Server { .clone() .map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")), index: r.index, - stub: r.stub.clone(), + key: r.key.clone(), + container_title: r.container_title.clone(), + year: r.year, + title: r.title.clone(), + locator: r.locator.clone(), + raw: r.raw.clone(), }) .collect(); let ref_rows: Vec = insert_into(release_ref::table) @@ -656,7 +678,7 @@ impl Server { .map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")), index: c.index, role: c.role.clone(), - stub: c.creator_stub.clone(), + raw: c.raw.clone(), }) .collect(); let contrib_rows: Vec = insert_into(release_contrib::table) -- cgit v1.2.3