Created all validators

This commit is contained in:
2026-03-10 10:43:28 +01:00
parent 9f858df5f8
commit 5c3419abc0
19 changed files with 54 additions and 34 deletions

View File

@@ -14,9 +14,9 @@ public class CreateBookDtoValidator : Validator<CreateBookDto>
.WithMessage("Le titre ne peut pas dépasser 200 caractères.");
RuleFor(x => x.Isbn)
.NotEmpty().WithMessage("LISBN est obligatoire.")
.Matches(@"^\d{13}$")
.WithMessage("LISBN doit contenir exactement 13 chiffres.");
.NotEmpty()
.WithMessage("LISBN est obligatoire.")!
.IsValidIsbn13();
RuleFor(x => x.PageCount)
.GreaterThan(0)

View File

@@ -26,6 +26,17 @@ public class CreateLoanDtoValidator : Validator<CreateLoanDto>
.GreaterThan(d => d.LoanDate)
.WithMessage("Due date must be in the future.")
.Must((loan, dueDate) => dueDate <= loan.LoanDate.AddDays(30))
.WithMessage("Due date must be in the future.");;
.WithMessage("Due date must be in the future.");
RuleFor(x => x.DueDate)
.Must((dto, dueDate) =>
{
var dayOfWeek = dto.LoanDate.DayOfWeek;
var isWeekend = dayOfWeek == DayOfWeek.Saturday
|| dayOfWeek == DayOfWeek.Sunday;
var maxDays = isWeekend ? 14 : 30;
return dueDate <= dto.LoanDate.AddDays(maxDays);
})
.WithMessage("La durée max est de 14j (week-end) ou 30j (semaine).");
}
}

View File

@@ -18,7 +18,7 @@ public class CreateReviewDtoValidator : Validator<CreateReviewDto>
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage("Rating must be between 1 and 5.");
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");
When(x => x.Comment is not null, () =>
{

View File

@@ -22,7 +22,7 @@ public class UpdateReviewDtoValidator : Validator<UpdateReviewDto>
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage("Rating must be between 1 and 5.");
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");
When(x => x.Comment is not null, () =>
{