From 6f7b6031a10f56823391143dbdb2dbe9d156a05a Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Fri, 2 Dec 2022 10:32:12 +0000 Subject: [PATCH 1/6] Fix typo --- thoth-export-server/src/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thoth-export-server/src/data.rs b/thoth-export-server/src/data.rs index 94cb626a1..87a7658a0 100644 --- a/thoth-export-server/src/data.rs +++ b/thoth-export-server/src/data.rs @@ -39,7 +39,7 @@ lazy_static! { }, Specification { id: "onix_3.0::overdrive", - name: "Google Books ONIX 3.0", + name: "OverDrive ONIX 3.0", format: concat!(env!("THOTH_EXPORT_API"), "/formats/onix_3.0"), accepted_by: vec![concat!(env!("THOTH_EXPORT_API"), "/platforms/overdrive"),], }, From 364071872e20d7446571057d86f55711c405ead6 Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Mon, 5 Dec 2022 11:20:28 +0000 Subject: [PATCH 2/6] Implement conversion from Work to PatchWork --- thoth-api/src/model/work/mod.rs | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/thoth-api/src/model/work/mod.rs b/thoth-api/src/model/work/mod.rs index a317a9136..9e4a9fc95 100644 --- a/thoth-api/src/model/work/mod.rs +++ b/thoth-api/src/model/work/mod.rs @@ -347,6 +347,45 @@ impl WorkWithRelations { } } +impl From for PatchWork { + fn from(w: Work) -> Self { + Self { + work_id: w.work_id, + work_type: w.work_type, + work_status: w.work_status, + full_title: w.full_title, + title: w.title, + subtitle: w.subtitle, + reference: w.reference, + edition: w.edition, + imprint_id: w.imprint_id, + doi: w.doi, + publication_date: w.publication_date, + place: w.place, + page_count: w.page_count, + page_breakdown: w.page_breakdown, + image_count: w.image_count, + table_count: w.table_count, + audio_count: w.audio_count, + video_count: w.video_count, + license: w.license, + copyright_holder: w.copyright_holder, + landing_page: w.landing_page, + lccn: w.lccn, + oclc: w.oclc, + short_abstract: w.short_abstract, + long_abstract: w.long_abstract, + general_note: w.general_note, + toc: w.toc, + cover_url: w.cover_url, + cover_caption: w.cover_caption, + first_page: w.first_page, + last_page: w.last_page, + page_interval: w.page_interval, + } + } +} + impl Default for WorkType { fn default() -> WorkType { WorkType::Monograph @@ -658,5 +697,81 @@ fn test_workfield_fromstr() { assert!(WorkField::from_str("Publisher").is_err()); } +#[test] +fn test_work_into_patchwork() { + use std::str::FromStr; + + let work = Work { + work_id: Uuid::parse_str("00000000-0000-0000-AAAA-000000000001").unwrap(), + work_type: WorkType::Monograph, + work_status: WorkStatus::Active, + full_title: "Some title".to_string(), + title: "Some title".to_string(), + subtitle: None, + reference: None, + edition: Some(1), + imprint_id: Uuid::parse_str("00000000-0000-0000-BBBB-000000000002").unwrap(), + doi: Some(Doi::from_str("https://doi.org/10.00001/BOOK.0001").unwrap()), + publication_date: Some(chrono::NaiveDate::from_ymd(1999, 12, 31)), + place: Some("León, Spain".to_string()), + page_count: Some(123), + page_breakdown: None, + image_count: Some(22), + table_count: Some(3), + audio_count: None, + video_count: None, + license: Some("https://creativecommons.org/licenses/by/4.0/".to_string()), + copyright_holder: Some("Author1".to_string()), + landing_page: Some("https://book.page".to_string()), + lccn: None, + oclc: None, + short_abstract: Some("Short abstract".to_string()), + long_abstract: Some("Long abstract".to_string()), + general_note: None, + toc: None, + cover_url: Some("https://book.cover/image".to_string()), + cover_caption: None, + created_at: Default::default(), + updated_at: Default::default(), + first_page: None, + last_page: None, + page_interval: None, + }; + let patch_work: PatchWork = work.clone().into(); + + assert_eq!(work.work_id, patch_work.work_id); + assert_eq!(work.work_type, patch_work.work_type); + assert_eq!(work.work_status, patch_work.work_status); + assert_eq!(work.full_title, patch_work.full_title); + assert_eq!(work.title, patch_work.title); + assert_eq!(work.subtitle, patch_work.subtitle); + assert_eq!(work.reference, patch_work.reference); + assert_eq!(work.edition, patch_work.edition); + assert_eq!(work.imprint_id, patch_work.imprint_id); + assert_eq!(work.doi, patch_work.doi); + assert_eq!(work.publication_date, patch_work.publication_date); + assert_eq!(work.place, patch_work.place); + assert_eq!(work.page_count, patch_work.page_count); + assert_eq!(work.page_breakdown, patch_work.page_breakdown); + assert_eq!(work.image_count, patch_work.image_count); + assert_eq!(work.table_count, patch_work.table_count); + assert_eq!(work.audio_count, patch_work.audio_count); + assert_eq!(work.video_count, patch_work.video_count); + assert_eq!(work.license, patch_work.license); + assert_eq!(work.copyright_holder, patch_work.copyright_holder); + assert_eq!(work.landing_page, patch_work.landing_page); + assert_eq!(work.lccn, patch_work.lccn); + assert_eq!(work.oclc, patch_work.oclc); + assert_eq!(work.short_abstract, patch_work.short_abstract); + assert_eq!(work.long_abstract, patch_work.long_abstract); + assert_eq!(work.general_note, patch_work.general_note); + assert_eq!(work.toc, patch_work.toc); + assert_eq!(work.cover_url, patch_work.cover_url); + assert_eq!(work.cover_caption, patch_work.cover_caption); + assert_eq!(work.first_page, patch_work.first_page); + assert_eq!(work.last_page, patch_work.last_page); + assert_eq!(work.page_interval, patch_work.page_interval); +} + #[cfg(feature = "backend")] pub mod crud; From d7dd838465d5dc4c6d2a755c780c29c8dc4bd867 Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Mon, 5 Dec 2022 11:20:46 +0000 Subject: [PATCH 3/6] Add method to gather a work's children --- thoth-api/src/model/work/crud.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/thoth-api/src/model/work/crud.rs b/thoth-api/src/model/work/crud.rs index 79a4a0791..7220b47f8 100644 --- a/thoth-api/src/model/work/crud.rs +++ b/thoth-api/src/model/work/crud.rs @@ -3,6 +3,7 @@ use super::{ WorkType, }; use crate::graphql::utils::Direction; +use crate::model::work_relation::{RelationType, WorkRelation, WorkRelationOrderBy}; use crate::model::{Crud, DbInsert, Doi, HistoryEntry}; use crate::schema::{work, work_history}; use crate::{crud_methods, db_insert}; @@ -78,6 +79,25 @@ impl Work { Err(ThothError::ChapterIsbnError) } } + + pub fn children(&self, db: &crate::db::PgPool) -> ThothResult> { + WorkRelation::all( + db, + 99999, + 0, + None, + WorkRelationOrderBy::default(), + vec![], + Some(self.work_id), + None, + vec![RelationType::HasChild], + None, + ) + .unwrap_or_default() + .into_iter() + .map(|relation| Work::from_id(db, &relation.related_work_id)) + .collect() + } } impl Crud for Work { From 3e62bdab26757df25e4c700fe6901852f54b545f Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Mon, 5 Dec 2022 11:21:57 +0000 Subject: [PATCH 4/6] Fix #414 --- thoth-api/src/graphql/model.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/thoth-api/src/graphql/model.rs b/thoth-api/src/graphql/model.rs index 7f63f0009..d024450a8 100644 --- a/thoth-api/src/graphql/model.rs +++ b/thoth-api/src/graphql/model.rs @@ -1559,8 +1559,24 @@ impl MutationRoot { } let account_id = context.token.jwt.as_ref().unwrap().account_id(&context.db); - work.update(&context.db, &data, &account_id) - .map_err(|e| e.into()) + // update the work and, if it succeeds, synchronise its children statuses and pub. date + match work.update(&context.db, &data, &account_id) { + Ok(w) => { + // update chapters if their pub. data or work_status doesn't match the parent's + for child in work.children(&context.db)? { + if child.publication_date != w.publication_date + || child.work_status != w.work_status + { + let mut data: PatchWork = child.clone().into(); + data.publication_date = w.publication_date; + data.work_status = w.work_status.clone(); + child.update(&context.db, &data, &account_id)?; + } + } + Ok(w) + } + Err(e) => Err(e.into()), + } } fn update_publisher(context: &Context, data: PatchPublisher) -> FieldResult { From 44092a454d904c47a7b20101fa78b3f5a4c1517e Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Mon, 5 Dec 2022 12:56:02 +0000 Subject: [PATCH 5/6] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1f21a684..c798885aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [[0.9.4]](https://github.com/thoth-pub/thoth/releases/tag/v0.9.4) - 2022-12-05 +### Added + - [#414](https://github.com/thoth-pub/thoth/pull/414) - Synchronise chapters' `work_status` and `publication_date` with parent's upon parent's update + ## [[0.9.3]](https://github.com/thoth-pub/thoth/releases/tag/v0.9.3) - 2022-11-21 ### Added - [#456](https://github.com/thoth-pub/thoth/pull/456) - Implement JSON output format From 80c4616de6bbb7a73cc3d274d1096898c403ee9f Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Mon, 5 Dec 2022 13:17:10 +0000 Subject: [PATCH 6/6] Bump v0.9.4 --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 12 ++++++------ thoth-api-server/Cargo.toml | 6 +++--- thoth-api/Cargo.toml | 4 ++-- thoth-app-server/Cargo.toml | 2 +- thoth-app/Cargo.toml | 6 +++--- thoth-app/manifest.json | 2 +- thoth-client/Cargo.toml | 6 +++--- thoth-errors/Cargo.toml | 2 +- thoth-export-server/Cargo.toml | 8 ++++---- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d29b3ff9c..9c2177daf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3822,7 +3822,7 @@ dependencies = [ [[package]] name = "thoth" -version = "0.9.3" +version = "0.9.4" dependencies = [ "cargo-husky", "clap", @@ -3837,7 +3837,7 @@ dependencies = [ [[package]] name = "thoth-api" -version = "0.9.3" +version = "0.9.4" dependencies = [ "actix-web", "argon2rs", @@ -3866,7 +3866,7 @@ dependencies = [ [[package]] name = "thoth-api-server" -version = "0.9.3" +version = "0.9.4" dependencies = [ "actix-cors", "actix-identity", @@ -3881,7 +3881,7 @@ dependencies = [ [[package]] name = "thoth-app" -version = "0.9.3" +version = "0.9.4" dependencies = [ "anyhow", "chrono", @@ -3909,7 +3909,7 @@ dependencies = [ [[package]] name = "thoth-app-server" -version = "0.9.3" +version = "0.9.4" dependencies = [ "actix-cors", "actix-web", @@ -3918,7 +3918,7 @@ dependencies = [ [[package]] name = "thoth-client" -version = "0.9.3" +version = "0.9.4" dependencies = [ "chrono", "graphql_client", @@ -3932,7 +3932,7 @@ dependencies = [ [[package]] name = "thoth-errors" -version = "0.9.3" +version = "0.9.4" dependencies = [ "actix-web", "csv", @@ -3951,7 +3951,7 @@ dependencies = [ [[package]] name = "thoth-export-server" -version = "0.9.3" +version = "0.9.4" dependencies = [ "actix-cors", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index f3c54a514..6dd757347 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" @@ -16,11 +16,11 @@ maintenance = { status = "actively-developed" } members = ["thoth-api", "thoth-api-server", "thoth-app", "thoth-app-server", "thoth-client", "thoth-errors", "thoth-export-server"] [dependencies] -thoth-api = { version = "0.9.3", path = "thoth-api", features = ["backend"] } -thoth-api-server = { version = "0.9.3", path = "thoth-api-server" } -thoth-app-server = { version = "0.9.3", path = "thoth-app-server" } -thoth-errors = { version = "0.9.3", path = "thoth-errors" } -thoth-export-server = { version = "0.9.3", path = "thoth-export-server" } +thoth-api = { version = "0.9.4", path = "thoth-api", features = ["backend"] } +thoth-api-server = { version = "0.9.4", path = "thoth-api-server" } +thoth-app-server = { version = "0.9.4", path = "thoth-app-server" } +thoth-errors = { version = "0.9.4", path = "thoth-errors" } +thoth-export-server = { version = "0.9.4", path = "thoth-export-server" } clap = "2.33.3" dialoguer = "0.7.1" dotenv = "0.15.0" diff --git a/thoth-api-server/Cargo.toml b/thoth-api-server/Cargo.toml index 7b6a63506..b2c240ee3 100644 --- a/thoth-api-server/Cargo.toml +++ b/thoth-api-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-api-server" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" @@ -9,8 +9,8 @@ repository = "https://github.com/thoth-pub/thoth" readme = "README.md" [dependencies] -thoth-api = { version = "0.9.3", path = "../thoth-api", features = ["backend"] } -thoth-errors = { version = "0.9.3", path = "../thoth-errors" } +thoth-api = { version = "0.9.4", path = "../thoth-api", features = ["backend"] } +thoth-errors = { version = "0.9.4", path = "../thoth-errors" } actix-web = "4.0.1" actix-cors = "0.6.0" actix-identity = "0.4.0" diff --git a/thoth-api/Cargo.toml b/thoth-api/Cargo.toml index 1bf92203c..b3cfe0b81 100644 --- a/thoth-api/Cargo.toml +++ b/thoth-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-api" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" @@ -16,7 +16,7 @@ maintenance = { status = "actively-developed" } backend = ["diesel", "diesel-derive-enum", "diesel_migrations", "futures", "actix-web"] [dependencies] -thoth-errors = { version = "0.9.3", path = "../thoth-errors" } +thoth-errors = { version = "0.9.4", path = "../thoth-errors" } actix-web = { version = "4.0.1", optional = true } argon2rs = "0.2.5" isbn2 = "0.4.0" diff --git a/thoth-app-server/Cargo.toml b/thoth-app-server/Cargo.toml index 79376070e..06fcbbce9 100644 --- a/thoth-app-server/Cargo.toml +++ b/thoth-app-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-app-server" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" diff --git a/thoth-app/Cargo.toml b/thoth-app/Cargo.toml index 51e6c5073..a7df30bbd 100644 --- a/thoth-app/Cargo.toml +++ b/thoth-app/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-app" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" @@ -38,5 +38,5 @@ serde = { version = "1.0.115", features = ["derive"] } serde_json = "1.0" url = "2.1.1" uuid = { version = "0.7", features = ["serde", "v4"] } -thoth-api = { version = "0.9.3", path = "../thoth-api" } -thoth-errors = { version = "0.9.3", path = "../thoth-errors" } +thoth-api = { version = "0.9.4", path = "../thoth-api" } +thoth-errors = { version = "0.9.4", path = "../thoth-errors" } diff --git a/thoth-app/manifest.json b/thoth-app/manifest.json index 64cd44914..898f54d2c 100644 --- a/thoth-app/manifest.json +++ b/thoth-app/manifest.json @@ -9,7 +9,7 @@ "start_url": "/?homescreen=1", "background_color": "#ffffff", "theme_color": "#ffdd57", - "version": "0.9.3", + "version": "0.9.4", "icons": [ { "src": "\/android-icon-36x36.png", diff --git a/thoth-client/Cargo.toml b/thoth-client/Cargo.toml index cd0809d85..93bf56423 100644 --- a/thoth-client/Cargo.toml +++ b/thoth-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-client" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" @@ -9,8 +9,8 @@ repository = "https://github.com/thoth-pub/thoth" readme = "README.md" [dependencies] -thoth-api = {version = "0.9.3", path = "../thoth-api" } -thoth-errors = {version = "0.9.3", path = "../thoth-errors" } +thoth-api = {version = "0.9.4", path = "../thoth-api" } +thoth-errors = {version = "0.9.4", path = "../thoth-errors" } graphql_client = "0.11.0" chrono = { version = "0.4", features = ["serde"] } reqwest = { version = "0.11", features = ["json"] } diff --git a/thoth-errors/Cargo.toml b/thoth-errors/Cargo.toml index b5be9d10c..77b7559f5 100644 --- a/thoth-errors/Cargo.toml +++ b/thoth-errors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-errors" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" diff --git a/thoth-export-server/Cargo.toml b/thoth-export-server/Cargo.toml index e1cee293e..ca55b88a5 100644 --- a/thoth-export-server/Cargo.toml +++ b/thoth-export-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thoth-export-server" -version = "0.9.3" +version = "0.9.4" authors = ["Javier Arias ", "Ross Higman "] edition = "2018" license = "Apache-2.0" @@ -9,9 +9,9 @@ repository = "https://github.com/thoth-pub/thoth" readme = "README.md" [dependencies] -thoth-api = { version = "0.9.3", path = "../thoth-api" } -thoth-errors = { version = "0.9.3", path = "../thoth-errors" } -thoth-client = { version = "0.9.3", path = "../thoth-client" } +thoth-api = { version = "0.9.4", path = "../thoth-api" } +thoth-errors = { version = "0.9.4", path = "../thoth-errors" } +thoth-client = { version = "0.9.4", path = "../thoth-client" } actix-web = "4.0.1" actix-cors = "0.6.0" chrono = { version = "0.4", features = ["serde"] }