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.
48 lines
1.9 KiB
48 lines
1.9 KiB
using Bugsnag; |
|
using ErsatzTV.Application.MediaCards; |
|
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Search; |
|
using ErsatzTV.Core.Search; |
|
using ErsatzTV.Infrastructure.Data; |
|
using Microsoft.EntityFrameworkCore; |
|
using static ErsatzTV.Application.MediaCards.Mapper; |
|
|
|
namespace ErsatzTV.Application.Search; |
|
|
|
public class |
|
QuerySearchIndexShowsHandler( |
|
IClient client, |
|
ISearchIndex searchIndex, |
|
IDbContextFactory<TvContext> dbContextFactory) |
|
: QuerySearchIndexHandlerBase, IRequestHandler<QuerySearchIndexShows, TelevisionShowCardResultsViewModel> |
|
{ |
|
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, |
|
cancellationToken); |
|
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
Option<JellyfinMediaSource> maybeJellyfin = await GetJellyfin(dbContext, cancellationToken); |
|
Option<EmbyMediaSource> maybeEmby = await GetEmby(dbContext, cancellationToken); |
|
|
|
var ids = searchResult.Items.Map(i => i.Id).ToHashSet(); |
|
List<TelevisionShowCardViewModel> items = await dbContext.ShowMetadata |
|
.AsNoTracking() |
|
.Filter(sm => ids.Contains(sm.ShowId)) |
|
.Include(sm => sm.Artwork) |
|
.Include(sm => sm.Show) |
|
.OrderBy(sm => sm.SortTitle) |
|
.ToListAsync(cancellationToken) |
|
.Map(list => list.Map(s => ProjectToViewModel(s, maybeJellyfin, maybeEmby)).ToList()); |
|
|
|
return new TelevisionShowCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap); |
|
} |
|
}
|
|
|