34 lines
808 B
Rust
34 lines
808 B
Rust
use axum::{
|
|
Json, Router,
|
|
extract::{Path, State},
|
|
routing::get,
|
|
};
|
|
use uuid::Uuid;
|
|
|
|
use crate::{
|
|
error::ApiError,
|
|
schema::{AlbumResponse, MediaResponse, PublicAlbumBundleResponse},
|
|
state::AppState,
|
|
};
|
|
|
|
pub fn public_routes() -> Router<AppState> {
|
|
Router::new().route("/public/albums/{id}", get(get_public_album))
|
|
}
|
|
|
|
async fn get_public_album(
|
|
State(state): State<AppState>,
|
|
Path(album_id): Path<Uuid>,
|
|
) -> Result<Json<PublicAlbumBundleResponse>, ApiError> {
|
|
let bundle = state
|
|
.album_service
|
|
.get_public_album_bundle(album_id)
|
|
.await?;
|
|
|
|
let response = PublicAlbumBundleResponse {
|
|
album: AlbumResponse::from(bundle.album),
|
|
media: bundle.media.into_iter().map(MediaResponse::from).collect(),
|
|
};
|
|
|
|
Ok(Json(response))
|
|
}
|