From 11109787d2a1dd3b3236be689f75d56a0a12238a Mon Sep 17 00:00:00 2001 From: Brendan O'Connell Date: Fri, 19 Apr 2024 15:14:20 +0200 Subject: [PATCH] Fixed migration, fixed formatting and clippy errors --- thoth-api/migrations/v0.12.3/up.sql | 3 +-- thoth-api/src/graphql/model.rs | 2 +- thoth-api/src/model/work/crud.rs | 3 ++- thoth-api/src/model/work/mod.rs | 8 +++----- thoth-app/src/component/new_work.rs | 12 +++++++++--- thoth-app/src/component/work.rs | 12 +++++++++--- thoth-errors/src/lib.rs | 4 +--- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/thoth-api/migrations/v0.12.3/up.sql b/thoth-api/migrations/v0.12.3/up.sql index c23692157..7001a993b 100644 --- a/thoth-api/migrations/v0.12.3/up.sql +++ b/thoth-api/migrations/v0.12.3/up.sql @@ -14,6 +14,5 @@ UPDATE work ALTER TABLE work ADD CONSTRAINT work_withdrawn_date_check CHECK - (((work_status = 'withdrawn-from-sale' OR work_status = 'out-of-print') - AND withdrawn_date IS NOT NULL) + ((work_status = 'withdrawn-from-sale' OR work_status = 'out-of-print') OR (work_status NOT IN ('withdrawn-from-sale', 'out-of-print') AND withdrawn_date IS NULL)); \ No newline at end of file diff --git a/thoth-api/src/graphql/model.rs b/thoth-api/src/graphql/model.rs index 5c8c4a6ee..843875d86 100644 --- a/thoth-api/src/graphql/model.rs +++ b/thoth-api/src/graphql/model.rs @@ -1709,7 +1709,7 @@ impl MutationRoot { // 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 + // update chapters if their pub. data, withdrawn_date 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 diff --git a/thoth-api/src/model/work/crud.rs b/thoth-api/src/model/work/crud.rs index 6d5875777..a8f94a738 100644 --- a/thoth-api/src/model/work/crud.rs +++ b/thoth-api/src/model/work/crud.rs @@ -1,5 +1,6 @@ use super::{ - NewWork, NewWorkHistory, PatchWork, WorkProperties, Work, WorkField, WorkHistory, WorkOrderBy, WorkStatus, WorkType + NewWork, NewWorkHistory, PatchWork, Work, WorkField, WorkHistory, WorkOrderBy, WorkProperties, + WorkStatus, WorkType, }; use crate::graphql::model::TimeExpression; use crate::graphql::utils::{Direction, Expression}; diff --git a/thoth-api/src/model/work/mod.rs b/thoth-api/src/model/work/mod.rs index 05eb6081d..1fac5a030 100644 --- a/thoth-api/src/model/work/mod.rs +++ b/thoth-api/src/model/work/mod.rs @@ -1,9 +1,9 @@ use chrono::naive::NaiveDate; use serde::{Deserialize, Serialize}; -use thoth_errors::{ThothError, ThothResult}; use std::fmt; use strum::Display; use strum::EnumString; +use thoth_errors::{ThothError, ThothResult}; use uuid::Uuid; use crate::graphql::utils::Direction; @@ -355,10 +355,8 @@ pub trait WorkProperties { } fn withdrawn_date_error(&self) -> ThothResult<()> { - if self.is_not_withdrawn_out_of_print() { - if self.has_withdrawn_date() { - return Err(ThothError::WithdrawnDateError) - } + if self.is_not_withdrawn_out_of_print() && self.has_withdrawn_date() { + return Err(ThothError::WithdrawnDateError); } Ok(()) } diff --git a/thoth-app/src/component/new_work.rs b/thoth-app/src/component/new_work.rs index a1a73df6e..dcebfda2e 100644 --- a/thoth-app/src/component/new_work.rs +++ b/thoth-app/src/component/new_work.rs @@ -289,7 +289,9 @@ impl Component for NewWorkComponent { self.work.last_page = None; self.work.page_interval = None; } - if self.work.work_status != WorkStatus::WithdrawnFromSale && self.work.work_status != WorkStatus::OutOfPrint { + if self.work.work_status != WorkStatus::WithdrawnFromSale + && self.work.work_status != WorkStatus::OutOfPrint + { self.work.withdrawn_date = None; } let body = CreateWorkRequestBody { @@ -381,7 +383,9 @@ impl Component for NewWorkComponent { } } Msg::ChangeDate(value) => self.work.publication_date.neq_assign(value.to_opt_string()), - Msg::ChangeWithdrawnDate(value) => self.work.withdrawn_date.neq_assign(value.to_opt_string()), + Msg::ChangeWithdrawnDate(value) => { + self.work.withdrawn_date.neq_assign(value.to_opt_string()) + } Msg::ChangePlace(value) => self.work.place.neq_assign(value.to_opt_string()), Msg::ChangePageCount(value) => self.work.page_count.neq_assign(value.to_opt_int()), Msg::ChangePageBreakdown(value) => { @@ -454,7 +458,9 @@ impl Component for NewWorkComponent { // Grey out chapter-specific or "book"-specific fields // based on currently selected work type. let is_chapter = self.work.work_type == WorkType::BookChapter; - let is_not_withdrawn_or_out_of_print = self.work.work_status != WorkStatus::WithdrawnFromSale && self.work.work_status != WorkStatus::OutOfPrint; + let is_not_withdrawn_or_out_of_print = self.work.work_status + != WorkStatus::WithdrawnFromSale + && self.work.work_status != WorkStatus::OutOfPrint; html! { <>