added validators in project
This commit is contained in:
30
BookHive/Validators/Reviews/CreateReviewDtoValidator.cs
Normal file
30
BookHive/Validators/Reviews/CreateReviewDtoValidator.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using BookHive.DTO.Review;
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
|
||||
namespace BookHive.Validators.Reviews;
|
||||
|
||||
public class CreateReviewDtoValidator : Validator<CreateReviewDto>
|
||||
{
|
||||
public CreateReviewDtoValidator()
|
||||
{
|
||||
RuleFor(x => x.MemberId)
|
||||
.GreaterThan(0)
|
||||
.WithMessage("Member id is invalid.");
|
||||
|
||||
RuleFor(x => x.BookId)
|
||||
.GreaterThan(0)
|
||||
.WithMessage("Book id is invalid.");
|
||||
|
||||
RuleFor(x => x.Rating)
|
||||
.InclusiveBetween(1, 5)
|
||||
.WithMessage("Rating must be between 1 and 5.");
|
||||
|
||||
When(x => x.Comment is not null, () =>
|
||||
{
|
||||
RuleFor(x => x.Comment)
|
||||
.MaximumLength(3000)
|
||||
.WithMessage("Comment cannot exceed 3000 characters.");
|
||||
});
|
||||
}
|
||||
}
|
||||
34
BookHive/Validators/Reviews/UpdateReviewDtoValidator.cs
Normal file
34
BookHive/Validators/Reviews/UpdateReviewDtoValidator.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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("Rating must be between 1 and 5.");
|
||||
|
||||
When(x => x.Comment is not null, () =>
|
||||
{
|
||||
RuleFor(x => x.Comment)
|
||||
.MaximumLength(3000)
|
||||
.WithMessage("Comment cannot exceed 3000 characters.");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user