Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions thoth-api/migrations/20260312_v1.0.0/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DROP INDEX IF EXISTS endorsement_author_institution_idx;

ALTER TABLE endorsement
DROP COLUMN IF EXISTS author_institution_id,
DROP COLUMN IF EXISTS author_orcid;

DROP INDEX IF EXISTS book_review_reviewer_institution_idx;

ALTER TABLE book_review
DROP COLUMN IF EXISTS page_range,
DROP COLUMN IF EXISTS reviewer_institution_id,
DROP COLUMN IF EXISTS reviewer_orcid;

ALTER TABLE additional_resource
DROP COLUMN IF EXISTS date;

ALTER TABLE award
DROP COLUMN IF EXISTS role;

ALTER TABLE award
RENAME COLUMN prize_statement TO note;

DROP TYPE IF EXISTS award_role;
35 changes: 35 additions & 0 deletions thoth-api/migrations/20260312_v1.0.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CREATE TYPE award_role AS ENUM (
'SHORT_LISTED',
'WINNER',
'LONG_LISTED',
'COMMENDED',
'RUNNER_UP',
'JOINT_WINNER',
'NOMINATED'
);

ALTER TABLE award
RENAME COLUMN note TO prize_statement;

ALTER TABLE award
ADD COLUMN role award_role;

ALTER TABLE additional_resource
ADD COLUMN date DATE;

ALTER TABLE book_review
ADD COLUMN reviewer_orcid TEXT,
ADD COLUMN reviewer_institution_id UUID REFERENCES institution(institution_id) ON DELETE SET NULL,
ADD COLUMN page_range TEXT;

CREATE INDEX book_review_reviewer_institution_idx
ON book_review (reviewer_institution_id)
WHERE reviewer_institution_id IS NOT NULL;

ALTER TABLE endorsement
ADD COLUMN author_orcid TEXT,
ADD COLUMN author_institution_id UUID REFERENCES institution(institution_id) ON DELETE SET NULL;

CREATE INDEX endorsement_author_institution_idx
ON endorsement (author_institution_id)
WHERE author_institution_id IS NOT NULL;
92 changes: 83 additions & 9 deletions thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::markup::{convert_from_jats, ConversionLimit, MarkupFormat};
use crate::model::{
additional_resource::{AdditionalResource, AdditionalResourceOrderBy},
affiliation::{Affiliation, AffiliationOrderBy},
award::{Award, AwardOrderBy},
award::{Award, AwardOrderBy, AwardRole},
biography::{Biography, BiographyOrderBy},
book_review::{BookReview, BookReviewOrderBy},
contact::{Contact, ContactOrderBy, ContactType},
Expand Down Expand Up @@ -2224,6 +2224,11 @@ impl AdditionalResource {
self.url.as_ref()
}

#[graphql(description = "Date associated with the additional resource")]
pub fn date(&self) -> Option<NaiveDate> {
self.date
}

#[graphql(
description = "Number representing this resource's position in an ordered list of resources within the work"
)]
Expand Down Expand Up @@ -2295,20 +2300,25 @@ impl Award {
self.category.as_ref()
}

#[graphql(description = "Additional note for this award")]
pub fn note(
#[graphql(description = "Role of the work in this award")]
pub fn role(&self) -> Option<AwardRole> {
self.role
}

#[graphql(description = "Prize statement for this award")]
pub fn prize_statement(
&self,
#[graphql(
default = MarkupFormat::JatsXml,
description = "Markup format used for rendering note",
description = "Markup format used for rendering prize statement",
)]
markup_format: Option<MarkupFormat>,
) -> FieldResult<Option<String>> {
self.note
self.prize_statement
.as_ref()
.map(|note| {
.map(|prize_statement| {
convert_from_jats(
note,
prize_statement,
markup_format.ok_or(ThothError::MissingMarkupFormat)?,
ConversionLimit::Abstract,
)
Expand Down Expand Up @@ -2365,6 +2375,18 @@ impl Endorsement {
self.author_role.as_ref()
}

#[graphql(
description = "ORCID (Open Researcher and Contributor ID) of the endorsement author as full URL, using the HTTPS scheme and the orcid.org domain"
)]
pub fn author_orcid(&self) -> Option<&Orcid> {
self.author_orcid.as_ref()
}

#[graphql(description = "Thoth ID of the endorsement author's institution")]
pub fn author_institution_id(&self) -> Option<&Uuid> {
self.author_institution_id.as_ref()
}

#[graphql(description = "URL associated with this endorsement")]
pub fn url(&self) -> Option<&String> {
self.url.as_ref()
Expand Down Expand Up @@ -2413,6 +2435,15 @@ impl Endorsement {
pub fn work(&self, context: &Context) -> FieldResult<Work> {
Work::from_id(&context.db, &self.work_id).map_err(Into::into)
}

#[graphql(description = "Get the endorsement author's institution")]
pub fn author_institution(&self, context: &Context) -> FieldResult<Option<Institution>> {
self.author_institution_id
.as_ref()
.map(|institution_id| Institution::from_id(&context.db, institution_id))
.transpose()
.map_err(Into::into)
}
}

#[juniper::graphql_object(
Expand All @@ -2431,15 +2462,44 @@ impl BookReview {
}

#[graphql(description = "Title of the review")]
pub fn title(&self) -> Option<&String> {
self.title.as_ref()
pub fn title(
&self,
#[graphql(
default = MarkupFormat::JatsXml,
description = "Markup format used for rendering review title",
)]
markup_format: Option<MarkupFormat>,
) -> FieldResult<Option<String>> {
self.title
.as_ref()
.map(|title| {
convert_from_jats(
title,
markup_format.ok_or(ThothError::MissingMarkupFormat)?,
ConversionLimit::Title,
)
})
.transpose()
.map_err(Into::into)
}

#[graphql(description = "Name of the review author")]
pub fn author_name(&self) -> Option<&String> {
self.author_name.as_ref()
}

#[graphql(
description = "ORCID (Open Researcher and Contributor ID) of the reviewer as full URL, using the HTTPS scheme and the orcid.org domain"
)]
pub fn reviewer_orcid(&self) -> Option<&Orcid> {
self.reviewer_orcid.as_ref()
}

#[graphql(description = "Thoth ID of the reviewer's institution")]
pub fn reviewer_institution_id(&self) -> Option<&Uuid> {
self.reviewer_institution_id.as_ref()
}

#[graphql(description = "URL of the review publication")]
pub fn url(&self) -> Option<&String> {
self.url.as_ref()
Expand Down Expand Up @@ -2477,6 +2537,11 @@ impl BookReview {
self.journal_issn.as_ref()
}

#[graphql(description = "Page range of the review")]
pub fn page_range(&self) -> Option<&String> {
self.page_range.as_ref()
}

#[graphql(description = "Text of the review")]
pub fn text(
&self,
Expand Down Expand Up @@ -2520,6 +2585,15 @@ impl BookReview {
pub fn work(&self, context: &Context) -> FieldResult<Work> {
Work::from_id(&context.db, &self.work_id).map_err(Into::into)
}

#[graphql(description = "Get the reviewer's institution")]
pub fn reviewer_institution(&self, context: &Context) -> FieldResult<Option<Institution>> {
self.reviewer_institution_id
.as_ref()
.map(|institution_id| Institution::from_id(&context.db, institution_id))
.transpose()
.map_err(Into::into)
}
}

#[juniper::graphql_object(
Expand Down
24 changes: 18 additions & 6 deletions thoth-api/src/graphql/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ impl MutationRoot {

let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
data.title = convert_to_jats(data.title, markup, ConversionLimit::Title)?;
data.note = data
.note
.map(|note| convert_to_jats(note, markup, ConversionLimit::Abstract))
data.prize_statement = data
.prize_statement
.map(|prize_statement| {
convert_to_jats(prize_statement, markup, ConversionLimit::Abstract)
})
.transpose()?;

Award::create(&context.db, &data).map_err(Into::into)
Expand Down Expand Up @@ -323,6 +325,10 @@ impl MutationRoot {
BookReviewPolicy::can_create(context, &data, ())?;

let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
data.title = data
.title
.map(|title| convert_to_jats(title, markup, ConversionLimit::Title))
.transpose()?;
data.text = data
.text
.map(|text| convert_to_jats(text, markup, ConversionLimit::Abstract))
Expand Down Expand Up @@ -588,9 +594,11 @@ impl MutationRoot {

let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
data.title = convert_to_jats(data.title, markup, ConversionLimit::Title)?;
data.note = data
.note
.map(|note| convert_to_jats(note, markup, ConversionLimit::Abstract))
data.prize_statement = data
.prize_statement
.map(|prize_statement| {
convert_to_jats(prize_statement, markup, ConversionLimit::Abstract)
})
.transpose()?;

award.update(context, &data).map_err(Into::into)
Expand Down Expand Up @@ -628,6 +636,10 @@ impl MutationRoot {
BookReviewPolicy::can_update(context, &book_review, &data, ())?;

let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
data.title = data
.title
.map(|title| convert_to_jats(title, markup, ConversionLimit::Title))
.transpose()?;
data.text = data
.text
.map(|text| convert_to_jats(text, markup, ConversionLimit::Abstract))
Expand Down
Loading
Loading