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,12 @@
|
||||
using LiteCqrs;
|
||||
using TeleWave.Application.Common.Models;
|
||||
|
||||
namespace TeleWave.Application.Library.SetShowGenres;
|
||||
|
||||
/// <summary>Полностью заменяет набор жанров шоу. <paramref name="PrimaryGenreId"/> — какой считать
|
||||
/// основным; если он не входит в набор, основным станет первый из списка.</summary>
|
||||
public sealed record SetShowGenresCommand(
|
||||
Guid ShowId,
|
||||
IReadOnlyList<Guid> GenreIds,
|
||||
Guid? PrimaryGenreId = null
|
||||
) : ICommand<Result>;
|
||||
@@ -0,0 +1,37 @@
|
||||
using LiteCqrs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Common.Models;
|
||||
using TeleWave.Application.Library.Genres;
|
||||
|
||||
namespace TeleWave.Application.Library.SetShowGenres;
|
||||
|
||||
public sealed class SetShowGenresCommandHandler(IAppDbContext dbContext)
|
||||
: ICommandHandler<SetShowGenresCommand, Result>
|
||||
{
|
||||
public async Task<Result> Handle(
|
||||
SetShowGenresCommand command,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var show = await dbContext
|
||||
.Shows.Include(s => s.Genres)
|
||||
.FirstOrDefaultAsync(s => s.Id == command.ShowId, cancellationToken);
|
||||
if (show is null)
|
||||
return Result.Failure(ShowErrors.NotFound);
|
||||
|
||||
var ids = command.GenreIds.Distinct().ToList();
|
||||
if (ids.Count > 0)
|
||||
{
|
||||
// Ссылка на несуществующий жанр упала бы нарушением внешнего ключа — проверяем заранее.
|
||||
var known = await dbContext
|
||||
.Genres.Where(g => ids.Contains(g.Id))
|
||||
.CountAsync(cancellationToken);
|
||||
if (known != ids.Count)
|
||||
return Result.Failure(GenreErrors.NotFound);
|
||||
}
|
||||
|
||||
show.SetGenres(ids, command.PrimaryGenreId);
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user