Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring Back Validators to Nodes Module #40

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,37 @@ public CreateNodeCommandValidator()
RuleFor(x => x.Node.Title)
.NotEmpty().WithMessage("Title is required.")
.MaximumLength(100).WithMessage("Title must not exceed 100 characters.");

RuleFor(x => x.Node.Description)
.NotEmpty().WithMessage("Description is required.")
.MaximumLength(500).WithMessage("Description must not exceed 500 characters.");

// ToDo: Add remaining Node command validators
RuleFor(x => x.Node.Timestamp)
.LessThanOrEqualTo(DateTime.Now).WithMessage("Timestamp cannot be in the future.");

RuleFor(x => x.Node.Importance)
.InclusiveBetween(1, 10).WithMessage("Importance must be between 1 and 10.");

RuleFor(x => x.Node.Phase)
.NotEmpty().WithMessage("Phase is required.");

RuleFor(x => x.Node)
.NotNull().WithMessage("Node cannot be null.")
.DependentRules(() =>
{
RuleFor(x => x.Node.Categories)
.Must(categories => categories != null && categories.Count > 0)
.WithMessage("At least one category must be provided.");

RuleFor(x => x.Node.Tags)
.Must(tags => tags != null && tags.Count > 0)
.WithMessage("At least one tag must be provided.");
});

RuleForEach(x => x.Node.Categories)
.MaximumLength(50).WithMessage("Category must not exceed 50 characters.");

RuleForEach(x => x.Node.Tags)
.MaximumLength(50).WithMessage("Tag must not exceed 50 characters.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
config.AddOpenBehavior(typeof(ValidationBehavior<,>));
config.AddOpenBehavior(typeof(LoggingBehavior<,>));
});

services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());

return services;
}
Expand Down
Loading