Created all validators
This commit is contained in:
@@ -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("L’ISBN est obligatoire.")
|
||||
.Matches(@"^\d{13}$")
|
||||
.WithMessage("L’ISBN doit contenir exactement 13 chiffres.");
|
||||
.NotEmpty()
|
||||
.WithMessage("L’ISBN est obligatoire.")!
|
||||
.IsValidIsbn13();
|
||||
|
||||
RuleFor(x => x.PageCount)
|
||||
.GreaterThan(0)
|
||||
|
||||
@@ -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).");
|
||||
}
|
||||
}
|
||||
@@ -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, () =>
|
||||
{
|
||||
|
||||
@@ -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, () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user