shared/api/endpoints/
category.rs

1use super::ApiEndpoint;
2use crate::{
3    api::method::Method,
4    domain::category::{
5        CategoryResponse, CreateCategoryPath, CreateCategoryRequest, DeleteCategoryPath,
6        GetCategoryPath, GetCategoryRequest, NewCategoryResponse, UpdateCategoryPath,
7        UpdateCategoryRequest,
8    },
9    error::EmptyError,
10};
11
12/// Get a tree of categories.
13///
14/// # Authorization
15/// No authorization required.
16pub struct Get;
17impl ApiEndpoint for Get {
18    type Path = GetCategoryPath;
19    type Req = GetCategoryRequest;
20    type Res = CategoryResponse;
21    type Err = EmptyError;
22    const METHOD: Method = Method::Get;
23}
24
25/// Create a category.
26///
27/// # Authorization
28/// Standard + [`UserScope::ManageCategory`](crate::domain::user::UserScope).
29pub struct Create;
30impl ApiEndpoint for Create {
31    type Path = CreateCategoryPath;
32    type Req = CreateCategoryRequest;
33    type Res = NewCategoryResponse;
34    type Err = EmptyError;
35    const METHOD: Method = Method::Post;
36}
37
38/// Update a category.
39///
40/// # Authorization
41/// Standard + [`UserScope::ManageCategory`](crate::domain::user::UserScope).
42pub struct Update;
43impl ApiEndpoint for Update {
44    type Path = UpdateCategoryPath;
45    type Req = UpdateCategoryRequest;
46    type Res = ();
47    type Err = EmptyError;
48    const METHOD: Method = Method::Patch;
49}
50
51/// Delete a category.
52///
53/// # Authorization
54/// Standard + [`UserScope::ManageCategory`](crate::domain::user::UserScope).
55pub struct Delete;
56impl ApiEndpoint for Delete {
57    type Path = DeleteCategoryPath;
58    type Req = ();
59    type Res = ();
60    type Err = EmptyError;
61    const METHOD: Method = Method::Delete;
62}