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.
This commit is contained in:
2026-01-12 16:03:10 +01:00
parent af6f94c1ed
commit bd4046a6c1

View File

@@ -0,0 +1,87 @@
using FluentValidation;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Common.Validations;
public class InsertObjectProcedureValidator : AbstractValidator<InsertObjectProcedure>
{
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);
}
}