Files
k-photos/crates/presentation/src/handlers/storage.rs

38 lines
1.5 KiB
Rust

use crate::{errors::AppError, extractors::JwtClaims, state::AppState};
use api_types::{
requests::{RegisterLibraryPathRequest, RegisterVolumeRequest},
responses::{LibraryPathResponse, VolumeResponse},
};
use application::storage::{RegisterLibraryPathCommand, RegisterVolumeCommand};
use axum::{Json, extract::State, http::StatusCode};
use domain::value_objects::SystemId;
pub async fn register_volume(
State(state): State<AppState>,
_claims: JwtClaims,
Json(req): Json<RegisterVolumeRequest>,
) -> Result<(StatusCode, Json<VolumeResponse>), AppError> {
let cmd = RegisterVolumeCommand {
volume_name: req.volume_name,
uri_prefix: req.uri_prefix,
is_writable: req.is_writable,
};
let volume = state.register_volume_handler.execute(cmd).await?;
Ok((StatusCode::CREATED, Json(VolumeResponse::from_domain(&volume))))
}
pub async fn register_library_path(
State(state): State<AppState>,
_claims: JwtClaims,
Json(req): Json<RegisterLibraryPathRequest>,
) -> Result<(StatusCode, Json<LibraryPathResponse>), AppError> {
let cmd = RegisterLibraryPathCommand {
volume_id: SystemId::from_uuid(req.volume_id),
relative_path: req.relative_path,
owner_id: SystemId::from_uuid(req.owner_id),
is_ingest_destination: req.is_ingest_destination,
};
let path = state.register_library_path_handler.execute(cmd).await?;
Ok((StatusCode::CREATED, Json(LibraryPathResponse::from_domain(&path))))
}