shared/api/endpoints/
playlist.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
use crate::{
    api::Method,
    domain::{
        playlist::{
            ListLikedPath, ListLikedRequest, ListLikedResponse, PlaylistAdminDataUpdatePath,
            PlaylistBrowsePath, PlaylistBrowseQuery, PlaylistBrowseResponse, PlaylistClonePath,
            PlaylistCreatePath, PlaylistCreateRequest, PlaylistDeletePath, PlaylistGetDraftPath,
            PlaylistGetLivePath, PlaylistId, PlaylistLikePath, PlaylistLikedPath,
            PlaylistLikedResponse, PlaylistPublishPath, PlaylistResponse, PlaylistSearchPath,
            PlaylistSearchQuery, PlaylistSearchResponse, PlaylistUnlikePath,
            PlaylistUpdateAdminDataRequest, PlaylistUpdateDraftDataPath,
            PlaylistUpdateDraftDataRequest, PlaylistViewPath,
        },
        CreateResponse,
    },
    error::{EmptyError, MetadataNotFound},
};

use super::ApiEndpoint;

/// Create a Playlist and it's draft and live data copies.
///
/// * New Playlists are all set to `PrivacyLevel::Unlisted` by default
///
/// # Flow:
/// 1. Create a Playlist and its two data copies with [`Create`]
/// 2. Optionally update Playlist info such as privacy, author with [`Update`]
/// 3. Make updates to draft data:
///     a. Patch Playlist 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 = PlaylistCreateRequest;
    type Res = CreateResponse<PlaylistId>;
    type Path = PlaylistCreatePath;
    type Err = MetadataNotFound;
    const METHOD: Method = Method::Post;
}

/// Get a Playlist's live data by ID.
///
/// # Authorization
/// * Creator ID of Playlist
/// * One of `Admin`, `AdminAsset`,, or `ManageSelfAsset` for owned Playlists
///
/// # Errors
///
pub struct GetLive;
impl ApiEndpoint for GetLive {
    type Req = ();
    type Res = PlaylistResponse;
    type Path = PlaylistGetLivePath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Get a Playlist's draft data by ID.
///
/// # Authorization
/// * Creator ID of Playlist
/// * One of `Admin`, `AdminAsset`,, or `ManageSelfAsset` for owned Playlists
///
/// # Errors
/// * [`Unauthorized`](http::StatusCode::UNAUTHORIZED) if authorization is not valid.
///
pub struct GetDraft;
impl ApiEndpoint for GetDraft {
    type Req = ();
    type Res = PlaylistResponse;
    type Path = PlaylistGetDraftPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Update the draft data of a Playlist.
///
/// Note that a copy of the Playlist'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 [`Playlist Data`](crate::domain::playlist::PlaylistData) for the over-the-wire representation.
///
/// # Authorization
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset` for owned Playlists
pub struct UpdateDraftData;
impl ApiEndpoint for UpdateDraftData {
    type Req = PlaylistUpdateDraftDataRequest;
    type Res = ();
    type Path = PlaylistUpdateDraftDataPath;
    type Err = MetadataNotFound;
    const METHOD: Method = Method::Patch;
}

/// Publish a Playlist draft to live by copying over the Playlistdata.
///
/// # Authorization
/// * Creator ID of Playlist
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset`
pub struct Publish;
impl ApiEndpoint for Publish {
    type Req = ();
    type Res = ();
    type Path = PlaylistPublishPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Put;
}

/// Browse Playlists. Returns the draft data copies in the response.
///
/// # Authorization
/// * None
pub struct Browse;
impl ApiEndpoint for Browse {
    type Req = PlaylistBrowseQuery;
    type Res = PlaylistBrowseResponse;
    type Path = PlaylistBrowsePath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Search for Playlists.
///
/// # Authorization
/// * None
pub struct Search;
impl ApiEndpoint for Search {
    type Req = PlaylistSearchQuery;
    type Res = PlaylistSearchResponse;
    type Path = PlaylistSearchPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Delete a Playlist.
///
/// # Authorization
/// * Creator ID of Playlist
/// * One of `Admin`, `AdminAsset`, or `ManageSelfAsset` for owned Playlists
pub struct Delete;
impl ApiEndpoint for Delete {
    type Req = ();
    type Res = ();
    type Path = PlaylistDeletePath;
    type Err = EmptyError;
    const METHOD: Method = Method::Delete;
}

/// Clone a Playlist. 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 Playlist is a draft.
pub struct Clone;
impl ApiEndpoint for Clone {
    type Path = PlaylistClonePath;
    type Req = ();
    type Res = CreateResponse<PlaylistId>;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Like a Playlist
///
/// # Authorization
/// * Admin, BasicAuth
pub struct Like;
impl ApiEndpoint for Like {
    type Path = PlaylistLikePath;
    type Req = ();
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Put;
}

/// Unlike a Playlist
///
/// # Authorization
/// * Admin, BasicAuth
pub struct Unlike;
impl ApiEndpoint for Unlike {
    type Path = PlaylistUnlikePath;
    type Req = ();
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Delete;
}

/// List user's liked Playlists.
pub struct ListLiked;
impl ApiEndpoint for ListLiked {
    type Req = ListLikedRequest;
    type Res = ListLikedResponse;
    type Path = ListLikedPath;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Is a Playlist liked by a user
///
/// # Authorization
/// * Admin, BasicAuth
pub struct Liked;
impl ApiEndpoint for Liked {
    type Path = PlaylistLikedPath;
    type Req = ();
    type Res = PlaylistLikedResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// View a Playlist
///
/// # Authorization
/// * None
pub struct View;
impl ApiEndpoint for View {
    type Path = PlaylistViewPath;
    type Req = ();
    type Res = ();
    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 PlaylistAdminDataUpdate;
impl ApiEndpoint for PlaylistAdminDataUpdate {
    type Path = PlaylistAdminDataUpdatePath;
    type Req = PlaylistUpdateAdminDataRequest;
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Patch;
}