yessir
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user