24 lines
714 B
C#
24 lines
714 B
C#
using FluentValidation;
|
|
using ExpenseTracker.Domain.Enums;
|
|
|
|
namespace ExpenseTracker.Application.Transactions.Commands.Create;
|
|
|
|
public class CreateTransactionCommandValidator : AbstractValidator<CreateTransactionCommand>
|
|
{
|
|
public CreateTransactionCommandValidator()
|
|
{
|
|
RuleFor(e => e.Amount)
|
|
.NotEmpty();
|
|
|
|
RuleFor(e => e.Category)
|
|
.Must(c => Category.FromName(c) is not null)
|
|
.WithMessage(c => $"'{nameof(c.Category)}' must be one of the following: '{String.Join("', ", Category.Enumerations.Values.Select(v => v.Name))}'.");
|
|
|
|
RuleFor(e => e.Time)
|
|
.NotEmpty();
|
|
|
|
RuleFor(e => e.Description)
|
|
.Length(0, 256);
|
|
}
|
|
}
|