Reformat RuleBuilder in ChangeColorValidator

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

View File

@@ -16,34 +16,29 @@ public sealed class ChangeColorsRequestValidator
{
public ChangeColorsRequestValidator()
{
When(x => x.BannerTop is not null, () =>
{
RuleFor(x => x.BannerTop)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #");
});
When(x => x.BannerBottom is not null, () =>
{
RuleFor(x => x.BannerBottom)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #");
});
When(x => x.Accent is not null, () =>
{
RuleFor(x => x.Accent)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #");
});
When(x => x.Menu is not null, () =>
{
RuleFor(x => x.Menu)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #");
});
RuleFor(x => x.BannerTop)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #")
.When(x => x.BannerTop is not null);
RuleFor(x => x.BannerBottom)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #")
.When(x => x.BannerBottom is not null);
RuleFor(x => x.Accent)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #")
.When(x => x.Accent is not null);
RuleFor(x => x.Menu)
.MinimumLength(4).WithMessage("The minimum value should be in the format #444")
.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 #")
.When(x => x.Menu is not null);
}
}
@@ -57,7 +52,9 @@ public class ChangeColorsHandler(
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
.Creators