diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-25 19:06:03 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-25 19:06:03 -0700 |
commit | f653c4070a076306825501ddbc27c0634d0e1438 (patch) | |
tree | 34241b90346dfb73947c89f3eed01ad9bc73765f | |
parent | 6f54d75f644ab5f0120637b1ceb13b16a4c8534d (diff) | |
download | fatcat-f653c4070a076306825501ddbc27c0634d0e1438.tar.gz fatcat-f653c4070a076306825501ddbc27c0634d0e1438.zip |
extra_json in POST
-rw-r--r-- | rust/src/api_server.rs | 36 | ||||
-rw-r--r-- | rust/tests/test_api_server.rs | 11 |
2 files changed, 28 insertions, 19 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index b29dae69..c9c8e754 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -546,18 +546,19 @@ impl Api for Server { }; let edit: ContainerEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO container_rev (name, publisher, issn) - VALUES ($1, $2, $3) + "WITH rev AS ( INSERT INTO container_rev (name, publisher, issn, extra_json) + VALUES ($1, $2, $3, $4) 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 - ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($5, (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::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) .get_result(&conn) .unwrap(); @@ -588,17 +589,18 @@ impl Api for Server { }; let edit: CreatorEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO creator_rev (name, orcid) - VALUES ($1, $2) + "WITH rev AS ( INSERT INTO creator_rev (name, orcid, extra_json) + VALUES ($1, $2, $3) 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 - ($3, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($4, (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.orcid) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) .get_result(&conn) .unwrap(); @@ -630,18 +632,19 @@ impl Api for Server { let edit: FileEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO file_rev (size, sha1, url) - VALUES ($1, $2, $3) + "WITH rev AS ( INSERT INTO file_rev (size, sha1, url, extra_json) + VALUES ($1, $2, $3, $4) 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 - ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($5, (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.url) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) .get_result(&conn) .unwrap(); @@ -695,16 +698,17 @@ impl Api for Server { let edit: WorkEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO work_rev (work_type) - VALUES ($1) + "WITH rev AS ( INSERT INTO work_rev (work_type, extra_json) + VALUES ($1, $2) RETURNING id ), ident AS ( INSERT INTO work_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO work_edit (editgroup_id, ident_id, rev_id) VALUES - ($2, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($3, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.work_type) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) .get_result(&conn) .unwrap(); @@ -741,14 +745,14 @@ 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) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + "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) 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 - ($10, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($11, (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) @@ -759,8 +763,8 @@ impl Api for Server { .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::Json>, _>(body.extra) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) - //XXX: extra_json .get_result(&conn) .unwrap(); let edit = &edit; diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs index 1ffbee90..01db031f 100644 --- a/rust/tests/test_api_server.rs +++ b/rust/tests/test_api_server.rs @@ -203,7 +203,8 @@ fn test_post_file() { "releases": [ "f1f046a3-45c9-4b99-4444-000000000001", "f1f046a3-45c9-4b99-4444-000000000002" - ] + ], + "extra": { "source": "speculation" } }"#, &router, ), @@ -257,7 +258,8 @@ fn test_post_release() { "contrib_type": "author" },{ "creator_stub": "shorter" - }] + }], + "extra": { "source": "speculation" } }"#, &router, ), @@ -275,7 +277,10 @@ fn test_post_work() { "http://localhost:9411/v0/work", headers.clone(), // TODO: target_work_id - r#"{"work_type": "journal-article"}"#, + r#"{ + "work_type": "journal-article", + "extra": { "source": "speculation" } + }"#, &router, ), status::Created, |