Two read-only endpoints: the album search and the album detail with its tracklist. Both go through the same single-flight cache as the song search, and the detail one especially benefits since it costs two upstream calls, the browse id lookup and the album itself, for metadata that never changes. Paginator handling is now shared between the song and album searches.
22 lines
870 B
C#
22 lines
870 B
C#
using ErrorOr;
|
|
using Mediator;
|
|
using Musify.Application.Contracts;
|
|
|
|
namespace Musify.Application.YouTube
|
|
{
|
|
public record SearchYouTubeAlbumsQuery(string Query, string ContinuationToken)
|
|
: IQuery<ErrorOr<YouTubeAlbumSearchResult>>;
|
|
|
|
public class SearchYouTubeAlbumsQueryHandler(IYouTubeMusicService youTubeMusicService)
|
|
: IQueryHandler<SearchYouTubeAlbumsQuery, ErrorOr<YouTubeAlbumSearchResult>>
|
|
{
|
|
public async ValueTask<ErrorOr<YouTubeAlbumSearchResult>> Handle(SearchYouTubeAlbumsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrEmpty(request.Query))
|
|
return Error.Validation(description: "The search query must not be empty.");
|
|
|
|
return await youTubeMusicService.SearchAlbumsAsync(request.Query, request.ContinuationToken, cancellationToken);
|
|
}
|
|
}
|
|
}
|