Add audience categorization for shows: implement ShowAudience type, update related API endpoints, and enhance frontend components for audience selection and display. Modify data structures to support audience information in show creation and retrieval processes.
This commit is contained in:
@@ -8,7 +8,9 @@ using TeleWave.Application.Library.GetShow;
|
||||
using TeleWave.Application.Library.ListShows;
|
||||
using TeleWave.Application.Library.RemoveEpisode;
|
||||
using TeleWave.Application.Library.RenameShow;
|
||||
using TeleWave.Application.Library.SetShowAudience;
|
||||
using TeleWave.Application.Library.SetShowOriginalName;
|
||||
using TeleWave.Domain.Library;
|
||||
using TeleWave.Infrastructure.Identity;
|
||||
|
||||
namespace TeleWave.Api.Endpoints;
|
||||
@@ -28,6 +30,7 @@ public static class ShowEndpoints
|
||||
admin
|
||||
.MapPut("/{id:guid}/original-name", SetOriginalName)
|
||||
.Produces(StatusCodes.Status204NoContent);
|
||||
admin.MapPut("/{id:guid}/audience", SetAudience).Produces(StatusCodes.Status204NoContent);
|
||||
admin.MapDelete("/{id:guid}", DeleteShow).Produces(StatusCodes.Status204NoContent);
|
||||
admin
|
||||
.MapPost("/{id:guid}/episodes", AddEpisode)
|
||||
@@ -98,6 +101,20 @@ public static class ShowEndpoints
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
private static async Task<IResult> SetAudience(
|
||||
Guid id,
|
||||
SetShowAudienceBody body,
|
||||
ISender sender,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var result = await sender.Send(
|
||||
new SetShowAudienceCommand(id, body.Audience),
|
||||
cancellationToken
|
||||
);
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
private static async Task<IResult> DeleteShow(
|
||||
Guid id,
|
||||
ISender sender,
|
||||
@@ -141,3 +158,5 @@ public sealed record AddEpisodeBody(Guid MediaAssetId);
|
||||
public sealed record RenameShowBody(string Name);
|
||||
|
||||
public sealed record SetShowOriginalNameBody(string? OriginalName);
|
||||
|
||||
public sealed record SetShowAudienceBody(ShowAudience Audience);
|
||||
|
||||
@@ -8,5 +8,6 @@ public sealed record CreateShowCommand(
|
||||
string Name,
|
||||
ShowKind Kind,
|
||||
string? Description,
|
||||
string? OriginalName = null
|
||||
string? OriginalName = null,
|
||||
ShowAudience Audience = ShowAudience.General
|
||||
) : ICommand<Result<Guid>>;
|
||||
|
||||
@@ -14,7 +14,8 @@ public sealed class CreateShowCommandHandler(IAppDbContext dbContext)
|
||||
command.Name,
|
||||
command.Kind,
|
||||
command.Description,
|
||||
command.OriginalName
|
||||
command.OriginalName,
|
||||
command.Audience
|
||||
);
|
||||
dbContext.Shows.Add(show);
|
||||
return Task.FromResult(Result.Success(show.Id));
|
||||
|
||||
@@ -61,6 +61,7 @@ public sealed class GetShowQueryHandler(IAppDbContext dbContext)
|
||||
show.Name,
|
||||
show.OriginalName,
|
||||
show.Kind,
|
||||
show.Audience,
|
||||
show.Description,
|
||||
show.MetadataProvider,
|
||||
show.MetadataExternalId,
|
||||
|
||||
@@ -46,6 +46,7 @@ public sealed class ListShowsQueryHandler(IAppDbContext dbContext)
|
||||
s.Name,
|
||||
s.OriginalName,
|
||||
s.Kind,
|
||||
s.Audience,
|
||||
s.Episodes.Count,
|
||||
seasons,
|
||||
s.Year,
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using LiteCqrs;
|
||||
using TeleWave.Application.Common.Models;
|
||||
using TeleWave.Domain.Library;
|
||||
|
||||
namespace TeleWave.Application.Library.SetShowAudience;
|
||||
|
||||
/// <summary>Задать категорию аудитории шоу (обычное/детское/взрослое).</summary>
|
||||
public sealed record SetShowAudienceCommand(Guid Id, ShowAudience Audience) : ICommand<Result>;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using LiteCqrs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Common.Models;
|
||||
|
||||
namespace TeleWave.Application.Library.SetShowAudience;
|
||||
|
||||
public sealed class SetShowAudienceCommandHandler(IAppDbContext dbContext)
|
||||
: ICommandHandler<SetShowAudienceCommand, Result>
|
||||
{
|
||||
public async Task<Result> Handle(
|
||||
SetShowAudienceCommand command,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var show = await dbContext.Shows.FirstOrDefaultAsync(
|
||||
s => s.Id == command.Id,
|
||||
cancellationToken
|
||||
);
|
||||
if (show is null)
|
||||
return Result.Failure(ShowErrors.NotFound);
|
||||
|
||||
show.SetAudience(command.Audience);
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ public sealed record ShowSummaryDto(
|
||||
string Name,
|
||||
string? OriginalName,
|
||||
ShowKind Kind,
|
||||
ShowAudience Audience,
|
||||
int EpisodeCount,
|
||||
int SeasonCount,
|
||||
int? Year,
|
||||
@@ -35,6 +36,7 @@ public sealed record ShowDto(
|
||||
string Name,
|
||||
string? OriginalName,
|
||||
ShowKind Kind,
|
||||
ShowAudience Audience,
|
||||
string? Description,
|
||||
string? MetadataProvider,
|
||||
string? MetadataExternalId,
|
||||
|
||||
@@ -18,6 +18,10 @@ public class Show
|
||||
|
||||
public string? Description { get; private set; }
|
||||
public ShowKind Kind { get; private set; }
|
||||
|
||||
/// <summary>Категория аудитории (обычное/детское/взрослое) — под будущие фильтры показа.</summary>
|
||||
public ShowAudience Audience { get; private set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; private set; }
|
||||
|
||||
// ── Метаданные (TMDb/OMDb/вручную) ──
|
||||
@@ -42,7 +46,8 @@ public class Show
|
||||
string name,
|
||||
ShowKind kind,
|
||||
string? description = null,
|
||||
string? originalName = null
|
||||
string? originalName = null,
|
||||
ShowAudience audience = ShowAudience.General
|
||||
) =>
|
||||
new()
|
||||
{
|
||||
@@ -51,9 +56,13 @@ public class Show
|
||||
OriginalName = Normalize(originalName),
|
||||
Kind = kind,
|
||||
Description = description,
|
||||
Audience = audience,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
/// <summary>Задать категорию аудитории (обычное/детское/взрослое).</summary>
|
||||
public void SetAudience(ShowAudience audience) => Audience = audience;
|
||||
|
||||
public void Rename(string name, string? description)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace TeleWave.Domain.Library;
|
||||
|
||||
/// <summary>Категория аудитории шоу (пригодится для фильтров/разграничения показа).</summary>
|
||||
public enum ShowAudience
|
||||
{
|
||||
/// <summary>Обычное — без ограничений (по умолчанию).</summary>
|
||||
General,
|
||||
|
||||
/// <summary>Детское.</summary>
|
||||
Kids,
|
||||
|
||||
/// <summary>Взрослое.</summary>
|
||||
Adult,
|
||||
}
|
||||
+1026
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TeleWave.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ShowAudience : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Audience",
|
||||
table: "Shows",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Audience",
|
||||
table: "Shows");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -587,6 +587,9 @@ namespace TeleWave.Infrastructure.Migrations
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("Audience")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user