single song watching
This commit is contained in:
@@ -21,8 +21,16 @@ pub struct SearchParams {
|
||||
offset: u64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct WatchTrackRequest {
|
||||
artist: Option<String>,
|
||||
title: Option<String>,
|
||||
mbid: Option<String>,
|
||||
}
|
||||
|
||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::resource("/tracks").route(web::get().to(list_tracks)))
|
||||
cfg.service(web::resource("/tracks/watch").route(web::post().to(watch_track)))
|
||||
.service(web::resource("/tracks").route(web::get().to(list_tracks)))
|
||||
.service(web::resource("/tracks/{id}").route(web::get().to(get_track)));
|
||||
}
|
||||
|
||||
@@ -50,3 +58,32 @@ async fn get_track(
|
||||
let track = queries::tracks::get_by_id(state.db.conn(), id).await?;
|
||||
Ok(HttpResponse::Ok().json(track))
|
||||
}
|
||||
|
||||
async fn watch_track(
|
||||
state: web::Data<AppState>,
|
||||
session: Session,
|
||||
body: web::Json<WatchTrackRequest>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let (user_id, _, _) = auth::require_auth(&session)?;
|
||||
if body.title.is_none() && body.mbid.is_none() {
|
||||
return Err(ApiError::BadRequest(
|
||||
"provide title or recording mbid".into(),
|
||||
));
|
||||
}
|
||||
let entry = shanty_watch::add_track(
|
||||
state.db.conn(),
|
||||
body.artist.as_deref(),
|
||||
body.title.as_deref(),
|
||||
body.mbid.as_deref(),
|
||||
&state.mb_client,
|
||||
Some(user_id),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
"id": entry.id,
|
||||
"status": entry.status,
|
||||
"name": entry.name,
|
||||
"artist_name": entry.artist_name,
|
||||
})))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user