shared/api/endpoints/
category.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
use super::ApiEndpoint;
use crate::{
    api::method::Method,
    domain::category::{
        CategoryResponse, CreateCategoryPath, CreateCategoryRequest, DeleteCategoryPath,
        GetCategoryPath, GetCategoryRequest, NewCategoryResponse, UpdateCategoryPath,
        UpdateCategoryRequest,
    },
    error::EmptyError,
};

/// Get a tree of categories.
///
/// # Authorization
/// No authorization required.
pub struct Get;
impl ApiEndpoint for Get {
    type Path = GetCategoryPath;
    type Req = GetCategoryRequest;
    type Res = CategoryResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Create a category.
///
/// # Authorization
/// Standard + [`UserScope::ManageCategory`](crate::domain::user::UserScope).
pub struct Create;
impl ApiEndpoint for Create {
    type Path = CreateCategoryPath;
    type Req = CreateCategoryRequest;
    type Res = NewCategoryResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Update a category.
///
/// # Authorization
/// Standard + [`UserScope::ManageCategory`](crate::domain::user::UserScope).
pub struct Update;
impl ApiEndpoint for Update {
    type Path = UpdateCategoryPath;
    type Req = UpdateCategoryRequest;
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Patch;
}

/// Delete a category.
///
/// # Authorization
/// Standard + [`UserScope::ManageCategory`](crate::domain::user::UserScope).
pub struct Delete;
impl ApiEndpoint for Delete {
    type Path = DeleteCategoryPath;
    type Req = ();
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Delete;
}