classlib/ExpenseTracker.Application/Transactions/Commands/Create/CreateTransactionCommandValidator.cs
2024-08-07 21:12:02 +03:00

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);
}
}