Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Has been skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Has been skipped
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 15m30s
Build ErsatzTV Image / Functional E2E (curl contracts) (push) Successful in 15m48s
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 7m32s
Build ErsatzTV Image / Build & push image (amd64) (push) Has been cancelled
Closes #415. Server-derived health object on the channel list + detail DTOs (built-timeline detection, kind-agnostic across all 5 PlayoutScheduleKind; assessable gate keyed to the owning channel's mode), single "Problems" SPA filter with per-fault badges. Supersedes #72's api.channel-health-signal decision. Co-authored-by: Timothy <timothy.look@gmail.com> Co-committed-by: Timothy <timothy.look@gmail.com>
100 lines
3.7 KiB
C#
100 lines
3.7 KiB
C#
using ErsatzTV.Core.Api.Channels;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ErsatzTV.Infrastructure.Data.Repositories;
|
|
|
|
public class ChannelRepository(IDbContextFactory<TvContext> dbContextFactory) : IChannelRepository
|
|
{
|
|
public async Task<Option<Channel>> GetChannel(int id)
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync();
|
|
return await dbContext.Channels
|
|
.AsNoTracking()
|
|
.Include(c => c.FFmpegProfile)
|
|
.Include(c => c.Artwork)
|
|
.Include(c => c.Watermark)
|
|
.Include(c => c.Playouts)
|
|
.ThenInclude(p => p.BuildStatus)
|
|
.Include(c => c.MirrorSourceChannel)
|
|
.ThenInclude(mc => mc.Playouts)
|
|
.ThenInclude(p => p.BuildStatus)
|
|
.Include(c => c.ChannelGraphicsElements)
|
|
.ThenInclude(x => x.GraphicsElement)
|
|
.OrderBy(c => c.Id)
|
|
.SingleOrDefaultAsync(c => c.Id == id)
|
|
.Map(Optional);
|
|
}
|
|
|
|
public async Task<Option<Channel>> GetByNumber(string number)
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync();
|
|
return await dbContext.Channels
|
|
.AsNoTracking()
|
|
.Include(c => c.FFmpegProfile)
|
|
.ThenInclude(p => p.Resolution)
|
|
.Include(c => c.Artwork)
|
|
.Include(c => c.Watermark)
|
|
.OrderBy(c => c.Number)
|
|
.SingleOrDefaultAsync(c => c.Number == number)
|
|
.Map(Optional);
|
|
}
|
|
|
|
public async Task<List<Channel>> GetAll(CancellationToken cancellationToken)
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
|
return await dbContext.Channels
|
|
.AsNoTracking()
|
|
.Include(c => c.FFmpegProfile)
|
|
.Include(c => c.Artwork)
|
|
.Include(c => c.Playouts)
|
|
.ThenInclude(p => p.BuildStatus)
|
|
.Include(c => c.MirrorSourceChannel)
|
|
.ThenInclude(mc => mc.Playouts)
|
|
.ThenInclude(p => p.BuildStatus)
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
|
|
public async Task<Dictionary<int, PlayoutUpcoming>> GetPlayoutUpcomingHealth(
|
|
IReadOnlyCollection<int> playoutIds,
|
|
DateTime nowUtc,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (playoutIds.Count == 0)
|
|
{
|
|
return new Dictionary<int, PlayoutUpcoming>();
|
|
}
|
|
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
|
return await dbContext.PlayoutItems
|
|
.AsNoTracking()
|
|
.Where(pi => playoutIds.Contains(pi.PlayoutId) && pi.Finish >= nowUtc)
|
|
.GroupBy(pi => pi.PlayoutId)
|
|
.Select(g => new
|
|
{
|
|
PlayoutId = g.Key,
|
|
Total = g.Count(),
|
|
Broken = g.Count(pi =>
|
|
pi.MediaItem.State == MediaItemState.FileNotFound ||
|
|
pi.MediaItem.State == MediaItemState.Unavailable)
|
|
})
|
|
.ToDictionaryAsync(
|
|
x => x.PlayoutId,
|
|
x => new PlayoutUpcoming(x.Total, x.Broken),
|
|
cancellationToken);
|
|
}
|
|
|
|
public async Task<Option<ChannelWatermark>> GetWatermarkByName(string name)
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync();
|
|
|
|
List<ChannelWatermark> maybeWatermarks = await dbContext.ChannelWatermarks
|
|
.AsNoTracking()
|
|
.Where(cw => EF.Functions.Like(cw.Name, $"%{name}%"))
|
|
.ToListAsync();
|
|
|
|
return maybeWatermarks.HeadOrNone();
|
|
}
|
|
}
|