Skip to content

Commit 297e56d

Browse files
authored
Merge pull request #737 from thoth-pub/feature/work-book-relations-v1
Add additional fields to new entities
2 parents 7924492 + 550c2ff commit 297e56d

23 files changed

Lines changed: 746 additions & 35 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
DROP INDEX IF EXISTS endorsement_author_institution_idx;
2+
3+
ALTER TABLE endorsement
4+
DROP COLUMN IF EXISTS author_institution_id,
5+
DROP COLUMN IF EXISTS author_orcid;
6+
7+
DROP INDEX IF EXISTS book_review_reviewer_institution_idx;
8+
9+
ALTER TABLE book_review
10+
DROP COLUMN IF EXISTS page_range,
11+
DROP COLUMN IF EXISTS reviewer_institution_id,
12+
DROP COLUMN IF EXISTS reviewer_orcid;
13+
14+
ALTER TABLE additional_resource
15+
DROP COLUMN IF EXISTS date;
16+
17+
ALTER TABLE award
18+
DROP COLUMN IF EXISTS role;
19+
20+
ALTER TABLE award
21+
RENAME COLUMN prize_statement TO note;
22+
23+
DROP TYPE IF EXISTS award_role;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
CREATE TYPE award_role AS ENUM (
2+
'SHORT_LISTED',
3+
'WINNER',
4+
'LONG_LISTED',
5+
'COMMENDED',
6+
'RUNNER_UP',
7+
'JOINT_WINNER',
8+
'NOMINATED'
9+
);
10+
11+
ALTER TABLE award
12+
RENAME COLUMN note TO prize_statement;
13+
14+
ALTER TABLE award
15+
ADD COLUMN role award_role;
16+
17+
ALTER TABLE additional_resource
18+
ADD COLUMN date DATE;
19+
20+
ALTER TABLE book_review
21+
ADD COLUMN reviewer_orcid TEXT,
22+
ADD COLUMN reviewer_institution_id UUID REFERENCES institution(institution_id) ON DELETE SET NULL,
23+
ADD COLUMN page_range TEXT;
24+
25+
CREATE INDEX book_review_reviewer_institution_idx
26+
ON book_review (reviewer_institution_id)
27+
WHERE reviewer_institution_id IS NOT NULL;
28+
29+
ALTER TABLE endorsement
30+
ADD COLUMN author_orcid TEXT,
31+
ADD COLUMN author_institution_id UUID REFERENCES institution(institution_id) ON DELETE SET NULL;
32+
33+
CREATE INDEX endorsement_author_institution_idx
34+
ON endorsement (author_institution_id)
35+
WHERE author_institution_id IS NOT NULL;

thoth-api/src/graphql/model.rs

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::markup::{convert_from_jats, ConversionLimit, MarkupFormat};
1414
use crate::model::{
1515
additional_resource::{AdditionalResource, AdditionalResourceOrderBy},
1616
affiliation::{Affiliation, AffiliationOrderBy},
17-
award::{Award, AwardOrderBy},
17+
award::{Award, AwardOrderBy, AwardRole},
1818
biography::{Biography, BiographyOrderBy},
1919
book_review::{BookReview, BookReviewOrderBy},
2020
contact::{Contact, ContactOrderBy, ContactType},
@@ -2224,6 +2224,11 @@ impl AdditionalResource {
22242224
self.url.as_ref()
22252225
}
22262226

2227+
#[graphql(description = "Date associated with the additional resource")]
2228+
pub fn date(&self) -> Option<NaiveDate> {
2229+
self.date
2230+
}
2231+
22272232
#[graphql(
22282233
description = "Number representing this resource's position in an ordered list of resources within the work"
22292234
)]
@@ -2295,20 +2300,25 @@ impl Award {
22952300
self.category.as_ref()
22962301
}
22972302

2298-
#[graphql(description = "Additional note for this award")]
2299-
pub fn note(
2303+
#[graphql(description = "Role of the work in this award")]
2304+
pub fn role(&self) -> Option<AwardRole> {
2305+
self.role
2306+
}
2307+
2308+
#[graphql(description = "Prize statement for this award")]
2309+
pub fn prize_statement(
23002310
&self,
23012311
#[graphql(
23022312
default = MarkupFormat::JatsXml,
2303-
description = "Markup format used for rendering note",
2313+
description = "Markup format used for rendering prize statement",
23042314
)]
23052315
markup_format: Option<MarkupFormat>,
23062316
) -> FieldResult<Option<String>> {
2307-
self.note
2317+
self.prize_statement
23082318
.as_ref()
2309-
.map(|note| {
2319+
.map(|prize_statement| {
23102320
convert_from_jats(
2311-
note,
2321+
prize_statement,
23122322
markup_format.ok_or(ThothError::MissingMarkupFormat)?,
23132323
ConversionLimit::Abstract,
23142324
)
@@ -2365,6 +2375,18 @@ impl Endorsement {
23652375
self.author_role.as_ref()
23662376
}
23672377

2378+
#[graphql(
2379+
description = "ORCID (Open Researcher and Contributor ID) of the endorsement author as full URL, using the HTTPS scheme and the orcid.org domain"
2380+
)]
2381+
pub fn author_orcid(&self) -> Option<&Orcid> {
2382+
self.author_orcid.as_ref()
2383+
}
2384+
2385+
#[graphql(description = "Thoth ID of the endorsement author's institution")]
2386+
pub fn author_institution_id(&self) -> Option<&Uuid> {
2387+
self.author_institution_id.as_ref()
2388+
}
2389+
23682390
#[graphql(description = "URL associated with this endorsement")]
23692391
pub fn url(&self) -> Option<&String> {
23702392
self.url.as_ref()
@@ -2413,6 +2435,15 @@ impl Endorsement {
24132435
pub fn work(&self, context: &Context) -> FieldResult<Work> {
24142436
Work::from_id(&context.db, &self.work_id).map_err(Into::into)
24152437
}
2438+
2439+
#[graphql(description = "Get the endorsement author's institution")]
2440+
pub fn author_institution(&self, context: &Context) -> FieldResult<Option<Institution>> {
2441+
self.author_institution_id
2442+
.as_ref()
2443+
.map(|institution_id| Institution::from_id(&context.db, institution_id))
2444+
.transpose()
2445+
.map_err(Into::into)
2446+
}
24162447
}
24172448

24182449
#[juniper::graphql_object(
@@ -2431,15 +2462,44 @@ impl BookReview {
24312462
}
24322463

24332464
#[graphql(description = "Title of the review")]
2434-
pub fn title(&self) -> Option<&String> {
2435-
self.title.as_ref()
2465+
pub fn title(
2466+
&self,
2467+
#[graphql(
2468+
default = MarkupFormat::JatsXml,
2469+
description = "Markup format used for rendering review title",
2470+
)]
2471+
markup_format: Option<MarkupFormat>,
2472+
) -> FieldResult<Option<String>> {
2473+
self.title
2474+
.as_ref()
2475+
.map(|title| {
2476+
convert_from_jats(
2477+
title,
2478+
markup_format.ok_or(ThothError::MissingMarkupFormat)?,
2479+
ConversionLimit::Title,
2480+
)
2481+
})
2482+
.transpose()
2483+
.map_err(Into::into)
24362484
}
24372485

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

2491+
#[graphql(
2492+
description = "ORCID (Open Researcher and Contributor ID) of the reviewer as full URL, using the HTTPS scheme and the orcid.org domain"
2493+
)]
2494+
pub fn reviewer_orcid(&self) -> Option<&Orcid> {
2495+
self.reviewer_orcid.as_ref()
2496+
}
2497+
2498+
#[graphql(description = "Thoth ID of the reviewer's institution")]
2499+
pub fn reviewer_institution_id(&self) -> Option<&Uuid> {
2500+
self.reviewer_institution_id.as_ref()
2501+
}
2502+
24432503
#[graphql(description = "URL of the review publication")]
24442504
pub fn url(&self) -> Option<&String> {
24452505
self.url.as_ref()
@@ -2477,6 +2537,11 @@ impl BookReview {
24772537
self.journal_issn.as_ref()
24782538
}
24792539

2540+
#[graphql(description = "Page range of the review")]
2541+
pub fn page_range(&self) -> Option<&String> {
2542+
self.page_range.as_ref()
2543+
}
2544+
24802545
#[graphql(description = "Text of the review")]
24812546
pub fn text(
24822547
&self,
@@ -2520,6 +2585,15 @@ impl BookReview {
25202585
pub fn work(&self, context: &Context) -> FieldResult<Work> {
25212586
Work::from_id(&context.db, &self.work_id).map_err(Into::into)
25222587
}
2588+
2589+
#[graphql(description = "Get the reviewer's institution")]
2590+
pub fn reviewer_institution(&self, context: &Context) -> FieldResult<Option<Institution>> {
2591+
self.reviewer_institution_id
2592+
.as_ref()
2593+
.map(|institution_id| Institution::from_id(&context.db, institution_id))
2594+
.transpose()
2595+
.map_err(Into::into)
2596+
}
25232597
}
25242598

25252599
#[juniper::graphql_object(

thoth-api/src/graphql/mutation.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ impl MutationRoot {
287287

288288
let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
289289
data.title = convert_to_jats(data.title, markup, ConversionLimit::Title)?;
290-
data.note = data
291-
.note
292-
.map(|note| convert_to_jats(note, markup, ConversionLimit::Abstract))
290+
data.prize_statement = data
291+
.prize_statement
292+
.map(|prize_statement| {
293+
convert_to_jats(prize_statement, markup, ConversionLimit::Abstract)
294+
})
293295
.transpose()?;
294296

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

325327
let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
328+
data.title = data
329+
.title
330+
.map(|title| convert_to_jats(title, markup, ConversionLimit::Title))
331+
.transpose()?;
326332
data.text = data
327333
.text
328334
.map(|text| convert_to_jats(text, markup, ConversionLimit::Abstract))
@@ -588,9 +594,11 @@ impl MutationRoot {
588594

589595
let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
590596
data.title = convert_to_jats(data.title, markup, ConversionLimit::Title)?;
591-
data.note = data
592-
.note
593-
.map(|note| convert_to_jats(note, markup, ConversionLimit::Abstract))
597+
data.prize_statement = data
598+
.prize_statement
599+
.map(|prize_statement| {
600+
convert_to_jats(prize_statement, markup, ConversionLimit::Abstract)
601+
})
594602
.transpose()?;
595603

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

630638
let markup = markup_format.unwrap_or(MarkupFormat::JatsXml);
639+
data.title = data
640+
.title
641+
.map(|title| convert_to_jats(title, markup, ConversionLimit::Title))
642+
.transpose()?;
631643
data.text = data
632644
.text
633645
.map(|text| convert_to_jats(text, markup, ConversionLimit::Abstract))

0 commit comments

Comments
 (0)