shared/domain/jig/
curation.rs

1//! Types for Jig short codes for sharing
2use chrono::{DateTime, Utc};
3use macros::make_path_parts;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7use crate::api::endpoints::PathPart;
8
9use super::{report::JigReport, JigId};
10
11wrap_uuid! {
12    /// Wrapper type around [`Uuid`](Uuid), represents the ID of a curation comment.
13    pub struct CommentId
14}
15
16make_path_parts!(JigCurationPath => "/v1/jig/{}/curation" => JigId);
17
18/// Curation data for JIGS
19#[derive(Serialize, Deserialize, Clone, Debug)]
20#[serde(rename_all = "camelCase")]
21pub struct JigCurationData {
22    /// Jig ID for curation
23    pub jig_id: JigId,
24
25    /// Fields curated by Admin
26    pub fields_done: JigCurationFieldsDone,
27
28    /// Status for curation
29    pub curation_status: JigCurationStatus,
30
31    /// Comments from curator (not updatable)
32    pub comments: Vec<JigCurationComment>,
33
34    /// Reports for Jig from users (not updatable)
35    pub reports: Vec<JigReport>,
36}
37
38/// Curation fields that have been completed
39///
40/// Authorization:
41/// Admin
42#[derive(Serialize, Deserialize, Clone, Debug)]
43#[serde(rename_all = "camelCase")]
44pub struct JigCurationFieldsDone {
45    /// Display name of JIG
46    pub display_name: bool,
47
48    /// Language of JIG
49    pub language: bool,
50
51    /// Categories of JIG
52    pub categories: bool,
53
54    /// Descriptions of JIG
55    pub description: bool,
56
57    /// Age ranges of JIG
58    pub age_ranges: bool,
59
60    /// Affiliations of JIG
61    pub affiliations: bool,
62
63    /// Addtional resources of JIG
64    pub additional_resources: bool,
65}
66
67impl Default for JigCurationFieldsDone {
68    fn default() -> Self {
69        Self {
70            display_name: false,
71            language: false,
72            categories: false,
73            description: false,
74            age_ranges: false,
75            affiliations: false,
76            additional_resources: false,
77        }
78    }
79}
80
81/// Status of Curation
82#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug)]
83#[cfg_attr(feature = "backend", derive(sqlx::Type))]
84#[serde(rename_all = "camelCase")]
85#[repr(i16)]
86pub enum JigCurationStatus {
87    /// JIGs first curation
88    New = 0,
89
90    /// JIG has been updated by user
91    NewVersion = 1,
92
93    /// Admin is reviewing JIG
94    InProgress = 2,
95
96    /// Curation of JIG completed
97    Done = 3,
98}
99
100impl Default for JigCurationStatus {
101    fn default() -> Self {
102        Self::New
103    }
104}
105
106make_path_parts!(JigCurationUpdatePath => "/v1/jig/{}/curation" => JigId);
107
108/// Curation data for JIGS
109#[derive(Serialize, Deserialize, Clone, Debug, Default)]
110#[serde(rename_all = "camelCase")]
111pub struct JigCurationUpdateRequest {
112    /// Display name of JIG
113    #[serde(default)]
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub display_name: Option<bool>,
116
117    /// Language of JIG
118    #[serde(default)]
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub language: Option<bool>,
121
122    /// Goals of JIG
123    #[serde(default)]
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub goals: Option<bool>,
126
127    /// Categories of JIG
128    #[serde(default)]
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub categories: Option<bool>,
131
132    /// Descriptions of JIG
133    #[serde(default)]
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub description: Option<bool>,
136
137    /// Age ranges of JIG
138    #[serde(default)]
139    #[serde(skip_serializing_if = "Option::is_none")]
140    pub age_ranges: Option<bool>,
141
142    /// Affiliations of JIG
143    #[serde(default)]
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub affiliations: Option<bool>,
146
147    /// Addtional resources of JIG
148    #[serde(default)]
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub additional_resources: Option<bool>,
151
152    /// Curation status of Jig
153    #[serde(default)]
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub curation_status: Option<JigCurationStatus>,
156}
157
158make_path_parts!(JigCurationCommentCreatePath => "/v1/jig/{}/curation/comment" => JigId);
159
160/// Curation data for JIGS
161#[derive(Serialize, Deserialize, Clone, Debug)]
162#[serde(rename_all = "camelCase")]
163pub struct JigCurationComment {
164    /// Comment ID
165    pub id: CommentId,
166
167    /// Jig ID for comment
168    pub jig_id: JigId,
169
170    /// Comment
171    pub value: String,
172
173    /// When comment was submitted
174    pub created_at: DateTime<Utc>,
175
176    /// ID of commenter
177    pub author_id: Uuid,
178}
179
180/// Request to comment on Jig
181#[derive(Serialize, Deserialize, Debug)]
182#[serde(rename_all = "camelCase")]
183pub struct JigCurationCommentRequest {
184    /// Display name of JIG
185    pub value: String,
186}
187
188make_path_parts!(JigCurationCommentGetPath => "/v1/jig/{}/curation/comment/{}" => JigId, CommentId);
189
190/// Curation data for JIGS
191#[derive(Serialize, Deserialize, Debug)]
192#[serde(rename_all = "camelCase")]
193pub struct JigCurationCommentResponse {
194    /// ID of comment
195    pub id: CommentId,
196
197    /// ID of Jig
198    pub jig_id: JigId,
199
200    /// Curator comment
201    pub value: String,
202
203    /// When comment was submitted
204    pub created_at: Option<DateTime<Utc>>,
205
206    /// ID of commenter
207    pub author_id: Uuid,
208
209    /// Name of commenter
210    pub author_name: String,
211}