shared/domain/user/
public_user.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//! Types for public users.

use crate::{
    api::endpoints::PathPart,
    domain::{
        additional_resource::AdditionalResource, asset::UserOrMe, circle::CircleId,
        csv_encode_uuids, from_csv, image::ImageId, to_csv, user::UserId,
    },
};
use macros::make_path_parts;
use serde::{Deserialize, Serialize};
use strum_macros::Display;

use super::UserBadge;

make_path_parts!(PublicUserGetPath => "/v1/user/{}/public" => UserId);

/// A lite profile for other Users to view
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PublicUser {
    /// User Id
    pub id: UserId,

    /// Username of User
    pub username: String,

    /// First name of User
    pub given_name: String,

    /// Lastname of User
    pub family_name: String,

    /// Profile image of User
    pub profile_image: Option<ImageId>,

    /// following this user or not
    pub following: bool,

    /// Bio of User
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bio: Option<String>, // only here if bio_public is true

    /// Badge associated with User
    #[serde(default)]
    pub badge: Option<UserBadge>,

    /// Language spoken of User
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub languages_spoken: Option<Vec<String>>, // only here if languages_spoken_public is true

    /// Organization of User
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub organization: Option<String>, // only here if organization_public is true

    /// Persona of User
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub persona: Option<Vec<String>>, // only here if persona_public is true

    /// Country of User
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country_short: Option<String>, // only here if country_public is true

    /// Country of User
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country_long: Option<String>, // only here if country_public is true

    /// Circles associated with User
    #[serde(default)]
    pub circles: Vec<CircleId>,

    /// Number of Jigs
    #[serde(default)]
    pub jig_count: u64,

    /// Number of Resources
    #[serde(default)]
    pub resource_count: u64,

    /// Number of Courses
    #[serde(default)]
    pub course_count: u64,

    /// Number of playlists
    #[serde(default)]
    pub playlist_count: u64,

    /// Total number of assets
    #[serde(default)]
    pub total_asset_count: u64,
}

make_path_parts!(PublicUserBrowsePath => "/v1/user/public/browse");

/// Query for [`Browse`](crate::api::endpoints::user::public_user::Browse).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct UserBrowseQuery {
    /// The page number
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// The hits per page to be returned
    pub page_limit: Option<u32>,

    /// Circle's that has user joined
    #[serde(default)]
    #[serde(serialize_with = "csv_encode_uuids")]
    #[serde(deserialize_with = "from_csv")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub circles: Vec<CircleId>,

    /// Order by sort
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_by: Option<OrderBy>,

    /// Optional filter for user badges
    ///
    #[serde(default)]
    #[serde(serialize_with = "to_csv")]
    #[serde(deserialize_with = "from_csv")]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub badge: Vec<UserBadge>,
}

/// A lite profile for other Users to view
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserResponse {
    /// User Id
    pub users: Vec<PublicUser>,
    /// Pages
    pub pages: u32,
    /// Number of users with profiles
    pub total_user_count: u64,
}

make_path_parts!(PublicUserSearchPath => "/v1/user/public");

/// Query for [`Browse`](crate::api::endpoints::user::Search).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct SearchPublicUserQuery {
    /// The query string.
    #[serde(default)]
    #[serde(skip_serializing_if = "String::is_empty")]
    pub q: String,

    /// The page number of the Circles to get.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// Optionally filter by User's Id
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<UserOrMe>,

    /// Optionally filter by the user's username
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,

    /// Optionally filter by the user's name
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// Optionally filter by the user's spoken language(s)
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub languages_spoken: Option<Vec<String>>,

    /// Optionally filter by the user's organization
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub organization: Option<String>,

    /// Optionally filter by the user's persona(s)
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub persona: Option<Vec<String>>,

    /// Optionally filter by the user's bio
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bio: Option<String>,

    /// The hits per page to be returned
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_limit: Option<u32>,
}

/// A lite profile for other Users to view
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SearchPublicUserResponse {
    /// User Id
    pub users: Vec<PublicUser>,
    /// Number of pages
    pub pages: u32,
    /// Number of User profiles
    pub total_user_count: u64,
}

make_path_parts!(BrowsePublicUserJigsPath => "/v1/user/{}/public/jig/browse" => UserId);

/// Query for [`Browse`](crate::api::endpoints::user::public_user::BrowseUserJigs).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserJigsQuery {
    /// The page number of the User Jigs to fetch.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// The hits per page to be returned
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_limit: Option<u32>,
}

make_path_parts!(BrowsePublicUserResourcesPath => "/v1/user/{}/public/resource/browse" => UserId);

/// Query for [`Browse`](crate::api::endpoints::user::public_user::BrowseUserResources).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserResourcesQuery {
    /// The page number of the User Resources to fetch.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// The hits per page to be returned
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_limit: Option<u32>,
}

/// Response for Browsing a User's Additional Resources
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserResourcesResponse {
    /// The Additional Resources returned
    pub resources: Vec<AdditionalResource>,

    /// The number of pages found.
    pub pages: u32,

    /// The total number of additional resources belonging to user
    pub total_resource_count: u64,
}

make_path_parts!(BrowsePublicUserPlaylistsPath => "/v1/user/{}/public/playlist/browse" => UserId);

/// Query for [`Browse`](crate::api::endpoints::user::public_user::BrowseUserPlaylists).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserPlaylistsQuery {
    /// The page number of the User Playlists to fetch.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// The hits per page to be returned
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_limit: Option<u32>,
}

make_path_parts!(BrowsePublicUserFollowersPath => "/v1/user/{}/public/follower/browse" => UserId);

/// Query for [`Browse`](crate::api::endpoints::user::public_user::BrowseFollowers).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserFollowersQuery {
    /// The page number of the User Followers to fetch.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// The hits per page to be returned
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_limit: Option<u32>,
}

/// Browse User's followers
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserFollowersResponse {
    /// The follower profiles returned
    pub followers: Vec<PublicUser>,

    /// The number of pages found.
    pub pages: u32,

    /// The total number of followers found
    pub total_follower_count: u64,
}

make_path_parts!(BrowsePublicUserFollowingPath => "/v1/user/{}/public/following/browse" => UserId);

/// Query for [`Browse`](crate::api::endpoints::user::public_user::BrowseFollowing).
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserFollowingsQuery {
    /// The page number of the Public User Followers to fetch.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page: Option<u32>,

    /// The hits per page to be returned
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_limit: Option<u32>,
}

/// Browse User's followings
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BrowsePublicUserFollowingResponse {
    /// The Public User Profiles of followings
    pub followings: Vec<PublicUser>,

    /// The number of pages found.
    pub pages: u32,

    /// The total number of followings found
    pub total_following_count: u64,
}

make_path_parts!(PublicUserFollowPath => "/v1/user/{}/follow" => UserId);

make_path_parts!(PublicUserUnfollowPath => "/v1/user/{}/unfollow" => UserId);

/// Sort browse results by timestamp
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug, Display)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
#[repr(i16)]
pub enum OrderBy {
    /// Order Asset by asset count
    #[strum(serialize = "AssetCount")]
    AssetCount = 0,
}