Files
TP-Fluent/BookHive/Validators/Reviews/UpdateReviewDtoValidator.cs
2026-03-17 10:27:53 +01:00

34 lines
944 B
C#

using BookHive.DTO.Review;
using FastEndpoints;
using FluentValidation;
namespace BookHive.Validators.Reviews;
public class UpdateReviewDtoValidator : Validator<UpdateReviewDto>
{
public UpdateReviewDtoValidator()
{
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Id is invalid.");
RuleFor(x => x.BookId)
.GreaterThan(0)
.WithMessage("Book id is invalid.");
RuleFor(x => x.MemberId)
.GreaterThan(0)
.WithMessage("Member id is invalid.");
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage(x => $"La note {x.Rating} est invalide. Elle doit être comprise entre 1 et 5.");
When(x => x.Comment is not null, () =>
{
RuleFor(x => x.Comment)
.MaximumLength(3000)
.WithMessage("Comment cannot exceed 3000 characters.");
});
}
}