Browse Source

update xmltv channel list on channel edit (#1570)

pull/1571/head
Jason Dove 2 years ago committed by GitHub
parent
commit
d37ce2d38a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 16
      ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs
  3. 22
      ErsatzTV.Application/Channels/Commands/UpdateChannelHandler.cs

2
CHANGELOG.md

@ -39,6 +39,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix crop scale behavior with NVIDIA, QSV acceleration - Fix crop scale behavior with NVIDIA, QSV acceleration
- Fix bug that corrupted uploaded images (watermarks, channel logos) - Fix bug that corrupted uploaded images (watermarks, channel logos)
- Re-uploading images should fix them - Re-uploading images should fix them
- Recreate XMLTV channel list (including logos) when channels are edited in ErsatzTV
- This bug caused the ErsatzTV logo to be used instead of channel logos in some cases
### Changed ### Changed
- Upgrade from .NET 7 to .NET 8 - Upgrade from .NET 7 to .NET 8

16
ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs

@ -1,33 +1,35 @@
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Channels;
using ErsatzTV.Core; using ErsatzTV.Core;
using ErsatzTV.Core.Domain; using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Domain.Filler; using ErsatzTV.Core.Domain.Filler;
using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions; using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Channel = ErsatzTV.Core.Domain.Channel;
namespace ErsatzTV.Application.Channels; namespace ErsatzTV.Application.Channels;
public class CreateChannelHandler : IRequestHandler<CreateChannel, Either<BaseError, CreateChannelResult>> public class CreateChannelHandler(
ChannelWriter<IBackgroundServiceRequest> workerChannel,
IDbContextFactory<TvContext> dbContextFactory)
: IRequestHandler<CreateChannel, Either<BaseError, CreateChannelResult>>
{ {
private readonly IDbContextFactory<TvContext> _dbContextFactory;
public CreateChannelHandler(IDbContextFactory<TvContext> dbContextFactory) => _dbContextFactory = dbContextFactory;
public async Task<Either<BaseError, CreateChannelResult>> Handle( public async Task<Either<BaseError, CreateChannelResult>> Handle(
CreateChannel request, CreateChannel request,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Validation<BaseError, Channel> validation = await Validate(dbContext, request); Validation<BaseError, Channel> validation = await Validate(dbContext, request);
return await validation.Apply(c => PersistChannel(dbContext, c)); return await validation.Apply(c => PersistChannel(dbContext, c));
} }
private static async Task<CreateChannelResult> PersistChannel(TvContext dbContext, Channel channel) private async Task<CreateChannelResult> PersistChannel(TvContext dbContext, Channel channel)
{ {
await dbContext.Channels.AddAsync(channel); await dbContext.Channels.AddAsync(channel);
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
await workerChannel.WriteAsync(new RefreshChannelList());
return new CreateChannelResult(channel.Id); return new CreateChannelResult(channel.Id);
} }

22
ErsatzTV.Application/Channels/Commands/UpdateChannelHandler.cs

@ -12,26 +12,18 @@ using Channel = ErsatzTV.Core.Domain.Channel;
namespace ErsatzTV.Application.Channels; namespace ErsatzTV.Application.Channels;
public class UpdateChannelHandler : IRequestHandler<UpdateChannel, Either<BaseError, ChannelViewModel>> public class UpdateChannelHandler(
{
private readonly IDbContextFactory<TvContext> _dbContextFactory;
private readonly ChannelWriter<IBackgroundServiceRequest> _workerChannel;
public UpdateChannelHandler(
ChannelWriter<IBackgroundServiceRequest> workerChannel, ChannelWriter<IBackgroundServiceRequest> workerChannel,
IDbContextFactory<TvContext> dbContextFactory) IDbContextFactory<TvContext> dbContextFactory)
{ : IRequestHandler<UpdateChannel, Either<BaseError, ChannelViewModel>>
_workerChannel = workerChannel; {
_dbContextFactory = dbContextFactory;
}
public async Task<Either<BaseError, ChannelViewModel>> Handle( public async Task<Either<BaseError, ChannelViewModel>> Handle(
UpdateChannel request, UpdateChannel request,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Validation<BaseError, Channel> validation = await Validate(dbContext, request); Validation<BaseError, Channel> validation = await Validate(dbContext, request);
return await LanguageExtensions.Apply(validation, c => ApplyUpdateRequest(dbContext, c, request)); return await validation.Apply(c => ApplyUpdateRequest(dbContext, c, request));
} }
private async Task<ChannelViewModel> ApplyUpdateRequest(TvContext dbContext, Channel c, UpdateChannel update) private async Task<ChannelViewModel> ApplyUpdateRequest(TvContext dbContext, Channel c, UpdateChannel update)
@ -85,10 +77,12 @@ public class UpdateChannelHandler : IRequestHandler<UpdateChannel, Either<BaseEr
foreach (Playout playout in maybePlayout) foreach (Playout playout in maybePlayout)
{ {
await _workerChannel.WriteAsync(new ExtractEmbeddedSubtitles(playout.Id)); await workerChannel.WriteAsync(new ExtractEmbeddedSubtitles(playout.Id));
} }
} }
await workerChannel.WriteAsync(new RefreshChannelList());
return ProjectToViewModel(c); return ProjectToViewModel(c);
} }

Loading…
Cancel
Save