Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using ExpenseTracker.Api.DTOs;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ExpenseTracker.Api.Validators;
|
||||
|
||||
public class UpdateEntryDtoValidator : AbstractValidator<UpdateEntryDto>
|
||||
{
|
||||
public UpdateEntryDtoValidator()
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user