26 lines
836 B
C#
26 lines
836 B
C#
using FluentValidation;
|
|
using LittleShop.DTOs;
|
|
|
|
namespace LittleShop.Validators;
|
|
|
|
public class CreateProductDtoValidator : AbstractValidator<CreateProductDto>
|
|
{
|
|
public CreateProductDtoValidator()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.NotEmpty().WithMessage("Product name is required")
|
|
.MaximumLength(200).WithMessage("Product name cannot exceed 200 characters");
|
|
|
|
RuleFor(x => x.Description)
|
|
.NotEmpty().WithMessage("Product description is required");
|
|
|
|
RuleFor(x => x.BasePrice)
|
|
.GreaterThan(0).WithMessage("Base price must be greater than 0");
|
|
|
|
RuleFor(x => x.ProductWeight)
|
|
.GreaterThan(0).WithMessage("Product weight must be greater than 0");
|
|
|
|
RuleFor(x => x.CategoryId)
|
|
.NotEmpty().WithMessage("Category is required");
|
|
}
|
|
} |