bug fixes (#82)

* fix crash rebuilding playlists from ui

* fix error creating first channel
This commit is contained in:
Jason Dove
2021-03-18 01:27:08 +00:00
committed by GitHub
parent 0ca15ee7a8
commit 636bf0715b
3 changed files with 25 additions and 10 deletions
@@ -3,9 +3,9 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR; using MediatR;
using static ErsatzTV.Application.Channels.Mapper; using static ErsatzTV.Application.Channels.Mapper;
using static LanguageExt.Prelude;
namespace ErsatzTV.Application.Channels.Queries namespace ErsatzTV.Application.Channels.Queries
{ {
@@ -15,7 +15,7 @@ namespace ErsatzTV.Application.Channels.Queries
public GetAllChannelsHandler(IChannelRepository channelRepository) => _channelRepository = channelRepository; public GetAllChannelsHandler(IChannelRepository channelRepository) => _channelRepository = channelRepository;
public Task<List<ChannelViewModel>> Handle(GetAllChannels request, CancellationToken cancellationToken) => public async Task<List<ChannelViewModel>> Handle(GetAllChannels request, CancellationToken cancellationToken) =>
_channelRepository.GetAll().Map(channels => channels.Map(ProjectToViewModel).ToList()); Optional(await _channelRepository.GetAll()).Flatten().Map(ProjectToViewModel).ToList();
} }
} }
@@ -13,8 +13,13 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
public class PlayoutRepository : IPlayoutRepository public class PlayoutRepository : IPlayoutRepository
{ {
private readonly TvContext _dbContext; private readonly TvContext _dbContext;
private readonly IDbContextFactory<TvContext> _dbContextFactory;
public PlayoutRepository(TvContext dbContext) => _dbContext = dbContext; public PlayoutRepository(TvContext dbContext, IDbContextFactory<TvContext> dbContextFactory)
{
_dbContext = dbContext;
_dbContextFactory = dbContextFactory;
}
public async Task<Playout> Add(Playout playout) public async Task<Playout> Add(Playout playout)
{ {
@@ -67,8 +72,11 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.Map(Optional) .Map(Optional)
.MapT(pi => pi.StartOffset); .MapT(pi => pi.StartOffset);
public Task<List<PlayoutItem>> GetPlayoutItems(int playoutId) => public async Task<List<PlayoutItem>> GetPlayoutItems(int playoutId)
_dbContext.PlayoutItems {
await using TvContext context = _dbContextFactory.CreateDbContext();
return await context.PlayoutItems
.AsNoTracking()
.Include(i => i.MediaItem) .Include(i => i.MediaItem)
.ThenInclude(mi => (mi as Movie).MovieMetadata) .ThenInclude(mi => (mi as Movie).MovieMetadata)
.ThenInclude(mm => mm.Artwork) .ThenInclude(mm => mm.Artwork)
@@ -84,12 +92,17 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ThenInclude(s => s.SeasonMetadata) .ThenInclude(s => s.SeasonMetadata)
.Filter(i => i.PlayoutId == playoutId) .Filter(i => i.PlayoutId == playoutId)
.ToListAsync(); .ToListAsync();
}
public Task<List<Playout>> GetAll() => public async Task<List<Playout>> GetAll()
_dbContext.Playouts {
await using TvContext context = _dbContextFactory.CreateDbContext();
return await context.Playouts
.AsNoTracking()
.Include(p => p.Channel) .Include(p => p.Channel)
.Include(p => p.ProgramSchedule) .Include(p => p.ProgramSchedule)
.ToListAsync(); .ToListAsync();
}
public async Task Update(Playout playout) public async Task Update(Playout playout)
{ {
+4 -2
View File
@@ -5,6 +5,7 @@
@using ErsatzTV.Application.Images.Commands @using ErsatzTV.Application.Images.Commands
@using ErsatzTV.Application.Channels @using ErsatzTV.Application.Channels
@using ErsatzTV.Application.Channels.Queries @using ErsatzTV.Application.Channels.Queries
@using static LanguageExt.Prelude
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject ILogger<ChannelEditor> Logger @inject ILogger<ChannelEditor> Logger
@inject ISnackbar Snackbar @inject ISnackbar Snackbar
@@ -95,8 +96,9 @@
else else
{ {
// TODO: command for new channel // TODO: command for new channel
int maxNumber = await Mediator.Send(new GetAllChannels()) IEnumerable<int> channelNumbers = await Mediator.Send(new GetAllChannels())
.Map(list => list.Map(c => int.TryParse(c.Number.Split(".").Head(), out int result) ? result : 0).Max()); .Map(list => list.Map(c => int.TryParse(c.Number.Split(".").Head(), out int result) ? result : 0));
int maxNumber = Optional(channelNumbers).Flatten().DefaultIfEmpty(0).Max();
_model.Number = (maxNumber + 1).ToString(); _model.Number = (maxNumber + 1).ToString();
_model.Name = "New Channel"; _model.Name = "New Channel";
_model.FFmpegProfileId = _ffmpegProfiles.Head().Id; _model.FFmpegProfileId = _ffmpegProfiles.Head().Id;