添加接口
All checks were successful
Go CI / test-and-build (push) Successful in 11s

This commit is contained in:
2026-04-07 16:38:59 +08:00
parent 02efb9972a
commit 9aec254f23
4 changed files with 67 additions and 4 deletions

View File

@@ -275,6 +275,17 @@ func (r *LibraryRepository) GetArtists() ([]model.Artist, error) {
return artists, nil
}
func (r *LibraryRepository) GetArtist(id int) (model.Artist, error) {
row := r.db.QueryRow("SELECT id, name FROM artists WHERE id = ?", id)
var artist model.Artist
if err := row.Scan(&artist.ID, &artist.Name); err != nil {
return model.Artist{}, err
}
return artist, nil
}
func (r *LibraryRepository) GetAlbums() ([]model.Album, error) {
rows, err := r.db.Query("SELECT id, title, artist_id FROM albums")
if err != nil {
@@ -292,3 +303,13 @@ func (r *LibraryRepository) GetAlbums() ([]model.Album, error) {
}
return albums, nil
}
func (r *LibraryRepository) GetAlbum(id int) (model.Album, error) {
row := r.db.QueryRow("SELECT id, title, artist_id FROM albums WHERE id = ?", id)
var album model.Album
if err := row.Scan(&album.ID, &album.Title, &album.ArtistID); err != nil {
return model.Album{}, err
}
return album, nil
}