feat: Add public album routes and enhance authorization checks for media and albums
This commit is contained in:
33
libertas_api/src/handlers/public_handlers.rs
Normal file
33
libertas_api/src/handlers/public_handlers.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user