shared/api/endpoints/user/
profile.rs

1use crate::{
2    api::{ApiEndpoint, Method},
3    domain::{
4        session::NewSessionResponse,
5        user::{
6            CreateProfilePath, CreateProfileRequest, GetProfilePath, PatchProfileAdminDataPath,
7            PatchProfileAdminDataRequest, PatchProfilePath, PatchProfileRequest, UserProfile,
8        },
9    },
10    error::EmptyError,
11};
12
13/// Fetch your own user profile.
14pub struct Get;
15impl ApiEndpoint for Get {
16    type Path = GetProfilePath;
17    type Req = ();
18    type Res = UserProfile;
19    type Err = EmptyError;
20    const METHOD: Method = Method::Get;
21}
22
23/// Create or replace a user profile.
24///
25/// # Flow
26/// *
27/// *
28///
29/// # Errors
30/// * Invalid request - [`400 - Bad Request`](http::StatusCode::BAD_REQUEST)
31/// * Missing / bad auth - [`401 - Unauthorized`](http::StatusCode::UNAUTHORIZED)
32/// * User not found - [`404 - Not Found`](http::StatusCode::NOT_FOUND)
33/// * Profile image with ID not found - [`404 - Not Found`](http::StatusCode::NOT_FOUND)
34/// * Taken username - [`409 - Conflict`](http::StatusCode::CONFLICT)
35/// * Empty username - [`422 - Unprocessable Entity`](http::StatusCode::UNPROCESSABLE_ENTITY)
36pub struct Create;
37impl ApiEndpoint for Create {
38    type Path = CreateProfilePath;
39    type Req = CreateProfileRequest;
40    type Res = NewSessionResponse;
41    type Err = EmptyError;
42    const METHOD: Method = Method::Post;
43}
44
45/// Update a user profile.
46///
47/// # Errors
48///
49/// * Invalid request - [`400 - Bad Request`](http::StatusCode::BAD_REQUEST)
50/// * Missing / bad auth - [`401 - Unauthorized`](http::StatusCode::UNAUTHORIZED)
51/// * Taken username - [`409 - Conflict`](http::StatusCode::CONFLICT)
52/// * Empty username - [`422 - Unprocessable Entity`](http::StatusCode::UNPROCESSABLE_ENTITY)
53pub struct Patch;
54impl ApiEndpoint for Patch {
55    type Path = PatchProfilePath;
56    type Req = PatchProfileRequest;
57    type Res = ();
58    type Err = EmptyError;
59    const METHOD: Method = Method::Patch;
60}
61
62/// Update a user profile data that only an admin can update. E.g. badge.
63pub struct PatchProfileAdminData;
64impl ApiEndpoint for PatchProfileAdminData {
65    type Path = PatchProfileAdminDataPath;
66    type Req = PatchProfileAdminDataRequest;
67    type Res = ();
68    type Err = EmptyError;
69    const METHOD: Method = Method::Patch;
70}