feat: add album management endpoints (sections 2.1, 2.2, 2.3)
This commit is contained in:
@@ -274,6 +274,93 @@ func (e *TestEnv) CountAlbumsByArtist(ctx context.Context, foreignArtistID strin
|
||||
return count, err
|
||||
}
|
||||
|
||||
// GetAlbumByID retrieves an album by its UUID.
|
||||
func (e *TestEnv) GetAlbumByID(ctx context.Context, albumID string) (map[string]any, error) {
|
||||
var id, title string
|
||||
var foreignAlbumID, albumType *string
|
||||
var releaseDate *time.Time
|
||||
var monitored bool
|
||||
|
||||
err := e.DB.QueryRow(ctx, `
|
||||
SELECT id, foreign_album_id, title, album_type, release_date, monitored
|
||||
FROM albums WHERE id = $1
|
||||
`, albumID).Scan(&id, &foreignAlbumID, &title, &albumType, &releaseDate, &monitored)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := map[string]any{
|
||||
"id": id,
|
||||
"foreign_album_id": foreignAlbumID,
|
||||
"title": title,
|
||||
"album_type": albumType,
|
||||
"monitored": monitored,
|
||||
}
|
||||
if releaseDate != nil {
|
||||
result["release_date"] = releaseDate.Format("2006-01-02")
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CountWantedAlbums returns the number of entries in wanted_albums.
|
||||
func (e *TestEnv) CountWantedAlbums(ctx context.Context) (int64, error) {
|
||||
var count int64
|
||||
err := e.DB.QueryRow(ctx, "SELECT COUNT(*) FROM wanted_albums").Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
// IsAlbumWanted checks if an album is in the wanted_albums table.
|
||||
func (e *TestEnv) IsAlbumWanted(ctx context.Context, albumID string) (bool, error) {
|
||||
var count int64
|
||||
err := e.DB.QueryRow(ctx, `
|
||||
SELECT COUNT(*) FROM wanted_albums WHERE album_id = $1
|
||||
`, albumID).Scan(&count)
|
||||
return count > 0, err
|
||||
}
|
||||
|
||||
// GetWantedAlbumsByArtist returns wanted album IDs for an artist.
|
||||
func (e *TestEnv) GetWantedAlbumsByArtist(ctx context.Context, foreignArtistID string) ([]string, error) {
|
||||
rows, err := e.DB.Query(ctx, `
|
||||
SELECT wa.album_id::text FROM wanted_albums wa
|
||||
JOIN albums a ON wa.album_id = a.id
|
||||
JOIN artist_metadata am ON a.artist_metadata_id = am.id
|
||||
WHERE am.foreign_artist_id = $1
|
||||
`, foreignArtistID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var ids []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// CountBlocklistEntries returns the number of entries in blocklist.
|
||||
func (e *TestEnv) CountBlocklistEntries(ctx context.Context) (int64, error) {
|
||||
var count int64
|
||||
err := e.DB.QueryRow(ctx, "SELECT COUNT(*) FROM blocklist").Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
// CleanupWantedAlbums removes all wanted_albums entries (for test cleanup).
|
||||
func (e *TestEnv) CleanupWantedAlbums(ctx context.Context) error {
|
||||
_, err := e.DB.Exec(ctx, "DELETE FROM wanted_albums")
|
||||
return err
|
||||
}
|
||||
|
||||
// CleanupBlocklist removes all blocklist entries (for test cleanup).
|
||||
func (e *TestEnv) CleanupBlocklist(ctx context.Context) error {
|
||||
_, err := e.DB.Exec(ctx, "DELETE FROM blocklist")
|
||||
return err
|
||||
}
|
||||
|
||||
// GetAlbumsByArtistForeignID retrieves albums for an artist by foreign artist ID.
|
||||
func (e *TestEnv) GetAlbumsByArtistForeignID(ctx context.Context, foreignArtistID string) ([]map[string]any, error) {
|
||||
rows, err := e.DB.Query(ctx, `
|
||||
|
||||
Reference in New Issue
Block a user