From bd4046a6c1793096c490a1b303ffa929b7c69c72 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 12 Jan 2026 16:03:10 +0100 Subject: [PATCH] Add InsertObjectProcedureValidator with entity-specific rules Introduced InsertObjectProcedureValidator using FluentValidation to enforce required fields and string length constraints for InsertObjectProcedure. Validation rules are applied conditionally based on the Entity type, ensuring correct data for ACTION, ENDPOINT, PROFILE, RESULT, and ENDPOINT_PARAMS. Optional string fields also receive length checks. --- .../InsertObjectProcedureValidator.cs | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/ReC.Application/Common/Validations/InsertObjectProcedureValidator.cs diff --git a/src/ReC.Application/Common/Validations/InsertObjectProcedureValidator.cs b/src/ReC.Application/Common/Validations/InsertObjectProcedureValidator.cs new file mode 100644 index 0000000..6593e04 --- /dev/null +++ b/src/ReC.Application/Common/Validations/InsertObjectProcedureValidator.cs @@ -0,0 +1,87 @@ +using FluentValidation; +using ReC.Application.Common.Procedures; + +namespace ReC.Application.Common.Validations; + +public class InsertObjectProcedureValidator : AbstractValidator +{ + public InsertObjectProcedureValidator() + { + // ENTITY must be one of the allowed values + RuleFor(x => x.Entity) + .NotEmpty() + .Must(e => e is "ACTION" or "ENDPOINT" or "ENDPOINT_AUTH" or "ENDPOINT_PARAMS" or "PROFILE" or "RESULT") + .WithMessage("ENTITY must be one of: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT."); + + // ACTION validation + When(x => x.Entity == "ACTION", () => + { + RuleFor(x => x.ActionProfileId) + .NotNull() + .WithMessage("ACTION requires ActionProfileId (maps to @pACTION_PROFILE_ID)."); + + RuleFor(x => x.ActionEndpointId) + .NotNull() + .WithMessage("ACTION requires ActionEndpointId (maps to @pACTION_ENDPOINT_ID)."); + }); + + // ENDPOINT validation + When(x => x.Entity == "ENDPOINT", () => + { + RuleFor(x => x.EndpointUri) + .NotEmpty() + .WithMessage("ENDPOINT requires EndpointUri (maps to @pENDPOINT_URI).") + .MaximumLength(2000); + }); + + // PROFILE validation + When(x => x.Entity == "PROFILE", () => + { + RuleFor(x => x.ProfileName) + .NotEmpty() + .WithMessage("PROFILE requires ProfileName (maps to @pPROFILE_NAME).") + .MaximumLength(50); + + RuleFor(x => x.ProfileMandantor) + .MaximumLength(50) + .When(x => x.ProfileMandantor != null); + + RuleFor(x => x.ProfileDescription) + .MaximumLength(250) + .When(x => x.ProfileDescription != null); + }); + + // RESULT validation + When(x => x.Entity == "RESULT", () => + { + RuleFor(x => x.ResultActionId) + .NotNull() + .WithMessage("RESULT requires ResultActionId (maps to @pRESULT_ACTION_ID)."); + + RuleFor(x => x.ResultStatusId) + .NotNull() + .WithMessage("RESULT requires ResultStatusId (maps to @pRESULT_STATUS_ID)."); + }); + + // ENDPOINT_PARAMS validation + When(x => x.Entity == "ENDPOINT_PARAMS", () => + { + RuleFor(x => x.EndpointParamsGroupId) + .NotNull() + .WithMessage("ENDPOINT_PARAMS requires EndpointParamsGroupId (maps to @pENDPOINT_PARAMS_GROUP_ID)."); + }); + + // Simple length guards for some string fields (optional but cheap) + RuleFor(x => x.AddedWho) + .MaximumLength(50) + .When(x => x.AddedWho != null); + + RuleFor(x => x.EndpointDescription) + .MaximumLength(250) + .When(x => x.EndpointDescription != null); + + RuleFor(x => x.EndpointAuthDescription) + .MaximumLength(250) + .When(x => x.EndpointAuthDescription != null); + } +} \ No newline at end of file