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.
54 lines
2.0 KiB
54 lines
2.0 KiB
using Bugsnag; |
|
using ErsatzTV.Application.MediaCards; |
|
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
using ErsatzTV.Core.Interfaces.Search; |
|
using ErsatzTV.Core.Search; |
|
using static ErsatzTV.Application.MediaCards.Mapper; |
|
|
|
namespace ErsatzTV.Application.Search; |
|
|
|
public class |
|
QuerySearchIndexShowsHandler : IRequestHandler<QuerySearchIndexShows, TelevisionShowCardResultsViewModel> |
|
{ |
|
private readonly IClient _client; |
|
private readonly IMediaSourceRepository _mediaSourceRepository; |
|
private readonly ISearchIndex _searchIndex; |
|
private readonly ITelevisionRepository _televisionRepository; |
|
|
|
public QuerySearchIndexShowsHandler( |
|
IClient client, |
|
ISearchIndex searchIndex, |
|
ITelevisionRepository televisionRepository, |
|
IMediaSourceRepository mediaSourceRepository) |
|
{ |
|
_client = client; |
|
_searchIndex = searchIndex; |
|
_televisionRepository = televisionRepository; |
|
_mediaSourceRepository = mediaSourceRepository; |
|
} |
|
|
|
public async Task<TelevisionShowCardResultsViewModel> Handle( |
|
QuerySearchIndexShows request, |
|
CancellationToken cancellationToken) |
|
{ |
|
SearchResult searchResult = await _searchIndex.Search( |
|
_client, |
|
request.Query, |
|
string.Empty, |
|
(request.PageNumber - 1) * request.PageSize, |
|
request.PageSize); |
|
|
|
Option<JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() |
|
.Map(list => list.HeadOrNone()); |
|
|
|
Option<EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() |
|
.Map(list => list.HeadOrNone()); |
|
|
|
List<TelevisionShowCardViewModel> items = await _televisionRepository |
|
.GetShowsForCards(searchResult.Items.Map(i => i.Id).ToList()) |
|
.Map(list => list.Map(s => ProjectToViewModel(s, maybeJellyfin, maybeEmby)).ToList()); |
|
|
|
return new TelevisionShowCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap); |
|
} |
|
}
|
|
|