From 0316f302ee9223b062fbd3a0bc30312e437ae8a0 Mon Sep 17 00:00:00 2001 From: Francis Pion Date: Thu, 18 Jul 2024 16:51:44 -0400 Subject: [PATCH] Validators. --- .../Validators/DateTimeFieldValueValidator.cs | 9 ++++++++- .../Validators/DateTimePropertiesValidator.cs | 6 +++++- .../Validators/NumberFieldValueValidator.cs | 11 ++++++++++- .../Validators/NumberPropertiesValidator.cs | 8 +++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimeFieldValueValidator.cs b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimeFieldValueValidator.cs index 6dd2ff6..18bbbf5 100644 --- a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimeFieldValueValidator.cs +++ b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimeFieldValueValidator.cs @@ -7,6 +7,13 @@ public class DateTimeFieldValueValidator : AbstractValidator { public DateTimeFieldValueValidator(IDateTimeProperties properties) { - // TODO(fpion): implement + if (properties.MinimumValue.HasValue) + { + RuleFor(x => x).GreaterThanOrEqualTo(properties.MinimumValue.Value); + } + if (properties.MaximumValue.HasValue) + { + RuleFor(x => x).LessThanOrEqualTo(properties.MaximumValue.Value); + } } } diff --git a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimePropertiesValidator.cs b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimePropertiesValidator.cs index 6b0981c..3e094df 100644 --- a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimePropertiesValidator.cs +++ b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/DateTimePropertiesValidator.cs @@ -7,6 +7,10 @@ public class DateTimePropertiesValidator : AbstractValidator x.MinimumValue.HasValue && x.MaximumValue.HasValue, () => + { + RuleFor(x => x.MinimumValue!.Value).LessThanOrEqualTo(x => x.MaximumValue!.Value); + RuleFor(x => x.MaximumValue!.Value).GreaterThanOrEqualTo(x => x.MinimumValue!.Value); + }); } } diff --git a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberFieldValueValidator.cs b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberFieldValueValidator.cs index 8978958..be56fe8 100644 --- a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberFieldValueValidator.cs +++ b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberFieldValueValidator.cs @@ -7,6 +7,15 @@ public class NumberFieldValueValidator : AbstractValidator { public NumberFieldValueValidator(INumberProperties properties) { - // TODO(fpion): implement + if (properties.MinimumValue.HasValue) + { + RuleFor(x => x).GreaterThanOrEqualTo(properties.MinimumValue.Value); + } + if (properties.MaximumValue.HasValue) + { + RuleFor(x => x).LessThanOrEqualTo(properties.MaximumValue.Value); + } + + // ISSUE: https://github.com/Logitar/CMS/issues/28 } } diff --git a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberPropertiesValidator.cs b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberPropertiesValidator.cs index 5e65536..951e1d4 100644 --- a/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberPropertiesValidator.cs +++ b/backend/src/Logitar.Cms.Core/FieldTypes/Validators/NumberPropertiesValidator.cs @@ -7,6 +7,12 @@ public class NumberPropertiesValidator : AbstractValidator { public NumberPropertiesValidator() { - // TODO(fpion): implement + When(x => x.MinimumValue.HasValue && x.MaximumValue.HasValue, () => + { + RuleFor(x => x.MinimumValue!.Value).LessThanOrEqualTo(x => x.MaximumValue!.Value); + RuleFor(x => x.MaximumValue!.Value).GreaterThanOrEqualTo(x => x.MinimumValue!.Value); + }); + + // ISSUE: https://github.com/Logitar/CMS/issues/28 } }