added validators in project

This commit is contained in:
2026-03-10 09:52:31 +01:00
parent 2e7b9e5154
commit 9f858df5f8
17 changed files with 558 additions and 188 deletions

View File

@@ -0,0 +1,49 @@
using BookHive.DTO.Author;
using FastEndpoints;
using FluentValidation;
namespace BookHive.Validators.Authors;
public class UpdateAuthorDtoValidator : Validator<UpdateAuthorDto>
{
public UpdateAuthorDtoValidator()
{
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("First name is required.")
.MaximumLength(100)
.WithMessage("First name cannot exceed 100 characters.")
.MinimumLength(2)
.WithMessage("First name must exceed 2 characters.");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("Last name is required.")
.MaximumLength(100)
.WithMessage("Last name cannot exceed 100 characters.")
.MinimumLength(2)
.WithMessage("Last name must exceed 2 characters.");
RuleFor(x => x.Biography)
.MaximumLength(2000)
.WithMessage("Biography cannot exceed 2000 characters.")
.MinimumLength(2)
.WithMessage("Biography must exceed 2 characters.");
RuleFor(x => x.BirthDate)
.NotEmpty()
.WithMessage("Birth date is required.")
.LessThan(DateOnly.FromDateTime(DateTime.Now))
.WithMessage("Birth date cannot be in the future.");
RuleFor(x => x.Nationality)
.NotEmpty()
.WithMessage("Nationality is required.")
.MaximumLength(60)
.WithMessage("Nationality cannot exceed 60 characters.");
}
}