31 lines
892 B
C#
31 lines
892 B
C#
using FluentValidation;
|
|
using TakeoutSaaS.Application.App.Billings.Commands;
|
|
|
|
namespace TakeoutSaaS.Application.App.Billings.Validators;
|
|
|
|
/// <summary>
|
|
/// 更新账单状态命令验证器。
|
|
/// </summary>
|
|
public sealed class UpdateBillingStatusCommandValidator : AbstractValidator<UpdateBillingStatusCommand>
|
|
{
|
|
public UpdateBillingStatusCommandValidator()
|
|
{
|
|
// 1. 账单 ID 必填
|
|
RuleFor(x => x.BillingId)
|
|
.GreaterThan(0)
|
|
.WithMessage("账单 ID 必须大于 0");
|
|
|
|
// 2. 状态枚举校验
|
|
RuleFor(x => x.NewStatus)
|
|
.IsInEnum()
|
|
.WithMessage("新状态无效");
|
|
|
|
// 3. 备注长度限制(可选)
|
|
RuleFor(x => x.Notes)
|
|
.MaximumLength(500)
|
|
.WithMessage("备注不能超过 500 个字符")
|
|
.When(x => !string.IsNullOrWhiteSpace(x.Notes));
|
|
}
|
|
}
|
|
|