mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* fix schedule editor crash due to bad music video artist data * update dependenciespull/1117/head
10 changed files with 47 additions and 33 deletions
@ -1,22 +1,44 @@
@@ -1,22 +1,44 @@
|
||||
using ErsatzTV.Application.MediaItems; |
||||
using ErsatzTV.Core.Interfaces.Repositories; |
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Infrastructure.Data; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using static ErsatzTV.Application.MediaItems.Mapper; |
||||
|
||||
namespace ErsatzTV.Application.Artists; |
||||
|
||||
public class GetAllArtistsHandler : IRequestHandler<GetAllArtists, List<NamedMediaItemViewModel>> |
||||
{ |
||||
private readonly IArtistRepository _artistRepository; |
||||
private readonly IDbContextFactory<TvContext> _dbContextFactory; |
||||
|
||||
public GetAllArtistsHandler(IArtistRepository artistRepository) => _artistRepository = artistRepository; |
||||
public GetAllArtistsHandler(IDbContextFactory<TvContext> dbContextFactory) |
||||
{ |
||||
_dbContextFactory = dbContextFactory; |
||||
} |
||||
|
||||
public Task<List<NamedMediaItemViewModel>> Handle( |
||||
public async Task<List<NamedMediaItemViewModel>> Handle( |
||||
GetAllArtists request, |
||||
CancellationToken cancellationToken) => |
||||
_artistRepository.GetAllArtists() |
||||
.Map( |
||||
list => list.Filter( |
||||
a => !string.IsNullOrWhiteSpace( |
||||
a.ArtistMetadata.HeadOrNone().Match(am => am.Title, () => string.Empty)))) |
||||
.Map(list => list.Map(ProjectToViewModel).ToList()); |
||||
CancellationToken cancellationToken) |
||||
{ |
||||
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); |
||||
|
||||
List<Artist> allArtists = await dbContext.Artists |
||||
.AsNoTracking() |
||||
.Include(a => a.ArtistMetadata) |
||||
.ToListAsync(cancellationToken: cancellationToken); |
||||
|
||||
return allArtists.Bind(a => ProjectArtist(a)).ToList(); |
||||
} |
||||
|
||||
private static Option<NamedMediaItemViewModel> ProjectArtist(Artist a) |
||||
{ |
||||
foreach (ArtistMetadata metadata in a.ArtistMetadata.HeadOrNone()) |
||||
{ |
||||
if (!string.IsNullOrWhiteSpace(metadata.Title)) |
||||
{ |
||||
return ProjectToViewModel(a); |
||||
} |
||||
} |
||||
|
||||
return None; |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue