using BuildFlow.Platform.Application.Menus.DTOs;
namespace BuildFlow.Host.Endpoints.Platform.Menus;
///
/// 创建菜单请求校验。
///
public class CreateMenuRequestValidator : Validator
{
public CreateMenuRequestValidator()
{
// Name 可选:留空时由后端根据 Code 派生,无需用户填写。
When(x => x.Name is not null, () =>
{
RuleFor(x => x.Name!).MaximumLength(100).WithMessage("菜单路由名称长度不能超过 100 个字符");
});
RuleFor(x => x.Path).NotEmpty().WithMessage("路由路径不能为空")
.MaximumLength(200).WithMessage("路由路径长度不能超过 200 个字符");
RuleFor(x => x.Title).NotEmpty().WithMessage("菜单标题不能为空")
.MaximumLength(100).WithMessage("菜单标题长度不能超过 100 个字符");
When(x => x.Component is not null, () =>
{
RuleFor(x => x.Component!).MaximumLength(200).WithMessage("组件路径长度不能超过 200 个字符");
});
When(x => x.Authority is not null, () =>
{
RuleFor(x => x.Authority!).MaximumLength(200).WithMessage("Authority 长度不能超过 200 个字符");
});
}
}