Browse Source

bug fixes (#82)

* fix crash rebuilding playlists from ui

* fix error creating first channel
pull/83/head
Jason Dove 4 years ago committed by GitHub
parent
commit
636bf0715b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ErsatzTV.Application/Channels/Queries/GetAllChannelsHandler.cs
  2. 23
      ErsatzTV.Infrastructure/Data/Repositories/PlayoutRepository.cs
  3. 6
      ErsatzTV/Pages/ChannelEditor.razor

6
ErsatzTV.Application/Channels/Queries/GetAllChannelsHandler.cs

@ -3,9 +3,9 @@ using System.Linq; @@ -3,9 +3,9 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
using MediatR;
using static ErsatzTV.Application.Channels.Mapper;
using static LanguageExt.Prelude;
namespace ErsatzTV.Application.Channels.Queries
{
@ -15,7 +15,7 @@ namespace ErsatzTV.Application.Channels.Queries @@ -15,7 +15,7 @@ namespace ErsatzTV.Application.Channels.Queries
public GetAllChannelsHandler(IChannelRepository channelRepository) => _channelRepository = channelRepository;
public Task<List<ChannelViewModel>> Handle(GetAllChannels request, CancellationToken cancellationToken) =>
_channelRepository.GetAll().Map(channels => channels.Map(ProjectToViewModel).ToList());
public async Task<List<ChannelViewModel>> Handle(GetAllChannels request, CancellationToken cancellationToken) =>
Optional(await _channelRepository.GetAll()).Flatten().Map(ProjectToViewModel).ToList();
}
}

23
ErsatzTV.Infrastructure/Data/Repositories/PlayoutRepository.cs

@ -13,8 +13,13 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -13,8 +13,13 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
public class PlayoutRepository : IPlayoutRepository
{
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)
{
@ -67,8 +72,11 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -67,8 +72,11 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.Map(Optional)
.MapT(pi => pi.StartOffset);
public Task<List<PlayoutItem>> GetPlayoutItems(int playoutId) =>
_dbContext.PlayoutItems
public async Task<List<PlayoutItem>> GetPlayoutItems(int playoutId)
{
await using TvContext context = _dbContextFactory.CreateDbContext();
return await context.PlayoutItems
.AsNoTracking()
.Include(i => i.MediaItem)
.ThenInclude(mi => (mi as Movie).MovieMetadata)
.ThenInclude(mm => mm.Artwork)
@ -84,12 +92,17 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -84,12 +92,17 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ThenInclude(s => s.SeasonMetadata)
.Filter(i => i.PlayoutId == playoutId)
.ToListAsync();
}
public Task<List<Playout>> GetAll() =>
_dbContext.Playouts
public async Task<List<Playout>> GetAll()
{
await using TvContext context = _dbContextFactory.CreateDbContext();
return await context.Playouts
.AsNoTracking()
.Include(p => p.Channel)
.Include(p => p.ProgramSchedule)
.ToListAsync();
}
public async Task Update(Playout playout)
{

6
ErsatzTV/Pages/ChannelEditor.razor

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
@using ErsatzTV.Application.Images.Commands
@using ErsatzTV.Application.Channels
@using ErsatzTV.Application.Channels.Queries
@using static LanguageExt.Prelude
@inject NavigationManager NavigationManager
@inject ILogger<ChannelEditor> Logger
@inject ISnackbar Snackbar
@ -95,8 +96,9 @@ @@ -95,8 +96,9 @@
else
{
// TODO: command for new channel
int maxNumber = await Mediator.Send(new GetAllChannels())
.Map(list => list.Map(c => int.TryParse(c.Number.Split(".").Head(), out int result) ? result : 0).Max());
IEnumerable<int> channelNumbers = await Mediator.Send(new GetAllChannels())
.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.Name = "New Channel";
_model.FFmpegProfileId = _ffmpegProfiles.Head().Id;

Loading…
Cancel
Save