shared/api/endpoints/course/
unit.rs

1//! Endpoints for CourseUnit
2use crate::{
3    api::Method,
4    domain::{
5        course::unit::{
6            CourseUnit, CourseUnitCreateRequest, CourseUnitId, CourseUnitUpdateRequest,
7            CreateCourseUnitPath, DeleteCourseUnitPath, GetCourseUnitDraftPath,
8            GetCourseUnitLivePath, UpdateCourseUnitPath,
9        },
10        CreateResponse,
11    },
12    error::EmptyError,
13};
14
15use super::ApiEndpoint;
16
17/// Get an Course Unit on a draft Course
18///
19/// # Authorization
20/// Standard
21///
22/// # Errors
23///
24/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
25/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the Course Unit or the parent Course doesn't exist.
26pub struct GetDraft;
27impl ApiEndpoint for GetDraft {
28    type Req = ();
29    type Res = CourseUnit;
30    type Path = GetCourseUnitDraftPath;
31    type Err = EmptyError;
32    const METHOD: Method = Method::Get;
33}
34
35/// Get an Course Unit on a live Course
36///
37/// # Authorization
38/// Standard
39///
40/// # Errors
41///
42/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
43/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the Course Unit or the parent Course doesn't exist.
44pub struct GetLive;
45impl ApiEndpoint for GetLive {
46    type Req = ();
47    type Res = CourseUnit;
48    type Path = GetCourseUnitLivePath;
49    type Err = EmptyError;
50    const METHOD: Method = Method::Get;
51}
52
53/// Add a Course Unit to a draft Course.
54///
55/// # Authorization
56///
57/// * Standard + [`UserScope::ManageJig`](crate::domain::user::UserScope)
58///
59/// # Errors
60///
61/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
62/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
63/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the request is missing/invalid.
64pub struct Create;
65impl ApiEndpoint for Create {
66    type Path = CreateCourseUnitPath;
67    type Req = CourseUnitCreateRequest;
68    type Res = CreateResponse<CourseUnitId>;
69    type Err = EmptyError;
70    const METHOD: Method = Method::Post;
71}
72
73/// Update an Course Units to a draft Course.
74///
75/// # Authorization
76///
77/// * Standard + [`UserScope::ManageJig`](crate::domain::user::UserScope)
78///
79/// # Errors
80///
81/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
82/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
83/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the request is missing/invalid.
84pub struct Update;
85impl ApiEndpoint for Update {
86    type Path = UpdateCourseUnitPath;
87    type Req = CourseUnitUpdateRequest;
88    type Res = ();
89    type Err = EmptyError;
90    const METHOD: Method = Method::Patch;
91}
92
93/// Delete an Course Unit from a draft Course.
94///
95/// # Authorization
96///
97/// * Standard + [`UserScope::ManageJig`](crate::domain::user::UserScope)
98///
99/// # Errors
100///
101/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
102/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
103/// * [`NotFound`](http::StatusCode::NOT_FOUND) if the Course Unit or parent Course does not exist.
104/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the given `id` is not a [`Uuid`](uuid::Uuid) or the request is missing/invalid.
105pub struct Delete;
106impl ApiEndpoint for Delete {
107    type Req = ();
108    type Res = ();
109    type Path = DeleteCourseUnitPath;
110    type Err = EmptyError;
111    const METHOD: Method = Method::Delete;
112}