Added merge
This commit is contained in:
@@ -430,6 +430,56 @@ pub async fn retry_merge(State(state): State<S>, Path(id): Path<Uuid>) -> impl I
|
||||
}
|
||||
}
|
||||
|
||||
// --- Library search ---
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct LibraryQuery {
|
||||
#[serde(default)]
|
||||
pub q: String,
|
||||
#[serde(default)]
|
||||
pub artist: String,
|
||||
#[serde(default)]
|
||||
pub album: String,
|
||||
#[serde(default = "default_lib_limit")]
|
||||
pub limit: i64,
|
||||
#[serde(default)]
|
||||
pub offset: i64,
|
||||
}
|
||||
fn default_lib_limit() -> i64 { 50 }
|
||||
|
||||
pub async fn library_tracks(State(state): State<S>, Query(q): Query<LibraryQuery>) -> impl IntoResponse {
|
||||
let (tracks, total) = tokio::join!(
|
||||
db::search_tracks(&state.pool, &q.q, &q.artist, &q.album, q.limit, q.offset),
|
||||
db::count_tracks(&state.pool, &q.q, &q.artist, &q.album),
|
||||
);
|
||||
match (tracks, total) {
|
||||
(Ok(rows), Ok(n)) => (StatusCode::OK, Json(serde_json::json!({"total": n, "items": rows}))).into_response(),
|
||||
(Err(e), _) | (_, Err(e)) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn library_albums(State(state): State<S>, Query(q): Query<LibraryQuery>) -> impl IntoResponse {
|
||||
let (albums, total) = tokio::join!(
|
||||
db::search_albums(&state.pool, &q.q, &q.artist, q.limit, q.offset),
|
||||
db::count_albums(&state.pool, &q.q, &q.artist),
|
||||
);
|
||||
match (albums, total) {
|
||||
(Ok(rows), Ok(n)) => (StatusCode::OK, Json(serde_json::json!({"total": n, "items": rows}))).into_response(),
|
||||
(Err(e), _) | (_, Err(e)) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn library_artists(State(state): State<S>, Query(q): Query<LibraryQuery>) -> impl IntoResponse {
|
||||
let (artists, total) = tokio::join!(
|
||||
db::search_artists_lib(&state.pool, &q.q, q.limit, q.offset),
|
||||
db::count_artists_lib(&state.pool, &q.q),
|
||||
);
|
||||
match (artists, total) {
|
||||
(Ok(rows), Ok(n)) => (StatusCode::OK, Json(serde_json::json!({"total": n, "items": rows}))).into_response(),
|
||||
(Err(e), _) | (_, Err(e)) => error_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
fn error_response(status: StatusCode, message: &str) -> axum::response::Response {
|
||||
|
||||
Reference in New Issue
Block a user