feat: 增加分页排序与FluentValidation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Deliveries.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Deliveries.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 创建配送单命令验证器。
|
||||
/// </summary>
|
||||
public sealed class CreateDeliveryOrderCommandValidator : AbstractValidator<CreateDeliveryOrderCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public CreateDeliveryOrderCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.OrderId).GreaterThan(0);
|
||||
RuleFor(x => x.ProviderOrderId).MaximumLength(64);
|
||||
RuleFor(x => x.CourierName).MaximumLength(64);
|
||||
RuleFor(x => x.CourierPhone).MaximumLength(32);
|
||||
RuleFor(x => x.FailureReason).MaximumLength(256);
|
||||
RuleFor(x => x.DeliveryFee).GreaterThanOrEqualTo(0).When(x => x.DeliveryFee.HasValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Deliveries.Queries;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Deliveries.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 配送单列表查询验证器。
|
||||
/// </summary>
|
||||
public sealed class SearchDeliveryOrdersQueryValidator : AbstractValidator<SearchDeliveryOrdersQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public SearchDeliveryOrdersQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Page).GreaterThan(0);
|
||||
RuleFor(x => x.PageSize).InclusiveBetween(1, 200);
|
||||
RuleFor(x => x.SortBy).MaximumLength(64);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Deliveries.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Deliveries.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 更新配送单命令验证器。
|
||||
/// </summary>
|
||||
public sealed class UpdateDeliveryOrderCommandValidator : AbstractValidator<UpdateDeliveryOrderCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public UpdateDeliveryOrderCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.DeliveryOrderId).GreaterThan(0);
|
||||
RuleFor(x => x.OrderId).GreaterThan(0);
|
||||
RuleFor(x => x.ProviderOrderId).MaximumLength(64);
|
||||
RuleFor(x => x.CourierName).MaximumLength(64);
|
||||
RuleFor(x => x.CourierPhone).MaximumLength(32);
|
||||
RuleFor(x => x.FailureReason).MaximumLength(256);
|
||||
RuleFor(x => x.DeliveryFee).GreaterThanOrEqualTo(0).When(x => x.DeliveryFee.HasValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user