Utoipa for search and playlist endpoints
This commit is contained in:
parent
350557785c
commit
b5a8aea1f8
2 changed files with 42 additions and 9 deletions
|
@ -3,7 +3,7 @@ use std::path::PathBuf;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{DefaultBodyLimit, Path, Query, State},
|
extract::{DefaultBodyLimit, Path, Query, State},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
routing::{delete, get, post, put},
|
routing::{get, post},
|
||||||
Json,
|
Json,
|
||||||
};
|
};
|
||||||
use axum_extra::headers::Range;
|
use axum_extra::headers::Range;
|
||||||
|
@ -58,12 +58,10 @@ pub fn router() -> OpenApiRouter<App> {
|
||||||
.route("/random", get(get_random_albums)) // Deprecated
|
.route("/random", get(get_random_albums)) // Deprecated
|
||||||
.route("/recent", get(get_recent_albums)) // Deprecated
|
.route("/recent", get(get_recent_albums)) // Deprecated
|
||||||
// Search
|
// Search
|
||||||
.route("/search/{*query}", get(get_search))
|
.routes(routes!(get_search))
|
||||||
// Playlist management
|
// Playlist management
|
||||||
.route("/playlists", get(get_playlists))
|
.routes(routes!(get_playlists))
|
||||||
.route("/playlist/{name}", put(put_playlist))
|
.routes(routes!(put_playlist, get_playlist, delete_playlist))
|
||||||
.route("/playlist/{name}", get(get_playlist))
|
|
||||||
.route("/playlist/{name}", delete(delete_playlist))
|
|
||||||
// Media
|
// Media
|
||||||
.route("/songs", post(get_songs)) // post because of https://github.com/whatwg/fetch/issues/551
|
.route("/songs", post(get_songs)) // post because of https://github.com/whatwg/fetch/issues/551
|
||||||
.route("/peaks/{*path}", get(get_peaks))
|
.route("/peaks/{*path}", get(get_peaks))
|
||||||
|
@ -763,6 +761,14 @@ async fn get_genre_songs(
|
||||||
Ok(Json(song_list))
|
Ok(Json(song_list))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/search/{*query}",
|
||||||
|
params(("query" = String, Path, allow_reserved)),
|
||||||
|
responses(
|
||||||
|
(status = 200, body = dto::SongList),
|
||||||
|
)
|
||||||
|
)]
|
||||||
async fn get_search(
|
async fn get_search(
|
||||||
_auth: Auth,
|
_auth: Auth,
|
||||||
api_version: APIMajorVersion,
|
api_version: APIMajorVersion,
|
||||||
|
@ -796,6 +802,13 @@ async fn get_search(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/playlists",
|
||||||
|
responses(
|
||||||
|
(status = 200, body = Vec<dto::PlaylistHeader>),
|
||||||
|
)
|
||||||
|
)]
|
||||||
async fn get_playlists(
|
async fn get_playlists(
|
||||||
auth: Auth,
|
auth: Auth,
|
||||||
State(playlist_manager): State<playlist::Manager>,
|
State(playlist_manager): State<playlist::Manager>,
|
||||||
|
@ -806,6 +819,12 @@ async fn get_playlists(
|
||||||
Ok(Json(playlists))
|
Ok(Json(playlists))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/playlist/{name}",
|
||||||
|
params(("name" = String, Path)),
|
||||||
|
request_body = dto::SavePlaylistInput,
|
||||||
|
)]
|
||||||
async fn put_playlist(
|
async fn put_playlist(
|
||||||
auth: Auth,
|
auth: Auth,
|
||||||
State(playlist_manager): State<playlist::Manager>,
|
State(playlist_manager): State<playlist::Manager>,
|
||||||
|
@ -825,6 +844,14 @@ async fn put_playlist(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/playlist/{name}",
|
||||||
|
params(("name" = String, Path)),
|
||||||
|
responses(
|
||||||
|
(status = 200, body = dto::Playlist),
|
||||||
|
)
|
||||||
|
)]
|
||||||
async fn get_playlist(
|
async fn get_playlist(
|
||||||
auth: Auth,
|
auth: Auth,
|
||||||
api_version: APIMajorVersion,
|
api_version: APIMajorVersion,
|
||||||
|
@ -850,6 +877,11 @@ async fn get_playlist(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/playlist/{name}",
|
||||||
|
params(("name" = String, Path)),
|
||||||
|
)]
|
||||||
async fn delete_playlist(
|
async fn delete_playlist(
|
||||||
auth: Auth,
|
auth: Auth,
|
||||||
State(playlist_manager): State<playlist::Manager>,
|
State(playlist_manager): State<playlist::Manager>,
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl From<peaks::Peaks> for Peaks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct PlaylistHeader {
|
pub struct PlaylistHeader {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub num_songs_by_genre: HashMap<String, u32>,
|
pub num_songs_by_genre: HashMap<String, u32>,
|
||||||
|
@ -94,15 +94,16 @@ impl From<playlist::PlaylistHeader> for PlaylistHeader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct Playlist {
|
pub struct Playlist {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub header: PlaylistHeader,
|
pub header: PlaylistHeader,
|
||||||
pub songs: SongList,
|
pub songs: SongList,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct SavePlaylistInput {
|
pub struct SavePlaylistInput {
|
||||||
|
#[schema(value_type = Vec<String>)]
|
||||||
pub tracks: Vec<PathBuf>,
|
pub tracks: Vec<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue