| | | 1 | | using ArturRios.Heimdall.Shared.Messages; |
| | | 2 | | using FluentValidation; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.Command.Input.Validation; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Input validation for <see cref="CreateScopeCommand" /> (UC-01, step 2 / AF-01b). Only checks |
| | | 8 | | /// the shape of the request — including the field lengths the columns impose, so an overlong |
| | | 9 | | /// value is a named 400 here rather than the persistence layer's unclassified data-access |
| | | 10 | | /// failure; business rules that require data access (name uniqueness, owner eligibility) are |
| | | 11 | | /// enforced by the handler. |
| | | 12 | | /// </summary> |
| | | 13 | | public class CreateScopeCommandValidator : AbstractValidator<CreateScopeCommand> |
| | | 14 | | { |
| | 16 | 15 | | public CreateScopeCommandValidator() |
| | | 16 | | { |
| | 16 | 17 | | RuleFor(command => command.Name) |
| | 16 | 18 | | .NotEmpty() |
| | 16 | 19 | | .WithMessage(ScopeMessages.NameRequired) |
| | 16 | 20 | | .MaximumLength(200) |
| | 16 | 21 | | .WithMessage(ScopeMessages.NameTooLong); |
| | | 22 | | |
| | | 23 | | // FluentValidation's MaximumLength rule skips a null argument, so only a non-null overlong |
| | | 24 | | // description is rejected — matching how the Application and ScopePermission validators |
| | | 25 | | // treat their optional descriptions. |
| | 16 | 26 | | RuleFor(command => command.Description) |
| | 16 | 27 | | .MaximumLength(500) |
| | 16 | 28 | | .WithMessage(ScopeMessages.DescriptionTooLong); |
| | | 29 | | |
| | 16 | 30 | | RuleFor(command => command.OwnerIds) |
| | 16 | 31 | | .NotEmpty() |
| | 16 | 32 | | .WithMessage(ScopeMessages.AtLeastOneOwnerRequired); |
| | 16 | 33 | | } |
| | | 34 | | } |