using Hutopy.Modules.Creators.Data; namespace Hutopy.Modules.Creators.Features; [PublicAPI] public record ChangeNameRequest( Guid CreatorId, string Name); [PublicAPI] internal sealed class ChangeNameRequestValidator : Validator { public ChangeNameRequestValidator() { RuleFor(r => r.Name) .NotNull().WithMessage("You should specify the Name") .NotEmpty().WithMessage("You should specify a valid/not empty Name"); } } [PublicAPI] public class ChangeNameHandler( CreatorsDbContext context) : Endpoint { public override void Configure() { Post("/api/creators/{CreatorId}/name"); Options(o => o.WithTags("Creators")); } public override async Task HandleAsync( ChangeNameRequest request, CancellationToken ct) { Creator creator = await context .Creators .SingleAsync( c => c.Id == request.CreatorId, ct); creator.Name = request.Name; await context.SaveChangesAsync(ct); await SendOkAsync(ct); } }