using Hutopy.Modules.Creators.Data; namespace Hutopy.Modules.Creators.Features; [PublicAPI] public sealed class GetCreatorByIdRequest { public required Guid CreatorId { get; set; } } [UsedImplicitly] public sealed class GetCreatorByIdRequestValidator : Validator { public GetCreatorByIdRequestValidator() { RuleFor(r => r.CreatorId) .NotNull().WithMessage("You should specify the CreatorId") .NotEmpty().WithMessage("You should specify a valid/not empty CreatorId"); } } [PublicAPI] public class GetCreatorByIdHandler( CreatorsDbContext context) : Endpoint { public override void Configure() { Get("/api/creators/{CreatorId}"); Options(o => o.WithTags("Creators")); AllowAnonymous(); } public override async Task HandleAsync( GetCreatorByIdRequest req, CancellationToken ct) { Creator? creator = await context .Creators .FindAsync( [req.CreatorId], ct); if (creator is null) { await SendNotFoundAsync(ct); } else { await SendAsync(creator, cancellation: ct); } } }