shared/api/endpoints/
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
use super::ApiEndpoint;

use crate::{
    api::method::Method,
    domain::{
        session::NewSessionResponse,
        user::{
            ChangePasswordPath, ChangePasswordRequest, CreateUserPath, CreateUserRequest,
            OtherUser, ResetEmailPath, ResetEmailRequest, ResetEmailResponse, ResetPasswordPath,
            ResetPasswordRequest, UserBrowsePath, UserBrowseQuery, UserBrowseResponse,
            UserDeletePath, UserLookupPath, UserLookupQuery, UserSearchPath, UserSearchQuery,
            UserSearchResponse, VerifyEmailPath, VerifyEmailRequest, VerifyResetEmailPath,
            VerifyResetEmailRequest,
        },
    },
    error::EmptyError,
};

mod colors;
mod fonts;
mod profile;
mod public_user;

pub use colors::{
    Create as CreateColor, Delete as DeleteColor, Get as GetColors, Update as UpdateColor,
};

pub use fonts::{
    Create as CreateFont, Delete as DeleteFont, Get as GetFonts, Update as UpdateFont,
};

pub use profile::{
    Create as CreateProfile, Get as Profile, Patch as PatchProfile, PatchProfileAdminData,
};

pub use public_user::{
    BrowseFollowers, BrowseFollowing, BrowsePublicUser, BrowseUserJigs,
    BrowseUserPlaylists as BrowsePlaylists, BrowseUserResources as BrowseResources, Follow,
    Get as GetPublicUser, SearchPublicUser as Search, Unfollow,
};

/// Create a new user.
///
/// # Flow
/// 1. `POST` to this route
///     * recieve one of:
///         1. email gets sent to the user - [`204 - No Content`](http::StatusCode::NO_CONTENT)
///         2. email already exists - [`409 - Conflict`](http::StatusCode::CONFLICT)
///             * In the future this may contain information about *how* the email is registered.
/// 2. [`POST /v1/user/verify-email`](VerifyEmail)
/// 3. [`POST /v1/user/me/profile`](profile::Create)
pub struct Create;
impl ApiEndpoint for Create {
    type Req = CreateUserRequest;
    type Res = ();
    type Path = CreateUserPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Verify a user's email.
///
/// # Register Flow
/// 1. [`POST /v1/user`](Create)
///     * This will send the email for verification
/// 2. `POST` this route with the Verify request.
///     * recieve one of:
///         1. a 200 ([`NewSessionResponse`])
///         2. a 401 response (`<token>` is invalid)
///
/// # Change email Flow (NOT CURRENTLY IMPLEMENTED)
/// 1. `PUT /v1/user/me/email`
///     * this will send an email to verify the *old* address
/// 2. `POST` this route with the token from the email
///     * this will send an email to verify the *new* address
/// 3. `POST` this route *again* with the token from the new address
///     * The new email will get set at this point, recieve one of:
///         1. a 204 (success!)
///         2. a 401 response (`token` is invalid)
///
/// # Resend verification email
/// 1. `POST` this route with no auth and [`Resend`](VerifyEmailRequest::Resend)
///     * this resend will the verification email
///     * this will *always* return a 204 on success.
/// 2. Continue the flow you were in.
///
/// If no verification is in progress, no email will be sent.
pub struct VerifyEmail;
impl ApiEndpoint for VerifyEmail {
    type Req = VerifyEmailRequest;
    type Res = Option<NewSessionResponse>;
    type Path = VerifyEmailPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// verifies the updated email for a user
pub struct VerifyResetEmail;
impl ApiEndpoint for VerifyResetEmail {
    type Req = VerifyResetEmailRequest;
    type Res = ();
    type Path = VerifyResetEmailPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Resets user email
///
/// # Flow
/// 1. `POST` to this route
///     * recieve one of:
///         1. email gets sent to the user - [`204 - No Content`](http::StatusCode::NO_CONTENT)
///         2. email already exists - [`409 - Conflict`](http::StatusCode::CONFLICT)
/// 2. [`PATCH /v1/user/reset-email`](ResetEmail)
pub struct ResetEmail;
impl ApiEndpoint for ResetEmail {
    type Req = ResetEmailRequest;
    type Res = ResetEmailResponse;
    type Path = ResetEmailPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Patch;
}

/// Reset a user's password.
///
/// # Flow
/// 1. `POST` This route.
///      * email gets sent to the included email address
///      * recieve [`204 - No Content`](http::StatusCode::NO_CONTENT)
/// 2. [`PUT /v1/user/me/password`](ChangePassword)
pub struct ResetPassword;
impl ApiEndpoint for ResetPassword {
    type Req = ResetPasswordRequest;
    type Res = ();
    type Path = ResetPasswordPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Change your password.
///
/// # Responses
///
/// success - [`204 - No Content`](http::StatusCode::NO_CONTENT)
///
/// # Errors
///
/// If the user isn't authorized to change their password ([`403 - Forbidden`](http::StatusCode::FORBIDDEN))
pub struct ChangePassword;
impl ApiEndpoint for ChangePassword {
    type Req = ChangePasswordRequest;
    type Res = ();
    type Path = ChangePasswordPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Put;
}

/// Find a user by username.
pub struct UserLookup;
impl ApiEndpoint for UserLookup {
    type Req = UserLookupQuery;
    type Res = OtherUser;
    type Path = UserLookupPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Delete your account.
pub struct Delete;
impl ApiEndpoint for Delete {
    type Req = ();
    type Res = ();
    type Path = UserDeletePath;
    type Err = EmptyError;
    const METHOD: Method = Method::Delete;
}

/// Browse for users.
///
/// # Errors
///
/// If the user isn't an Admin ([`403 - Forbidden`](http::StatusCode::FORBIDDEN))
pub struct Browse;
impl ApiEndpoint for Browse {
    type Req = UserBrowseQuery;
    type Res = UserBrowseResponse;
    type Path = UserBrowsePath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Browse for users.
///
/// # Errors
///
/// If the user isn't an Admin ([`403 - Forbidden`](http::StatusCode::FORBIDDEN))
pub struct SearchUser;
impl ApiEndpoint for SearchUser {
    type Req = UserSearchQuery;
    type Res = UserSearchResponse;
    type Path = UserSearchPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}