This commit is contained in:
2025-11-03 07:44:17 -05:00
parent d2a4639c0e
commit a0426aa0d1
13 changed files with 98 additions and 12 deletions
+40
View File
@@ -0,0 +1,40 @@
using FluentValidation;
using Svrnty.CQRS.Abstractions;
namespace Svrnty.Sample;
public record AddUserCommand
{
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public int Age { get; set; }
}
public class AddUserCommandValidator : AbstractValidator<AddUserCommand>
{
public AddUserCommandValidator()
{
RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("Email is required")
.EmailAddress()
.WithMessage("Email must be a valid email address");
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage("Name is required");
RuleFor(x => x.Age)
.GreaterThan(0)
.WithMessage("Age must be greater than 0");
}
}
public class AddUserCommandHandler : ICommandHandler<AddUserCommand, int>
{
public Task<int> HandleAsync(AddUserCommand command, CancellationToken cancellationToken = default)
{
// Simulate adding a user and returning ID
return Task.FromResult(123);
}
}