feat: add refresh and delete artist endpoints (sections 1.2, 1.3)
- Add POST /api/artists/{id}/refresh to re-fetch metadata from gRPC service
- Add DELETE /api/artists/{id} with cascade delete via PostgreSQL
- Add e2e tests for both flows covering happy path, not found, idempotency
- Extend testutil with GetArtistUpdatedAt, CountAlbumsByArtist, DELETE helper
This commit is contained in:
@@ -250,3 +250,41 @@ func (db *DB) CountAlbums(ctx context.Context) (int64, error) {
|
||||
err := db.pool.QueryRow(ctx, "SELECT COUNT(*) FROM albums").Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (db *DB) GetArtistByForeignID(ctx context.Context, foreignArtistID string) (*ArtistMetadataRow, error) {
|
||||
var a ArtistMetadataRow
|
||||
err := db.pool.QueryRow(ctx, `
|
||||
SELECT id, foreign_artist_id, name, sort_name, artist_type, genres, created_at, updated_at
|
||||
FROM artist_metadata
|
||||
WHERE foreign_artist_id = $1
|
||||
`, foreignArtistID).Scan(&a.ID, &a.ForeignArtistID, &a.Name, &a.SortName, &a.ArtistType, &a.Genres, &a.CreatedAt, &a.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
func (db *DB) CountAlbumsByArtist(ctx context.Context, artistMetadataID uuid.UUID) (int64, error) {
|
||||
var count int64
|
||||
err := db.pool.QueryRow(ctx, `
|
||||
SELECT COUNT(*) FROM albums WHERE artist_metadata_id = $1
|
||||
`, artistMetadataID).Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (db *DB) TouchArtistUpdatedAt(ctx context.Context, artistMetadataID uuid.UUID) error {
|
||||
_, err := db.pool.Exec(ctx, `
|
||||
UPDATE artist_metadata SET updated_at = NOW() WHERE id = $1
|
||||
`, artistMetadataID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *DB) DeleteArtistByForeignID(ctx context.Context, foreignArtistID string) (bool, error) {
|
||||
result, err := db.pool.Exec(ctx, `
|
||||
DELETE FROM artist_metadata WHERE foreign_artist_id = $1
|
||||
`, foreignArtistID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result.RowsAffected() > 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user