Skip to content

Commit

Permalink
Merge branch 'release/v0.9.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Dec 5, 2022
2 parents 02ebda1 + 80c4616 commit cd7a8ea
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions thoth-api-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-api-server"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions thoth-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-api"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Publisher> {
Expand Down
20 changes: 20 additions & 0 deletions thoth-api/src/model/work/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -78,6 +79,25 @@ impl Work {
Err(ThothError::ChapterIsbnError)
}
}

pub fn children(&self, db: &crate::db::PgPool) -> ThothResult<Vec<Work>> {
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 {
Expand Down
115 changes: 115 additions & 0 deletions thoth-api/src/model/work/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,45 @@ impl WorkWithRelations {
}
}

impl From<Work> 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
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion thoth-app-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-app-server"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions thoth-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-app"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion thoth-app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions thoth-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-client"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion thoth-errors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "thoth-errors"
version = "0.9.3"
version = "0.9.4"
authors = ["Javier Arias <[email protected]>", "Ross Higman <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
Loading

0 comments on commit cd7a8ea

Please sign in to comment.