| using FluentValidation; | |
| namespace AiDevProject.Core.Validation; | |
| /// <summary> | |
| /// User creation validator. | |
| /// </summary> | |
| public class CreateUserValidator : AbstractValidator<CreateUserRequest> | |
| { | |
| public CreateUserValidator() | |
| { | |
| RuleFor(x => x.Email) | |
| .NotEmpty().WithMessage("Email is required") | |
| .EmailAddress().WithMessage("Invalid email format"); | |
| RuleFor(x => x.Password) | |
| .NotEmpty().WithMessage("Password is required") | |
| .MinimumLength(8).WithMessage("Password must be at least 8 characters") | |
| .Matches(@"[A-Z]").WithMessage("Password must contain uppercase letter") | |
| .Matches(@"[a-z]").WithMessage("Password must contain lowercase letter") | |
| .Matches(@"[0-9]").WithMessage("Password must contain number"); | |
| RuleFor(x => x.Name) | |
| .MaximumLength(100).WithMessage("Name too long") | |
| .When(x => !string.IsNullOrEmpty(x.Name)); | |
| } | |
| } | |
| /// <summary> | |
| /// User creation request DTO. | |
| /// </summary> | |
| public record CreateUserRequest( | |
| string Email, | |
| string Password, | |
| string? Name = null | |
| ); | |