mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.3 KiB
32 lines
1.3 KiB
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
using static ErsatzTV.Application.Artists.Mapper; |
|
|
|
namespace ErsatzTV.Application.Artists; |
|
|
|
public class GetArtistByIdHandler : IRequestHandler<GetArtistById, Option<ArtistViewModel>> |
|
{ |
|
private readonly IArtistRepository _artistRepository; |
|
private readonly ISearchRepository _searchRepository; |
|
|
|
public GetArtistByIdHandler(IArtistRepository artistRepository, ISearchRepository searchRepository) |
|
{ |
|
_artistRepository = artistRepository; |
|
_searchRepository = searchRepository; |
|
} |
|
|
|
public async Task<Option<ArtistViewModel>> Handle( |
|
GetArtistById request, |
|
CancellationToken cancellationToken) |
|
{ |
|
Option<Artist> maybeArtist = await _artistRepository.GetArtist(request.ArtistId); |
|
return await maybeArtist.Match<Task<Option<ArtistViewModel>>>( |
|
async artist => |
|
{ |
|
List<string> mediaCodes = await _searchRepository.GetLanguagesForArtist(artist); |
|
List<string> languageCodes = await _searchRepository.GetAllThreeLetterLanguageCodes(mediaCodes); |
|
return ProjectToViewModel(artist, languageCodes); |
|
}, |
|
() => Task.FromResult(Option<ArtistViewModel>.None)); |
|
} |
|
}
|
|
|