45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using BookHive.DTO.Member;
|
|
using FastEndpoints;
|
|
using FluentValidation;
|
|
|
|
namespace BookHive.Validators.Members;
|
|
|
|
public class UpdateMemberDtoValidator : Validator<UpdateMemberDto>
|
|
{
|
|
public UpdateMemberDtoValidator()
|
|
{
|
|
RuleFor(x => x.Id)
|
|
.GreaterThan(0)
|
|
.WithMessage("Id is invalid.");
|
|
|
|
RuleFor(x => x.Email)
|
|
.NotEmpty()
|
|
.WithMessage("Email is required.")
|
|
.EmailAddress()
|
|
.WithMessage("Email is invalid.")
|
|
.MaximumLength(255)
|
|
.WithMessage("Email cannot be longer than 255 characters.");
|
|
|
|
RuleFor(x => x.FirstName)
|
|
.NotEmpty()
|
|
.WithMessage("First name is required.")
|
|
.MaximumLength(100)
|
|
.WithMessage("First name cannot be longer than 100 characters.")
|
|
.MinimumLength(2)
|
|
.WithMessage("First name cannot be shorter than 2 characters.");
|
|
|
|
RuleFor(x => x.LastName)
|
|
.NotEmpty()
|
|
.WithMessage("Last name is required.")
|
|
.MaximumLength(100)
|
|
.WithMessage("Last name cannot be longer than 100 characters.")
|
|
.MinimumLength(2)
|
|
.WithMessage("Last name cannot be shorter than 2 characters.");
|
|
|
|
RuleFor(x => x.MembershipDate)
|
|
.NotEmpty()
|
|
.WithMessage("Membership date is required.")
|
|
.Must(d => d <= DateOnly.FromDateTime(DateTime.Now))
|
|
.WithMessage("Membership date cannot be in the future.");
|
|
}
|
|
} |