diff options
Diffstat (limited to 'rust/src')
-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 |
3 files changed, 123 insertions, 32 deletions
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>, } } |