Add rename show functionality: implement API endpoint for renaming shows, update Show model to support name changes, and enhance ShowMetadataCard UI for name input. Update translations for new UI elements to improve user experience.
This commit is contained in:
@@ -7,6 +7,7 @@ using TeleWave.Application.Library.DeleteShow;
|
||||
using TeleWave.Application.Library.GetShow;
|
||||
using TeleWave.Application.Library.ListShows;
|
||||
using TeleWave.Application.Library.RemoveEpisode;
|
||||
using TeleWave.Application.Library.RenameShow;
|
||||
using TeleWave.Application.Library.SetShowOriginalName;
|
||||
using TeleWave.Infrastructure.Identity;
|
||||
|
||||
@@ -23,6 +24,7 @@ public static class ShowEndpoints
|
||||
admin.MapPost("", CreateShow).Produces<CreatedIdResponse>(StatusCodes.Status201Created);
|
||||
admin.MapGet("", ListShows).Produces<IReadOnlyList<ShowSummaryDto>>();
|
||||
admin.MapGet("/{id:guid}", GetShow).Produces<ShowDto>();
|
||||
admin.MapPut("/{id:guid}/name", Rename).Produces(StatusCodes.Status204NoContent);
|
||||
admin
|
||||
.MapPut("/{id:guid}/original-name", SetOriginalName)
|
||||
.Produces(StatusCodes.Status204NoContent);
|
||||
@@ -65,6 +67,17 @@ public static class ShowEndpoints
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
private static async Task<IResult> Rename(
|
||||
Guid id,
|
||||
RenameShowBody body,
|
||||
ISender sender,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var result = await sender.Send(new RenameShowCommand(id, body.Name), cancellationToken);
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
private static async Task<IResult> SetOriginalName(
|
||||
Guid id,
|
||||
SetShowOriginalNameBody body,
|
||||
@@ -116,4 +129,6 @@ public static class ShowEndpoints
|
||||
|
||||
public sealed record AddEpisodeBody(Guid MediaAssetId);
|
||||
|
||||
public sealed record RenameShowBody(string Name);
|
||||
|
||||
public sealed record SetShowOriginalNameBody(string? OriginalName);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
using LiteCqrs;
|
||||
using TeleWave.Application.Common.Models;
|
||||
|
||||
namespace TeleWave.Application.Library.RenameShow;
|
||||
|
||||
/// <summary>Изменить отображаемое название шоу.</summary>
|
||||
public sealed record RenameShowCommand(Guid Id, string Name) : ICommand<Result>;
|
||||
@@ -0,0 +1,23 @@
|
||||
using LiteCqrs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Common.Models;
|
||||
|
||||
namespace TeleWave.Application.Library.RenameShow;
|
||||
|
||||
public sealed class RenameShowCommandHandler(IAppDbContext dbContext)
|
||||
: ICommandHandler<RenameShowCommand, Result>
|
||||
{
|
||||
public async Task<Result> Handle(RenameShowCommand 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.SetName(command.Name.Trim());
|
||||
return Result.Success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace TeleWave.Application.Library.RenameShow;
|
||||
|
||||
public sealed class RenameShowCommandValidator : AbstractValidator<RenameShowCommand>
|
||||
{
|
||||
public RenameShowCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().MaximumLength(256);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,9 @@ public class Show
|
||||
Description = description;
|
||||
}
|
||||
|
||||
/// <summary>Изменить отображаемое название (на экранах). Метаданные ищутся по <see cref="OriginalName"/>.</summary>
|
||||
public void SetName(string name) => Name = name;
|
||||
|
||||
/// <summary>Задать/снять оригинальное название (пустая строка трактуется как отсутствие).</summary>
|
||||
public void SetOriginalName(string? originalName) => OriginalName = Normalize(originalName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user