Skip to content

Commit

Permalink
Fixed migration, fixed formatting and clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-oconnell committed Apr 19, 2024
1 parent 8c98b68 commit 1110978
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
3 changes: 1 addition & 2 deletions thoth-api/migrations/v0.12.3/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion thoth-api/src/model/work/crud.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
8 changes: 3 additions & 5 deletions thoth-api/src/model/work/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(())
}
Expand Down
12 changes: 9 additions & 3 deletions thoth-app/src/component/new_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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! {
<>
<nav class="level">
Expand Down
12 changes: 9 additions & 3 deletions thoth-app/src/component/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ impl Component for WorkComponent {
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 = UpdateWorkRequestBody {
Expand Down Expand Up @@ -457,7 +459,9 @@ impl Component for WorkComponent {
}
}
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) => {
Expand Down Expand Up @@ -568,7 +572,9 @@ impl Component for WorkComponent {
// 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! {
<>
<nav class="level">
Expand Down
4 changes: 1 addition & 3 deletions thoth-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ pub enum ThothError {
"Price values must be greater than zero. To indicate an unpriced Publication, omit all Prices."
)]
WithdrawnDateError,
#[error(
"Withdrawn Date can only be added to out of print or withdrawn from sale Works."
)]
#[error("Withdrawn Date can only be added to out of print or withdrawn from sale Works.")]
PriceZeroError,
#[error("{0}")]
RequestError(String),
Expand Down

0 comments on commit 1110978

Please sign in to comment.