Improved admin UI
This commit is contained in:
@@ -837,6 +837,12 @@ pub struct AlbumTrackRow {
|
||||
pub genre: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn set_album_tracks_genre(pool: &PgPool, album_id: i64, genre: &str) -> Result<(), sqlx::Error> {
|
||||
sqlx::query("UPDATE tracks SET genre = $2 WHERE album_id = $1")
|
||||
.bind(album_id).bind(genre).execute(pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_album_details(pool: &PgPool, id: i64) -> Result<Option<AlbumDetails>, sqlx::Error> {
|
||||
let row: Option<(i64, String, Option<i32>, i64, String)> = sqlx::query_as(
|
||||
"SELECT a.id, a.name, a.year, ar.id, ar.name FROM albums a JOIN artists ar ON ar.id=a.artist_id WHERE a.id=$1"
|
||||
@@ -873,6 +879,14 @@ pub async fn get_album_cover(pool: &PgPool, album_id: i64) -> Result<Option<(Str
|
||||
Ok(row)
|
||||
}
|
||||
|
||||
/// Returns the storage_path of the first track in an album (for embedded cover fallback).
|
||||
pub async fn get_album_first_track_path(pool: &PgPool, album_id: i64) -> Result<Option<String>, sqlx::Error> {
|
||||
let row: Option<(String,)> = sqlx::query_as(
|
||||
"SELECT storage_path FROM tracks WHERE album_id=$1 ORDER BY track_number NULLS LAST, title LIMIT 1"
|
||||
).bind(album_id).fetch_optional(pool).await?;
|
||||
Ok(row.map(|(p,)| p))
|
||||
}
|
||||
|
||||
pub async fn get_artist_by_id(pool: &PgPool, id: i64) -> Result<Option<Artist>, sqlx::Error> {
|
||||
sqlx::query_as::<_, Artist>("SELECT id, name, hidden FROM artists WHERE id=$1")
|
||||
.bind(id).fetch_optional(pool).await
|
||||
|
||||
Reference in New Issue
Block a user