Browse Source

fix adding channel with no watermark (#265)

pull/266/head
Jason Dove 5 years ago committed by GitHub
parent
commit
57aa14b764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 16
      ErsatzTV.Application/Channels/Commands/CreateChannelHandler.cs

4
CHANGELOG.md

@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [Unreleased]
### Fixed
- Fix ui crash adding a channel without a watermark
## [0.0.46-prealpha] - 2021-06-14 ## [0.0.46-prealpha] - 2021-06-14
### Added ### Added
@ -18,7 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- This allows easy watermark reuse across channels - This allows easy watermark reuse across channels
### Fixed ### Fixed
- Fix crash adding or editing schedule items due to Artist with no name - Fix ui crash adding or editing schedule items due to Artist with no name
- Fix many potential sources of inconsistent data in UI - Fix many potential sources of inconsistent data in UI
## [0.0.45-prealpha] - 2021-06-12 ## [0.0.45-prealpha] - 2021-06-12

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

@ -38,7 +38,7 @@ namespace ErsatzTV.Application.Channels.Commands
return new CreateChannelResult(channel.Id); return new CreateChannelResult(channel.Id);
} }
private async Task<Validation<BaseError, Channel>> Validate(TvContext dbContext, CreateChannel request) => private static async Task<Validation<BaseError, Channel>> Validate(TvContext dbContext, CreateChannel request) =>
(ValidateName(request), await ValidateNumber(dbContext, request), (ValidateName(request), await ValidateNumber(dbContext, request),
await FFmpegProfileMustExist(dbContext, request), await FFmpegProfileMustExist(dbContext, request),
ValidatePreferredLanguage(request), ValidatePreferredLanguage(request),
@ -66,10 +66,14 @@ namespace ErsatzTV.Application.Channels.Commands
FFmpegProfileId = ffmpegProfileId, FFmpegProfileId = ffmpegProfileId,
StreamingMode = request.StreamingMode, StreamingMode = request.StreamingMode,
Artwork = artwork, Artwork = artwork,
PreferredLanguageCode = preferredLanguageCode, PreferredLanguageCode = preferredLanguageCode
WatermarkId = watermarkId
}; };
foreach (int id in watermarkId)
{
channel.WatermarkId = id;
}
return channel; return channel;
}); });
@ -111,20 +115,20 @@ namespace ErsatzTV.Application.Channels.Commands
.MapT(_ => createChannel.FFmpegProfileId) .MapT(_ => createChannel.FFmpegProfileId)
.Map(o => o.ToValidation<BaseError>($"FFmpegProfile {createChannel.FFmpegProfileId} does not exist.")); .Map(o => o.ToValidation<BaseError>($"FFmpegProfile {createChannel.FFmpegProfileId} does not exist."));
private static async Task<Validation<BaseError, int?>> WatermarkMustExist( private static async Task<Validation<BaseError, Option<int>>> WatermarkMustExist(
TvContext dbContext, TvContext dbContext,
CreateChannel createChannel) CreateChannel createChannel)
{ {
if (createChannel.WatermarkId is null) if (createChannel.WatermarkId is null)
{ {
return createChannel.WatermarkId; return Option<int>.None;
} }
return await dbContext.ChannelWatermarks return await dbContext.ChannelWatermarks
.CountAsync(w => w.Id == createChannel.WatermarkId) .CountAsync(w => w.Id == createChannel.WatermarkId)
.Map(Optional) .Map(Optional)
.Filter(c => c > 0) .Filter(c => c > 0)
.MapT(_ => createChannel.WatermarkId) .MapT(_ => Optional(createChannel.WatermarkId))
.Map(o => o.ToValidation<BaseError>($"Watermark {createChannel.WatermarkId} does not exist.")); .Map(o => o.ToValidation<BaseError>($"Watermark {createChannel.WatermarkId} does not exist."));
} }
} }

Loading…
Cancel
Save