diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-25 19:42:39 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-25 19:42:39 -0700 |
commit | f3523b1d900e19911bf0041ac1c75877b0bfc943 (patch) | |
tree | 4286885906e7758c4cf6625a369d17b96c4d8e62 | |
parent | f653c4070a076306825501ddbc27c0634d0e1438 (diff) | |
download | fatcat-f3523b1d900e19911bf0041ac1c75877b0bfc943.tar.gz fatcat-f3523b1d900e19911bf0041ac1c75877b0bfc943.zip |
return all edits for an editgroup GET
-rw-r--r-- | rust/fatcat-api/README.md | 2 | ||||
-rw-r--r-- | rust/fatcat-api/api.yaml | 8 | ||||
-rw-r--r-- | rust/fatcat-api/api/swagger.yaml | 31 | ||||
-rw-r--r-- | rust/fatcat-api/src/models.rs | 20 | ||||
-rw-r--r-- | rust/fatcat-openapi2.yml | 8 | ||||
-rw-r--r-- | rust/migrations/2018-05-12-001226_init/up.sql | 20 | ||||
-rw-r--r-- | rust/src/api_server.rs | 133 | ||||
-rw-r--r-- | rust/src/database_models.rs | 2 | ||||
-rw-r--r-- | rust/src/database_schema.rs | 20 | ||||
-rw-r--r-- | rust/tests/test_api_server.rs | 10 |
10 files changed, 202 insertions, 52 deletions
diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md index 364f7271..146758fb 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-26T01:47:28.955Z +- Build date: 2018-05-26T02:33:00.709Z 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 cfce24d7..146c11dd 100644 --- a/rust/fatcat-api/api.yaml +++ b/rust/fatcat-api/api.yaml @@ -50,6 +50,10 @@ x-entity-edit-props: &ENTITYEDITPROPS type: integer example: 42 format: int64 + redirect_ident: + type: string + example: "f1f046a3-45c9-4b99-adce-000000000002" + #format: uuid editgroup_id: type: integer example: 16 @@ -174,6 +178,10 @@ definitions: type: string entity_edit: type: object + required: + - edit_id + - ident + - editgroup_id properties: <<: *ENTITYEDITPROPS editor: diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml index 506cb9db..db7b0e03 100644 --- a/rust/fatcat-api/api/swagger.yaml +++ b/rust/fatcat-api/api/swagger.yaml @@ -1300,6 +1300,10 @@ definitions: upperCaseName: "WORK_ENTITY" entity_edit: type: "object" + required: + - "edit_id" + - "editgroup_id" + - "ident" properties: extra: type: "object" @@ -1307,6 +1311,9 @@ definitions: type: "integer" format: "int64" example: 16 + redirect_ident: + type: "string" + example: "f1f046a3-45c9-4b99-adce-000000000002" revision: type: "integer" format: "int64" @@ -1322,6 +1329,7 @@ definitions: ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 upperCaseName: "ENTITY_EDIT" @@ -1360,55 +1368,65 @@ definitions: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 creators: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 files: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 containers: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 releases: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 description: "description" @@ -1480,55 +1498,65 @@ definitions: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 creators: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 files: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 containers: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 releases: - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 - ident: "f1f046a3-45c9-4b99-adce-000000000001" extra: "{}" edit_id: 847 + redirect_ident: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: 16 revision: 42 upperCaseName: "EDITGROUP_EDITS" @@ -1585,6 +1613,9 @@ x-entity-edit-props: type: "integer" example: 42 format: "int64" + redirect_ident: + type: "string" + example: "f1f046a3-45c9-4b99-adce-000000000002" editgroup_id: type: "integer" example: 16 diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index e3ce33c3..68242058 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -285,30 +285,32 @@ pub struct EntityEdit { pub extra: Option<serde_json::Value>, #[serde(rename = "editgroup_id")] + pub editgroup_id: i64, + + #[serde(rename = "redirect_ident")] #[serde(skip_serializing_if = "Option::is_none")] - pub editgroup_id: Option<i64>, + pub redirect_ident: Option<String>, #[serde(rename = "revision")] #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option<i64>, #[serde(rename = "ident")] - #[serde(skip_serializing_if = "Option::is_none")] - pub ident: Option<String>, + pub ident: String, #[serde(rename = "edit_id")] - #[serde(skip_serializing_if = "Option::is_none")] - pub edit_id: Option<i64>, + pub edit_id: i64, } impl EntityEdit { - pub fn new() -> EntityEdit { + pub fn new(editgroup_id: i64, ident: String, edit_id: i64) -> EntityEdit { EntityEdit { extra: None, - editgroup_id: None, + editgroup_id: editgroup_id, + redirect_ident: None, revision: None, - ident: None, - edit_id: None, + ident: ident, + edit_id: edit_id, } } } diff --git a/rust/fatcat-openapi2.yml b/rust/fatcat-openapi2.yml index cfce24d7..146c11dd 100644 --- a/rust/fatcat-openapi2.yml +++ b/rust/fatcat-openapi2.yml @@ -50,6 +50,10 @@ x-entity-edit-props: &ENTITYEDITPROPS type: integer example: 42 format: int64 + redirect_ident: + type: string + example: "f1f046a3-45c9-4b99-adce-000000000002" + #format: uuid editgroup_id: type: integer example: 16 @@ -174,6 +178,10 @@ definitions: type: string entity_edit: type: object + required: + - edit_id + - ident + - editgroup_id properties: <<: *ENTITYEDITPROPS editor: diff --git a/rust/migrations/2018-05-12-001226_init/up.sql b/rust/migrations/2018-05-12-001226_init/up.sql index 1fbd7c09..1f366f90 100644 --- a/rust/migrations/2018-05-12-001226_init/up.sql +++ b/rust/migrations/2018-05-12-001226_init/up.sql @@ -54,11 +54,11 @@ CREATE TABLE creator_ident ( CREATE TABLE creator_edit ( id BIGSERIAL PRIMARY KEY, - extra_json JSON, + editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL, ident_id UUID REFERENCES creator_ident(id) NOT NULL, rev_id BIGINT REFERENCES creator_rev(id), redirect_id UUID REFERENCES creator_ident(id), - editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL + extra_json JSON ); -------------------- Containers -------------------------------------------- @@ -82,11 +82,11 @@ CREATE TABLE container_ident ( CREATE TABLE container_edit ( id BIGSERIAL PRIMARY KEY, - extra_json JSON, + editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL, ident_id UUID REFERENCES container_ident(id) NOT NULL, rev_id BIGINT REFERENCES container_rev(id), redirect_id UUID REFERENCES container_ident(id), - editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL + extra_json JSON ); -------------------- Files ------------------------------------------------- @@ -108,11 +108,11 @@ CREATE TABLE file_ident ( CREATE TABLE file_edit ( id BIGSERIAL PRIMARY KEY, - extra_json JSON, + editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL, ident_id UUID REFERENCES file_ident(id) NOT NULL, rev_id BIGINT REFERENCES file_rev(id), redirect_id UUID REFERENCES file_ident(id), - editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL + extra_json JSON ); -------------------- Release ----------------------------------------------- @@ -143,11 +143,11 @@ CREATE TABLE release_ident ( CREATE TABLE release_edit ( id BIGSERIAL PRIMARY KEY, - extra_json JSON, + editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL, ident_id UUID REFERENCES release_ident(id) NOT NULL, rev_id BIGINT REFERENCES release_rev(id), redirect_id UUID REFERENCES release_ident(id), - editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL + extra_json JSON ); -------------------- Works -------------------------------------------------- @@ -169,11 +169,11 @@ CREATE TABLE work_ident ( CREATE TABLE work_edit ( id BIGSERIAL PRIMARY KEY, - extra_json JSON, + editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL, ident_id UUID REFERENCES work_ident(id) NOT NULL, rev_id BIGINT REFERENCES work_rev(id), redirect_id UUID REFERENCES work_ident(id), - editgroup_id BIGINT REFERENCES editgroup(id) NOT NULL + extra_json JSON ); diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index c9c8e754..8311896f 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -4,9 +4,10 @@ use ConnectionPool; use api_helpers::*; use chrono; use database_models::*; -use database_schema::{changelog, container_ident, container_rev, creator_ident, creator_rev, - editgroup, editor, file_ident, file_release, file_rev, release_contrib, - release_ident, release_ref, release_rev, work_ident, work_rev}; +use database_schema::{changelog, container_edit, container_ident, container_rev, creator_edit, + creator_ident, creator_rev, editgroup, editor, file_edit, file_ident, + file_release, file_rev, release_contrib, release_edit, release_ident, + release_ref, release_rev, work_edit, work_ident, work_rev}; use diesel::prelude::*; use diesel::{self, insert_into}; use errors::*; @@ -342,7 +343,8 @@ impl Server { let entity = ReleaseEntity { title: rev.title, release_type: rev.release_type, - date: rev.date.map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), + 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 +407,8 @@ impl Server { let entity = ReleaseEntity { title: rev.title, release_type: rev.release_type, - date: rev.date.map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), + 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, @@ -429,11 +432,94 @@ impl Server { let row: EditgroupRow = editgroup::table.find(id as i64).first(&conn)?; + let edits = EditgroupEdits { + containers: Some( + container_edit::table + .filter(container_edit::editgroup_id.eq(id)) + .get_results(&conn) + .unwrap() + .iter() + .map(|e: &ContainerEditRow| EntityEdit { + edit_id: e.id, + editgroup_id: e.editgroup_id, + revision: e.rev_id, + redirect_ident: e.redirect_id.map(|v| v.to_string()), + ident: e.ident_id.to_string(), + extra: e.extra_json.clone(), + }) + .collect(), + ), + creators: Some( + creator_edit::table + .filter(creator_edit::editgroup_id.eq(id)) + .get_results(&conn) + .unwrap() + .iter() + .map(|e: &CreatorEditRow| EntityEdit { + edit_id: e.id, + editgroup_id: e.editgroup_id, + revision: e.rev_id, + redirect_ident: e.redirect_id.map(|v| v.to_string()), + ident: e.ident_id.to_string(), + extra: e.extra_json.clone(), + }) + .collect(), + ), + files: Some( + file_edit::table + .filter(file_edit::editgroup_id.eq(id)) + .get_results(&conn) + .unwrap() + .iter() + .map(|e: &FileEditRow| EntityEdit { + edit_id: e.id, + editgroup_id: e.editgroup_id, + revision: e.rev_id, + redirect_ident: e.redirect_id.map(|v| v.to_string()), + ident: e.ident_id.to_string(), + extra: e.extra_json.clone(), + }) + .collect(), + ), + releases: Some( + release_edit::table + .filter(release_edit::editgroup_id.eq(id)) + .get_results(&conn) + .unwrap() + .iter() + .map(|e: &ReleaseEditRow| EntityEdit { + edit_id: e.id, + editgroup_id: e.editgroup_id, + revision: e.rev_id, + redirect_ident: e.redirect_id.map(|v| v.to_string()), + ident: e.ident_id.to_string(), + extra: e.extra_json.clone(), + }) + .collect(), + ), + works: Some( + work_edit::table + .filter(work_edit::editgroup_id.eq(id)) + .get_results(&conn) + .unwrap() + .iter() + .map(|e: &WorkEditRow| EntityEdit { + edit_id: e.id, + editgroup_id: e.editgroup_id, + revision: e.rev_id, + redirect_ident: e.redirect_id.map(|v| v.to_string()), + ident: e.ident_id.to_string(), + extra: e.extra_json.clone(), + }) + .collect(), + ), + }; + let eg = Editgroup { id: Some(row.id), editor_id: row.editor_id, description: row.description, - edits: None, + edits: Some(edits), extra: row.extra_json, }; Ok(Some(eg)) @@ -565,10 +651,11 @@ impl Api for Server { let edit = &edit; let entity_edit = EntityEdit { - editgroup_id: Some(edit.editgroup_id), + editgroup_id: edit.editgroup_id, revision: Some(edit.rev_id.unwrap()), - ident: Some(edit.ident_id.to_string()), - edit_id: Some(edit.id), + redirect_ident: None, + ident: edit.ident_id.to_string(), + edit_id: edit.id, extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(ContainerPostResponse::CreatedEntity( @@ -607,10 +694,11 @@ impl Api for Server { let edit = &edit; let entity_edit = EntityEdit { - editgroup_id: Some(edit.editgroup_id), + editgroup_id: edit.editgroup_id, revision: Some(edit.rev_id.unwrap()), - ident: Some(edit.ident_id.to_string()), - edit_id: Some(edit.id), + redirect_ident: None, + ident: edit.ident_id.to_string(), + edit_id: edit.id, extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(CreatorPostResponse::CreatedEntity( @@ -673,10 +761,11 @@ impl Api for Server { }; let entity_edit = EntityEdit { - editgroup_id: Some(edit.editgroup_id), + editgroup_id: edit.editgroup_id, revision: Some(edit.rev_id.unwrap()), - ident: Some(edit.ident_id.to_string()), - edit_id: Some(edit.id), + redirect_ident: None, + ident: edit.ident_id.to_string(), + edit_id: edit.id, extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(FilePostResponse::CreatedEntity( @@ -715,10 +804,11 @@ impl Api for Server { let edit = &edit; let entity_edit = EntityEdit { - editgroup_id: Some(edit.editgroup_id), + editgroup_id: edit.editgroup_id, revision: Some(edit.rev_id.unwrap()), - ident: Some(edit.ident_id.to_string()), - edit_id: Some(edit.id), + redirect_ident: None, + ident: edit.ident_id.to_string(), + edit_id: edit.id, extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(WorkPostResponse::CreatedEntity( @@ -823,10 +913,11 @@ impl Api for Server { }; let entity_edit = EntityEdit { - editgroup_id: Some(edit.editgroup_id), + editgroup_id: edit.editgroup_id, revision: Some(edit.rev_id.unwrap()), - ident: Some(edit.ident_id.to_string()), - edit_id: Some(edit.id), + redirect_ident: None, + ident: edit.ident_id.to_string(), + edit_id: edit.id, extra: edit.extra_json.clone(), }; Box::new(futures::done(Ok(ReleasePostResponse::CreatedEntity( diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 2b205fe7..b27bca3f 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -36,10 +36,10 @@ macro_rules! entity_structs { #[table_name = $edit_table] pub struct $edit_struct { pub id: i64, + pub editgroup_id: i64, pub ident_id: Uuid, pub rev_id: Option<i64>, pub redirect_id: Option<Uuid>, - pub editgroup_id: i64, pub extra_json: Option<serde_json::Value>, } diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 3adbd63a..7d8ff4e1 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -9,11 +9,11 @@ table! { table! { container_edit (id) { id -> Int8, - extra_json -> Nullable<Json>, + editgroup_id -> Int8, ident_id -> Uuid, rev_id -> Nullable<Int8>, redirect_id -> Nullable<Uuid>, - editgroup_id -> Int8, + extra_json -> Nullable<Json>, } } @@ -39,11 +39,11 @@ table! { table! { creator_edit (id) { id -> Int8, - extra_json -> Nullable<Json>, + editgroup_id -> Int8, ident_id -> Uuid, rev_id -> Nullable<Int8>, redirect_id -> Nullable<Uuid>, - editgroup_id -> Int8, + extra_json -> Nullable<Json>, } } @@ -86,11 +86,11 @@ table! { table! { file_edit (id) { id -> Int8, - extra_json -> Nullable<Json>, + editgroup_id -> Int8, ident_id -> Uuid, rev_id -> Nullable<Int8>, redirect_id -> Nullable<Uuid>, - editgroup_id -> Int8, + extra_json -> Nullable<Json>, } } @@ -134,11 +134,11 @@ table! { table! { release_edit (id) { id -> Int8, - extra_json -> Nullable<Json>, + editgroup_id -> Int8, ident_id -> Uuid, rev_id -> Nullable<Int8>, redirect_id -> Nullable<Uuid>, - editgroup_id -> Int8, + extra_json -> Nullable<Json>, } } @@ -180,11 +180,11 @@ table! { table! { work_edit (id) { id -> Int8, - extra_json -> Nullable<Json>, + editgroup_id -> Int8, ident_id -> Uuid, rev_id -> Nullable<Int8>, redirect_id -> Nullable<Uuid>, - editgroup_id -> Int8, + extra_json -> Nullable<Json>, } } diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs index 01db031f..8eedfa2f 100644 --- a/rust/tests/test_api_server.rs +++ b/rust/tests/test_api_server.rs @@ -342,6 +342,16 @@ fn test_accept_editgroup() { assert_eq!(c, 2); check_response( + request::get( + &format!("http://localhost:9411/v0/editgroup/{}", editgroup_id), + headers.clone(), + &router, + ), + status::Ok, + None, + ); + + check_response( request::post( &format!("http://localhost:9411/v0/editgroup/{}/accept", editgroup_id), headers.clone(), |