Files
ReC/src/ReC.Application/Common/Validations/InsertObjectProcedureValidator.cs
TekH 563375f6e3 Refactor validator to use nested property accessors
Update InsertObjectProcedureValidator to reference nested properties (e.g., x.Action.ProfileId instead of x.ActionProfileId) throughout all entity validation rules. Adjust .When conditions accordingly to match the new data model structure with grouped sub-objects.
2026-01-14 13:17:10 +01:00

87 lines
3.1 KiB
C#

using FluentValidation;
using ReC.Application.Common.Procedures.InsertProcedure;
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.Action.ProfileId)
.NotNull()
.WithMessage("ACTION requires ActionProfileId (maps to @pACTION_PROFILE_ID).");
RuleFor(x => x.Action.EndpointId)
.NotNull()
.WithMessage("ACTION requires ActionEndpointId (maps to @pACTION_ENDPOINT_ID).");
});
// ENDPOINT validation
When(x => x.Entity == "ENDPOINT", () =>
{
RuleFor(x => x.Endpoint.Uri)
.NotEmpty()
.WithMessage("ENDPOINT requires EndpointUri (maps to @pENDPOINT_URI).")
.MaximumLength(2000);
});
// PROFILE validation
When(x => x.Entity == "PROFILE", () =>
{
RuleFor(x => x.Profile.Name)
.NotEmpty()
.WithMessage("PROFILE requires ProfileName (maps to @pPROFILE_NAME).")
.MaximumLength(50);
RuleFor(x => x.Profile.Mandantor)
.MaximumLength(50)
.When(x => x.Profile.Mandantor != null);
RuleFor(x => x.Profile.Description)
.MaximumLength(250)
.When(x => x.Profile.Description != null);
});
// RESULT validation
When(x => x.Entity == "RESULT", () =>
{
RuleFor(x => x.Result.ActionId)
.NotNull()
.WithMessage("RESULT requires ResultActionId (maps to @pRESULT_ACTION_ID).");
RuleFor(x => x.Result.StatusId)
.NotNull()
.WithMessage("RESULT requires ResultStatusId (maps to @pRESULT_STATUS_ID).");
});
// ENDPOINT_PARAMS validation
When(x => x.Entity == "ENDPOINT_PARAMS", () =>
{
RuleFor(x => x.EndpointParams.GroupId)
.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.Endpoint.Description)
.MaximumLength(250)
.When(x => x.Endpoint.Description != null);
RuleFor(x => x.EndpointAuth.Description)
.MaximumLength(250)
.When(x => x.EndpointAuth.Description != null);
}
}