36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using ExpenseTracker.Api.DTOs;
|
|
using FluentValidation;
|
|
|
|
namespace ExpenseTracker.Api.Validators;
|
|
|
|
public class CreateEntryDtoValidator : AbstractValidator<CreateEntryDto>
|
|
{
|
|
public CreateEntryDtoValidator()
|
|
{
|
|
RuleFor(x => x.Type)
|
|
.NotEmpty()
|
|
.WithMessage("Type is required.")
|
|
.Must(t => t == "INCOME" || t == "EXPENSE")
|
|
.WithMessage("Type must be INCOME or EXPENSE.");
|
|
|
|
RuleFor(x => x.Amount)
|
|
.GreaterThan(0)
|
|
.WithMessage("Amount must be greater than 0.");
|
|
|
|
RuleFor(x => x.Label)
|
|
.NotEmpty()
|
|
.WithMessage("Label is required.")
|
|
.MaximumLength(200)
|
|
.WithMessage("Label must not exceed 200 characters.");
|
|
|
|
RuleFor(x => x.EntryDate)
|
|
.NotEqual(default(DateOnly))
|
|
.WithMessage("EntryDate is required.");
|
|
|
|
RuleFor(x => x.CategoryId)
|
|
.NotNull()
|
|
.WithMessage("CategoryId is required for EXPENSE entries.")
|
|
.When(x => x.Type == "EXPENSE");
|
|
}
|
|
}
|