Reformat RuleBuilder in ChangeColorValidator

This commit is contained in:
2024-09-04 14:28:45 -04:00
parent 3e341e0019
commit a4a2c96922

View File

@@ -15,35 +15,30 @@ public sealed class ChangeColorsRequestValidator
: Validator<ChangeColorsRequest> : Validator<ChangeColorsRequest>
{ {
public ChangeColorsRequestValidator() public ChangeColorsRequestValidator()
{
When(x => x.BannerTop is not null, () =>
{ {
RuleFor(x => x.BannerTop) RuleFor(x => x.BannerTop)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444") .MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344")
.Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #")
}); .When(x => x.BannerTop is not null);
When(x => x.BannerBottom is not null, () =>
{
RuleFor(x => x.BannerBottom) RuleFor(x => x.BannerBottom)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444") .MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344")
.Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #")
}); .When(x => x.BannerBottom is not null);
When(x => x.Accent is not null, () =>
{
RuleFor(x => x.Accent) RuleFor(x => x.Accent)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444") .MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344")
.Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #")
}); .When(x => x.Accent is not null);
When(x => x.Menu is not null, () =>
{
RuleFor(x => x.Menu) RuleFor(x => x.Menu)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444") .MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344")
.Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #")
}); .When(x => x.Menu is not null);
} }
} }
@@ -57,7 +52,9 @@ public class ChangeColorsHandler(
Options(o => o.WithTags("Creators")); Options(o => o.WithTags("Creators"));
} }
public override async Task HandleAsync(ChangeColorsRequest request, CancellationToken ct) public override async Task HandleAsync(
ChangeColorsRequest request,
CancellationToken ct)
{ {
var creator = await context var creator = await context
.Creators .Creators