shared/domain/resource/
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
//! Types for Resource short codes for sharing
use chrono::{DateTime, Utc};
use macros::make_path_parts;
use serde::{Deserialize, Serialize};

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

use super::{report::ResourceReport, ResourceId, UserId};

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

make_path_parts!(ResourceCurationPath => "/v1/resource/{}/curation" => ResourceId);

/// Curation data for Resources
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ResourceCurationData {
    /// Resource ID for curation
    pub resource_id: ResourceId,

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

    /// Status for curation
    pub curation_status: ResourceCurationStatus,

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

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

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

    /// Language of Resource
    pub language: bool,

    /// Categories of Resource
    pub categories: bool,

    /// Descriptions of Resource
    pub description: bool,

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

    /// Affiliations of Resource
    pub affiliations: bool,

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

impl Default for ResourceCurationFieldsDone {
    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 ResourceCurationStatus {
    /// Resources first curation
    New = 0,

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

    /// Admin is reviewing Resource
    InProgress = 2,

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

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

make_path_parts!(ResourceCurationUpdatePath => "/v1/resource/{}/curation" => ResourceId);

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

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

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

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

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

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

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

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

make_path_parts!(ResourceCurationCommentCreatePath => "/v1/resource/{}/curation/comment" => ResourceId);

/// Curation data for ResourceS
#[derive(Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
pub struct ResourceCurationComment {
    /// Comment ID
    pub id: CommentId,

    /// Resource ID for comment
    pub resource_id: ResourceId,

    /// Comment
    pub value: String,

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

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

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

make_path_parts!(ResourceCurationCommentGetPath => "/v1/resource/{}/curation/comment/{}" => ResourceId, CommentId);

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

    /// ID of Resource
    pub resource_id: ResourceId,

    /// Curator comment
    pub value: String,

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

    /// ID of commenter
    pub author_id: UserId,

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