feat: add update_meta to SongRepositoryPort and PATCH /songs/{id}
This commit is contained in:
@@ -48,12 +48,36 @@ pub async fn list_songs(
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { error: e.to_string() })))
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct UpdateSongRequest {
|
||||
pub title: Option<String>,
|
||||
pub artist: Option<String>,
|
||||
pub original_key: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn update_song(
|
||||
State(_state): State<Arc<AppState>>,
|
||||
Path(_id): Path<String>,
|
||||
Json(_body): Json<serde_json::Value>,
|
||||
) -> StatusCode {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
State(state): State<Arc<AppState>>,
|
||||
Path(id): Path<String>,
|
||||
Json(body): Json<UpdateSongRequest>,
|
||||
) -> Result<Json<domain::SongSummary>, (StatusCode, Json<ErrorResponse>)> {
|
||||
let uuid = Uuid::parse_str(&id).map_err(|_| {
|
||||
(StatusCode::BAD_REQUEST, Json(ErrorResponse { error: "Invalid ID".into() }))
|
||||
})?;
|
||||
|
||||
state.songs
|
||||
.update_meta(
|
||||
uuid,
|
||||
body.title.as_deref(),
|
||||
body.artist.as_deref(),
|
||||
body.original_key.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map(Json)
|
||||
.map_err(|e| match e {
|
||||
domain::RepositoryError::NotFound =>
|
||||
(StatusCode::NOT_FOUND, Json(ErrorResponse { error: "Not found".into() })),
|
||||
e => (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { error: e.to_string() })),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn get_song(
|
||||
|
||||
Reference in New Issue
Block a user