shared/api/endpoints/course.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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
//! Endpoints for Course
use crate::domain::course::{CourseAdminDataUpdatePath, CourseUpdateAdminDataRequest};
use crate::{
api::Method,
domain::{
course::{
CourseBrowsePath, CourseBrowseQuery, CourseBrowseResponse, CourseClonePath,
CourseCreatePath, CourseCreateRequest, CourseDeletePath, CourseGetDraftPath,
CourseGetLivePath, CourseId, CoursePlayPath, CoursePublishPath, CourseResponse,
CourseSearchPath, CourseSearchQuery, CourseSearchResponse, CourseUpdateDraftDataPath,
CourseUpdateDraftDataRequest,
},
CreateResponse,
},
error::{EmptyError, MetadataNotFound},
};
pub mod unit;
use super::ApiEndpoint;
/// Create a Course and it's draft and live data copies.
///
/// * New Courses are all set to `PrivacyLevel::Unlisted` by default
///
/// # Flow:
/// 1. Create a Course and its two data copies with [`Create`]
/// 2. Optionally update Course info such as privacy, author with [`Update`]
/// 3. Make updates to draft data:
/// a. Patch Course data through [`UpdateDraftData`]
/// 4. Finalize draft changes by calling [`Publish`]
///
/// # Authorization
/// * TokenUser
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset`
pub struct Create;
impl ApiEndpoint for Create {
type Req = CourseCreateRequest;
type Res = CreateResponse<CourseId>;
type Path = CourseCreatePath;
type Err = MetadataNotFound;
const METHOD: Method = Method::Post;
}
/// Get a Course's live data by ID.
///
/// # Authorization
/// * Creator ID of Course
/// * One of `Admin`, `AdminAsset`,, or `ManageSelfAsset` for owned Courses
///
/// # Errors
///
pub struct GetLive;
impl ApiEndpoint for GetLive {
type Req = ();
type Res = CourseResponse;
type Path = CourseGetLivePath;
type Err = EmptyError;
const METHOD: Method = Method::Get;
}
/// Get a Course's draft data by ID.
///
/// # Authorization
/// * Creator ID of Course
/// * One of `Admin`, `AdminAsset`,, or `ManageSelfAsset` for owned Courses
///
/// # Errors
/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
///
pub struct GetDraft;
impl ApiEndpoint for GetDraft {
type Req = ();
type Res = CourseResponse;
type Path = CourseGetDraftPath;
type Err = EmptyError;
const METHOD: Method = Method::Get;
}
/// Update the draft data of a Course.
///
/// Note that a copy of the Course's draft or live data can not be fetched directly, but only as a part
/// of one of the following routes:
/// * [`GetLive`] fetches live copies
/// * [`Search`]
///
/// See [`Course Data`](crate::domain::course::CourseData) for the over-the-wire representation.
///
/// # Authorization
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset` for owned Courses
pub struct UpdateDraftData;
impl ApiEndpoint for UpdateDraftData {
type Req = CourseUpdateDraftDataRequest;
type Res = ();
type Path = CourseUpdateDraftDataPath;
type Err = MetadataNotFound;
const METHOD: Method = Method::Patch;
}
/// Publish a Course draft to live by copying over the Coursedata.
///
/// # Authorization
/// * Creator ID of Course
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset`
pub struct Publish;
impl ApiEndpoint for Publish {
type Req = ();
type Res = ();
type Path = CoursePublishPath;
type Err = EmptyError;
const METHOD: Method = Method::Put;
}
/// Browse Courses. Returns the draft data copies in the response.
///
/// # Authorization
/// * None
pub struct Browse;
impl ApiEndpoint for Browse {
type Req = CourseBrowseQuery;
type Res = CourseBrowseResponse;
type Path = CourseBrowsePath;
type Err = EmptyError;
const METHOD: Method = Method::Get;
}
/// Search for Courses.
///
/// # Authorization
/// * None
pub struct Search;
impl ApiEndpoint for Search {
type Req = CourseSearchQuery;
type Res = CourseSearchResponse;
type Path = CourseSearchPath;
type Err = EmptyError;
const METHOD: Method = Method::Get;
}
/// Delete a Course.
///
/// # Authorization
/// * Creator ID of Course
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset` for owned Courses
pub struct Delete;
impl ApiEndpoint for Delete {
type Req = ();
type Res = ();
type Path = CourseDeletePath;
type Err = EmptyError;
const METHOD: Method = Method::Delete;
}
/// Clone a Course. This clones both the draft and live.
///
/// # Authorization
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset`
///
/// # Errors
/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
/// * ['NotFound'](http::StatusCode::NOT_FOUND) if the resource does not exist.
/// * ['BadRequest'](http::StatusCode::BAD_REQUEST) if the request is malformed or the Course is a draft.
pub struct Clone;
impl ApiEndpoint for Clone {
type Path = CourseClonePath;
type Req = ();
type Res = CreateResponse<CourseId>;
type Err = EmptyError;
const METHOD: Method = Method::Post;
}
/// Add to play count for a Course
///
/// # Authorization
/// * None
pub struct Play;
impl ApiEndpoint for Play {
type Req = ();
type Res = ();
type Path = CoursePlayPath;
type Err = EmptyError;
const METHOD: Method = Method::Put;
}
/// Update an admin data for a JIG.
///
/// # Authorization
///
/// * Standard + [`UserScope::AdminAsset`](crate::domain::user::UserScope)
///
/// # Errors
///
/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
/// * [`Forbidden`](http::StatusCode::FORBIDDEN) if the user does not have sufficient permission to perform the action.
/// * [`BadRequest`](http::StatusCode::BAD_REQUEST) if the request is missing/invalid.
pub struct CourseAdminDataUpdate;
impl ApiEndpoint for CourseAdminDataUpdate {
type Path = CourseAdminDataUpdatePath;
type Req = CourseUpdateAdminDataRequest;
type Res = ();
type Err = EmptyError;
const METHOD: Method = Method::Patch;
}