Skip to content

Commit

Permalink
Bring Back Validators to Nodes Module (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaVetnic authored Jan 3, 2025
1 parent 2c6e2e7 commit 24c0491
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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

0 comments on commit 24c0491

Please sign in to comment.