shared/domain/jig/
curation.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! Types for Jig short codes for sharing
use chrono::{DateTime, Utc};
use macros::make_path_parts;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::api::endpoints::PathPart;

use super::{report::JigReport, JigId};

wrap_uuid! {
    /// Wrapper type around [`Uuid`](Uuid), represents the ID of a curation comment.
    pub struct CommentId
}

make_path_parts!(JigCurationPath => "/v1/jig/{}/curation" => JigId);

/// Curation data for JIGS
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigCurationData {
    /// Jig ID for curation
    pub jig_id: JigId,

    /// Fields curated by Admin
    pub fields_done: JigCurationFieldsDone,

    /// Status for curation
    pub curation_status: JigCurationStatus,

    /// Comments from curator (not updatable)
    pub comments: Vec<JigCurationComment>,

    /// Reports for Jig from users (not updatable)
    pub reports: Vec<JigReport>,
}

/// Curation fields that have been completed
///
/// Authorization:
/// Admin
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigCurationFieldsDone {
    /// Display name of JIG
    pub display_name: bool,

    /// Language of JIG
    pub language: bool,

    /// Categories of JIG
    pub categories: bool,

    /// Descriptions of JIG
    pub description: bool,

    /// Age ranges of JIG
    pub age_ranges: bool,

    /// Affiliations of JIG
    pub affiliations: bool,

    /// Addtional resources of JIG
    pub additional_resources: bool,
}

impl Default for JigCurationFieldsDone {
    fn default() -> Self {
        Self {
            display_name: false,
            language: false,
            categories: false,
            description: false,
            age_ranges: false,
            affiliations: false,
            additional_resources: false,
        }
    }
}

/// Status of Curation
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
#[repr(i16)]
pub enum JigCurationStatus {
    /// JIGs first curation
    New = 0,

    /// JIG has been updated by user
    NewVersion = 1,

    /// Admin is reviewing JIG
    InProgress = 2,

    /// Curation of JIG completed
    Done = 3,
}

impl Default for JigCurationStatus {
    fn default() -> Self {
        Self::New
    }
}

make_path_parts!(JigCurationUpdatePath => "/v1/jig/{}/curation" => JigId);

/// Curation data for JIGS
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct JigCurationUpdateRequest {
    /// Display name of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_name: Option<bool>,

    /// Language of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<bool>,

    /// Goals of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub goals: Option<bool>,

    /// Categories of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub categories: Option<bool>,

    /// Descriptions of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<bool>,

    /// Age ranges of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub age_ranges: Option<bool>,

    /// Affiliations of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub affiliations: Option<bool>,

    /// Addtional resources of JIG
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub additional_resources: Option<bool>,

    /// Curation status of Jig
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub curation_status: Option<JigCurationStatus>,
}

make_path_parts!(JigCurationCommentCreatePath => "/v1/jig/{}/curation/comment" => JigId);

/// Curation data for JIGS
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigCurationComment {
    /// Comment ID
    pub id: CommentId,

    /// Jig ID for comment
    pub jig_id: JigId,

    /// Comment
    pub value: String,

    /// When comment was submitted
    pub created_at: DateTime<Utc>,

    /// ID of commenter
    pub author_id: Uuid,
}

/// Request to comment on Jig
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigCurationCommentRequest {
    /// Display name of JIG
    pub value: String,
}

make_path_parts!(JigCurationCommentGetPath => "/v1/jig/{}/curation/comment/{}" => JigId, CommentId);

/// Curation data for JIGS
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigCurationCommentResponse {
    /// ID of comment
    pub id: CommentId,

    /// ID of Jig
    pub jig_id: JigId,

    /// Curator comment
    pub value: String,

    /// When comment was submitted
    pub created_at: Option<DateTime<Utc>>,

    /// ID of commenter
    pub author_id: Uuid,

    /// Name of commenter
    pub author_name: String,
}