show collection name in some error messages (#612)

This commit is contained in:
Jason Dove
2022-02-04 20:17:17 -06:00
committed by GitHub
parent 5fd315ead8
commit 0c53a4509c
5 changed files with 51 additions and 3 deletions
+1
View File
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Intermittent watermarks will now fade in and out
- Show collection name in some playout build error messages
## [0.4.0-alpha] - 2022-01-29
### Fixed
@@ -37,5 +37,6 @@ namespace ErsatzTV.Core.Tests.Fakes
throw new NotSupportedException();
public Task<bool> IsCustomPlaybackOrder(int collectionId) => false.AsTask();
public Task<Option<string>> GetNameFromKey(CollectionKey emptyCollection) => Option<string>.None.AsTask();
}
}
@@ -18,5 +18,6 @@ namespace ErsatzTV.Core.Interfaces.Repositories
Task<List<int>> PlayoutIdsUsingMultiCollection(int multiCollectionId);
Task<List<int>> PlayoutIdsUsingSmartCollection(int smartCollectionId);
Task<bool> IsCustomPlaybackOrder(int collectionId);
Task<Option<string>> GetNameFromKey(CollectionKey emptyCollection);
}
}
+17 -3
View File
@@ -73,9 +73,23 @@ namespace ErsatzTV.Core.Scheduling
Option<CollectionKey> maybeEmptyCollection = await CheckForEmptyCollections(collectionMediaItems);
foreach (CollectionKey emptyCollection in maybeEmptyCollection)
{
_logger.LogError(
"Unable to rebuild playout; collection {@CollectionKey} has no valid items!",
emptyCollection);
Option<string> maybeName = await _mediaCollectionRepository.GetNameFromKey(emptyCollection);
if (maybeName.IsSome)
{
foreach (string name in maybeName)
{
_logger.LogError(
"Unable to rebuild playout; {CollectionType} {CollectionName} has no valid items!",
emptyCollection.CollectionType,
name);
}
}
else
{
_logger.LogError(
"Unable to rebuild playout; collection {@CollectionKey} has no valid items!",
emptyCollection);
}
return playout;
}
@@ -355,6 +355,37 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
@"SELECT IFNULL(MIN(UseCustomPlaybackOrder), 0) FROM Collection WHERE Id = @CollectionId",
new { CollectionId = collectionId });
public async Task<Option<string>> GetNameFromKey(CollectionKey emptyCollection)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
return emptyCollection.CollectionType switch
{
ProgramScheduleItemCollectionType.Artist => await dbContext.Artists.Include(a => a.ArtistMetadata)
.SelectOneAsync(a => a.Id, a => a.Id == emptyCollection.MediaItemId.Value)
.MapT(a => a.ArtistMetadata.Head().Title),
ProgramScheduleItemCollectionType.Collection => await dbContext.Collections
.SelectOneAsync(c => c.Id, c => c.Id == emptyCollection.CollectionId.Value)
.MapT(c => c.Name),
ProgramScheduleItemCollectionType.MultiCollection => await dbContext.MultiCollections
.SelectOneAsync(c => c.Id, c => c.Id == emptyCollection.MultiCollectionId.Value)
.MapT(c => c.Name),
ProgramScheduleItemCollectionType.SmartCollection => await dbContext.SmartCollections
.SelectOneAsync(c => c.Id, c => c.Id == emptyCollection.SmartCollectionId.Value)
.MapT(c => c.Name),
ProgramScheduleItemCollectionType.TelevisionSeason => await dbContext.Seasons
.Include(s => s.SeasonMetadata)
.Include(s => s.Show)
.ThenInclude(s => s.ShowMetadata)
.SelectOneAsync(a => a.Id, a => a.Id == emptyCollection.MediaItemId.Value)
.MapT(s => $"{s.Show.ShowMetadata.Head().Title} Season {s.SeasonNumber}"),
ProgramScheduleItemCollectionType.TelevisionShow => await dbContext.Shows.Include(s => s.ShowMetadata)
.SelectOneAsync(a => a.Id, a => a.Id == emptyCollection.MediaItemId.Value)
.MapT(s => s.ShowMetadata.Head().Title),
_ => None
};
}
private async Task<List<Movie>> GetMovieItems(TvContext dbContext, int collectionId)
{
IEnumerable<int> ids = await _dbConnection.QueryAsync<int>(