Update scheduling parameters and refactor channel endpoints: extend HorizonDays to 7 and RetentionDays to 90 in appsettings.json. Consolidate channel-related endpoint logic by removing obsolete files and enhancing the ShowEndpoints with audience and genre management capabilities. Improve error handling and streamline command handlers for channel operations.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using LiteCqrs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Common.Models;
|
||||
|
||||
namespace TeleWave.Application.Programming.Groups.GetGroup;
|
||||
|
||||
public sealed class GetGroupQueryHandler(IAppDbContext dbContext, GroupElementResolver resolver)
|
||||
: IQueryHandler<GetGroupQuery, Result<GroupDto>>
|
||||
{
|
||||
public async Task<Result<GroupDto>> Handle(
|
||||
GetGroupQuery query,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var group = await dbContext
|
||||
.Groups.AsNoTracking()
|
||||
.Include(g => g.Items)
|
||||
.FirstOrDefaultAsync(g => g.Id == query.Id, cancellationToken);
|
||||
if (group is null)
|
||||
return Result.Failure<GroupDto>(GroupErrors.NotFound);
|
||||
|
||||
var info = await resolver.ResolveAsync(
|
||||
group.Items.Select(i => (i.ElementKind, i.ElementId)),
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
var items = group
|
||||
.Items.OrderBy(i => i.Position)
|
||||
.Select(i =>
|
||||
{
|
||||
info.TryGetValue((i.ElementKind, i.ElementId), out var element);
|
||||
return new GroupItemDto(
|
||||
i.Id,
|
||||
i.ElementKind,
|
||||
i.ElementId,
|
||||
// Элемент мог исчезнуть из библиотеки между чисткой и чтением — показываем прочерк,
|
||||
// а не роняем весь экран группы.
|
||||
element?.Name ?? "—",
|
||||
i.Weight,
|
||||
i.Position,
|
||||
element?.UnitCount ?? 0,
|
||||
element?.ShowKind,
|
||||
element?.Audience,
|
||||
element?.Year,
|
||||
element?.PosterImageId
|
||||
);
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Result.Success(
|
||||
new GroupDto(
|
||||
group.Id,
|
||||
group.Name,
|
||||
group.Description,
|
||||
GroupFilter.FromJson(group.FilterJson),
|
||||
group.ItemCount,
|
||||
group.UnitCount,
|
||||
group.TotalDuration.TotalSeconds,
|
||||
group.StatsComputedAt,
|
||||
items
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user