Example #1
0
    public async Task <TelevisionSeasonCardResultsViewModel> Handle(
        QuerySearchIndexSeasons request,
        CancellationToken cancellationToken)
    {
        SearchResult searchResult = await _searchIndex.Search(
            request.Query,
            (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 <TelevisionSeasonCardViewModel> items = await _televisionRepository
                                                     .GetSeasonsForCards(searchResult.Items.Map(i => i.Id).ToList())
                                                     .Map(list => list.Map(s => ProjectToViewModel(s, maybeJellyfin, maybeEmby)).ToList());

        return(new TelevisionSeasonCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap));
    }