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:
@@ -183,6 +183,11 @@ func (e *TestEnv) GET(path string) (*APIResponse, error) {
|
||||
return e.Do(APIRequest{Method: http.MethodGet, Path: path})
|
||||
}
|
||||
|
||||
// DELETE is a convenience method for DELETE requests.
|
||||
func (e *TestEnv) DELETE(path string) (*APIResponse, error) {
|
||||
return e.Do(APIRequest{Method: http.MethodDelete, Path: path})
|
||||
}
|
||||
|
||||
// DecodeJSON decodes the response body into the given value.
|
||||
func (r *APIResponse) DecodeJSON(v any) error {
|
||||
return json.Unmarshal(r.Body, v)
|
||||
@@ -244,6 +249,26 @@ func (e *TestEnv) GetArtistByForeignID(ctx context.Context, foreignID string) (m
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetArtistUpdatedAt retrieves the updated_at timestamp for an artist.
|
||||
func (e *TestEnv) GetArtistUpdatedAt(ctx context.Context, foreignArtistID string) (time.Time, error) {
|
||||
var updatedAt time.Time
|
||||
err := e.DB.QueryRow(ctx, `
|
||||
SELECT updated_at FROM artist_metadata WHERE foreign_artist_id = $1
|
||||
`, foreignArtistID).Scan(&updatedAt)
|
||||
return updatedAt, err
|
||||
}
|
||||
|
||||
// CountAlbumsByArtist returns the number of albums for a specific artist.
|
||||
func (e *TestEnv) CountAlbumsByArtist(ctx context.Context, foreignArtistID string) (int64, error) {
|
||||
var count int64
|
||||
err := e.DB.QueryRow(ctx, `
|
||||
SELECT COUNT(*) FROM albums a
|
||||
JOIN artist_metadata am ON a.artist_metadata_id = am.id
|
||||
WHERE am.foreign_artist_id = $1
|
||||
`, foreignArtistID).Scan(&count)
|
||||
return count, 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