using LiteCqrs; using TeleWave.Api.Common; using TeleWave.Application.Library.Interstitials; using TeleWave.Application.Library.Interstitials.ImportInterstitials; using TeleWave.Application.Library.Interstitials.ListInterstitialBlocks; using TeleWave.Application.Library.Interstitials.ListInterstitials; using TeleWave.Infrastructure.Identity; namespace TeleWave.Api.Endpoints; /// /// Ролики-врезки: тот же Show(Kind = Interstitial), но со своим экраном (см. 6.7). Правка /// названия и удаление идут через обычные эндпоинты шоу — здесь только то, чего у библиотеки нет: /// список с длительностями, блоки и импорт загруженных файлов. /// public static class InterstitialEndpoints { public static IEndpointRouteBuilder MapInterstitialEndpoints(this IEndpointRouteBuilder app) { var admin = app.MapGroup("/api/admin/interstitials") .WithTags("Admin.Interstitials") .RequireAuthorization(policy => policy.RequireRole(RoleNames.Admin)); admin.MapGet("", List).Produces>(); admin.MapGet("/blocks", ListBlocks).Produces>(); admin.MapPost("/import", Import).Produces(); return app; } private static async Task List(ISender sender, CancellationToken cancellationToken) { var result = await sender.Send(new ListInterstitialsQuery(), cancellationToken); return Results.Ok(result); } private static async Task ListBlocks( ISender sender, CancellationToken cancellationToken ) { var result = await sender.Send(new ListInterstitialBlocksQuery(), cancellationToken); return Results.Ok(result); } private static async Task Import( ImportInterstitialsBody body, ISender sender, CancellationToken cancellationToken ) { var result = await sender.Send( new ImportInterstitialsCommand(body.MediaAssetIds), cancellationToken ); return result.IsSuccess ? Results.Ok(new ImportInterstitialsResponse(result.Value)) : result.ToHttpResult(); } } public sealed record ImportInterstitialsBody(IReadOnlyList MediaAssetIds); public sealed record ImportInterstitialsResponse(int Imported);