shared/api/endpoints/
module.rs

1use super::ApiEndpoint;
2use crate::{
3    api::Method,
4    domain::module::{
5        LiteModule, ModuleCreatePath, ModuleCreateRequest, ModuleDeletePath, ModuleDeleteRequest,
6        ModuleGetDraftPath, ModuleGetLivePath, ModuleResponse, ModuleUpdateRequest,
7        ModuleUploadPath,
8    },
9    error::EmptyError,
10};
11
12/// Get a Module by it's concrete ID.
13///
14/// # Authorization
15/// No authorization required.
16///
17/// # Errors
18/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the module does not exist, or the parent jig doesn't exist.
19pub struct GetLive;
20impl ApiEndpoint for GetLive {
21    type Path = ModuleGetLivePath;
22    type Req = ();
23    type Res = ModuleResponse;
24    type Err = EmptyError;
25    const METHOD: Method = Method::Get;
26}
27
28/// Get a Module by it's concrete ID.
29///
30/// # Authorization
31/// * One of `Admin`, `AdminJig`,, or `ManageSelfAsset` for owned JIGs or Playlists
32///
33/// # Errors
34/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
35/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the module does not exist, or the parent jig doesn't exist.
36pub struct GetDraft;
37impl ApiEndpoint for GetDraft {
38    type Path = ModuleGetDraftPath;
39    type Req = ();
40    type Res = ModuleResponse;
41    type Err = EmptyError;
42    const METHOD: Method = Method::Get;
43}
44
45/// Create a Module.
46///
47/// # Authorization
48/// Standard + [`UserScope::ManageJig`](crate::domain::user::UserScope).
49///
50/// # Errors
51///
52/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
53/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
54/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the request is missing/invalid.
55pub struct Create;
56impl ApiEndpoint for Create {
57    type Path = ModuleCreatePath;
58    type Req = ModuleCreateRequest;
59    type Res = LiteModule;
60    type Err = EmptyError;
61    const METHOD: Method = Method::Post;
62}
63
64/// Update a Module.
65///
66/// # Authorization
67/// Standard + [`UserScope::ManageJig`](crate::domain::user::UserScope).
68///
69/// # Errors
70///
71/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
72/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
73/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the given `id` is not a [`Uuid`](uuid::Uuid) or the request is missing/invalid.
74/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the jig or module does not exist.
75pub struct Update;
76impl ApiEndpoint for Update {
77    type Path = ModuleUploadPath;
78    type Req = ModuleUpdateRequest;
79    type Res = ();
80    type Err = EmptyError;
81    const METHOD: Method = Method::Patch;
82}
83
84/// Delete a Module.
85///
86/// # Authorization
87/// Standard + [`UserScope::ManageJig`](crate::domain::user::UserScope).
88///
89/// # Errors
90///
91/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
92/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
93/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the jig or module does not exist.
94/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the given `id` is not a [`Uuid`](uuid::Uuid).
95pub struct Delete;
96impl ApiEndpoint for Delete {
97    type Path = ModuleDeletePath;
98    type Req = ModuleDeleteRequest;
99    type Res = ();
100    type Err = EmptyError;
101    const METHOD: Method = Method::Delete;
102}