shared/api/endpoints/
user.rs

1use super::ApiEndpoint;
2
3use crate::{
4    api::method::Method,
5    domain::{
6        session::NewSessionResponse,
7        user::{
8            ChangePasswordPath, ChangePasswordRequest, CreateUserPath, CreateUserRequest,
9            OtherUser, ResetEmailPath, ResetEmailRequest, ResetEmailResponse, ResetPasswordPath,
10            ResetPasswordRequest, UserBrowsePath, UserBrowseQuery, UserBrowseResponse,
11            UserDeletePath, UserLookupPath, UserLookupQuery, UserSearchPath, UserSearchQuery,
12            UserSearchResponse, VerifyEmailPath, VerifyEmailRequest, VerifyResetEmailPath,
13            VerifyResetEmailRequest,
14        },
15    },
16    error::EmptyError,
17};
18
19mod colors;
20mod fonts;
21mod profile;
22mod public_user;
23
24pub use colors::{
25    Create as CreateColor, Delete as DeleteColor, Get as GetColors, Update as UpdateColor,
26};
27
28pub use fonts::{
29    Create as CreateFont, Delete as DeleteFont, Get as GetFonts, Update as UpdateFont,
30};
31
32pub use profile::{
33    Create as CreateProfile, Get as Profile, Patch as PatchProfile, PatchProfileAdminData,
34};
35
36pub use public_user::{
37    BrowseFollowers, BrowseFollowing, BrowsePublicUser, BrowseUserJigs,
38    BrowseUserPlaylists as BrowsePlaylists, BrowseUserResources as BrowseResources, Follow,
39    Get as GetPublicUser, SearchPublicUser as Search, Unfollow,
40};
41
42/// Create a new user.
43///
44/// # Flow
45/// 1. `POST` to this route
46///     * recieve one of:
47///         1. email gets sent to the user - [`204 - No Content`](http::StatusCode::NO_CONTENT)
48///         2. email already exists - [`409 - Conflict`](http::StatusCode::CONFLICT)
49///             * In the future this may contain information about *how* the email is registered.
50/// 2. [`POST /v1/user/verify-email`](VerifyEmail)
51/// 3. [`POST /v1/user/me/profile`](profile::Create)
52pub struct Create;
53impl ApiEndpoint for Create {
54    type Req = CreateUserRequest;
55    type Res = ();
56    type Path = CreateUserPath;
57    type Err = EmptyError;
58    const METHOD: Method = Method::Post;
59}
60
61/// Verify a user's email.
62///
63/// # Register Flow
64/// 1. [`POST /v1/user`](Create)
65///     * This will send the email for verification
66/// 2. `POST` this route with the Verify request.
67///     * recieve one of:
68///         1. a 200 ([`NewSessionResponse`])
69///         2. a 401 response (`<token>` is invalid)
70///
71/// # Change email Flow (NOT CURRENTLY IMPLEMENTED)
72/// 1. `PUT /v1/user/me/email`
73///     * this will send an email to verify the *old* address
74/// 2. `POST` this route with the token from the email
75///     * this will send an email to verify the *new* address
76/// 3. `POST` this route *again* with the token from the new address
77///     * The new email will get set at this point, recieve one of:
78///         1. a 204 (success!)
79///         2. a 401 response (`token` is invalid)
80///
81/// # Resend verification email
82/// 1. `POST` this route with no auth and [`Resend`](VerifyEmailRequest::Resend)
83///     * this resend will the verification email
84///     * this will *always* return a 204 on success.
85/// 2. Continue the flow you were in.
86///
87/// If no verification is in progress, no email will be sent.
88pub struct VerifyEmail;
89impl ApiEndpoint for VerifyEmail {
90    type Req = VerifyEmailRequest;
91    type Res = Option<NewSessionResponse>;
92    type Path = VerifyEmailPath;
93    type Err = EmptyError;
94    const METHOD: Method = Method::Post;
95}
96
97/// verifies the updated email for a user
98pub struct VerifyResetEmail;
99impl ApiEndpoint for VerifyResetEmail {
100    type Req = VerifyResetEmailRequest;
101    type Res = ();
102    type Path = VerifyResetEmailPath;
103    type Err = EmptyError;
104    const METHOD: Method = Method::Post;
105}
106
107/// Resets user email
108///
109/// # Flow
110/// 1. `POST` to this route
111///     * recieve one of:
112///         1. email gets sent to the user - [`204 - No Content`](http::StatusCode::NO_CONTENT)
113///         2. email already exists - [`409 - Conflict`](http::StatusCode::CONFLICT)
114/// 2. [`PATCH /v1/user/reset-email`](ResetEmail)
115pub struct ResetEmail;
116impl ApiEndpoint for ResetEmail {
117    type Req = ResetEmailRequest;
118    type Res = ResetEmailResponse;
119    type Path = ResetEmailPath;
120    type Err = EmptyError;
121    const METHOD: Method = Method::Patch;
122}
123
124/// Reset a user's password.
125///
126/// # Flow
127/// 1. `POST` This route.
128///      * email gets sent to the included email address
129///      * recieve [`204 - No Content`](http::StatusCode::NO_CONTENT)
130/// 2. [`PUT /v1/user/me/password`](ChangePassword)
131pub struct ResetPassword;
132impl ApiEndpoint for ResetPassword {
133    type Req = ResetPasswordRequest;
134    type Res = ();
135    type Path = ResetPasswordPath;
136    type Err = EmptyError;
137    const METHOD: Method = Method::Post;
138}
139
140/// Change your password.
141///
142/// # Responses
143///
144/// success - [`204 - No Content`](http::StatusCode::NO_CONTENT)
145///
146/// # Errors
147///
148/// If the user isn't authorized to change their password ([`403 - Forbidden`](http::StatusCode::FORBIDDEN))
149pub struct ChangePassword;
150impl ApiEndpoint for ChangePassword {
151    type Req = ChangePasswordRequest;
152    type Res = ();
153    type Path = ChangePasswordPath;
154    type Err = EmptyError;
155    const METHOD: Method = Method::Put;
156}
157
158/// Find a user by username.
159pub struct UserLookup;
160impl ApiEndpoint for UserLookup {
161    type Req = UserLookupQuery;
162    type Res = OtherUser;
163    type Path = UserLookupPath;
164    type Err = EmptyError;
165    const METHOD: Method = Method::Get;
166}
167
168/// Delete your account.
169pub struct Delete;
170impl ApiEndpoint for Delete {
171    type Req = ();
172    type Res = ();
173    type Path = UserDeletePath;
174    type Err = EmptyError;
175    const METHOD: Method = Method::Delete;
176}
177
178/// Browse for users.
179///
180/// # Errors
181///
182/// If the user isn't an Admin ([`403 - Forbidden`](http::StatusCode::FORBIDDEN))
183pub struct Browse;
184impl ApiEndpoint for Browse {
185    type Req = UserBrowseQuery;
186    type Res = UserBrowseResponse;
187    type Path = UserBrowsePath;
188    type Err = EmptyError;
189    const METHOD: Method = Method::Get;
190}
191
192/// Browse for users.
193///
194/// # Errors
195///
196/// If the user isn't an Admin ([`403 - Forbidden`](http::StatusCode::FORBIDDEN))
197pub struct SearchUser;
198impl ApiEndpoint for SearchUser {
199    type Req = UserSearchQuery;
200    type Res = UserSearchResponse;
201    type Path = UserSearchPath;
202    type Err = EmptyError;
203    const METHOD: Method = Method::Get;
204}