Refactor insert procedures with entity-specific records

Refactored insert procedure modeling by introducing the IInsertProcedure interface and entity-specific Insert[Entity]Procedure records. Each entity now has its own record with relevant properties and a ToObjectProcedure() method, improving type safety, clarity, and extensibility for insert operations. Updated InsertObjectProcedure to use these new types.
This commit is contained in:
2026-01-14 09:18:52 +01:00
parent 1d31f2aff9
commit 854e36e71f

View File

@@ -6,86 +6,148 @@ using System.Text.Json;
namespace ReC.Application.Common.Procedures;
public interface IInsertProcedure
{
public InsertObjectProcedure ToObjectProcedure();
}
public record InsertActionProcedure : IInsertProcedure
{
public long? ProfileId { get; set; }
public bool? Active { get; set; }
public byte? Sequence { get; set; }
public long? EndpointId { get; set; }
public long? EndpointAuthId { get; set; }
public short? EndpointParamsId { get; set; }
public short? SqlConnectionId { get; set; }
public byte? TypeId { get; set; }
public string? PreSql { get; set; }
public string? HeaderSql { get; set; }
public string? BodySql { get; set; }
public string? PostSql { get; set; }
public byte? ErrorActionId { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "ACTION",
Action = this
};
}
}
public record InsertEndpointProcedure : IInsertProcedure
{
public bool? Active { get; set; }
public string? Description { get; set; }
public string? Uri { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT",
Endpoint = this
};
}
}
public record InsertEndpointAuthProcedure : IInsertProcedure
{
public bool? Active { get; set; }
public string? Description { get; set; }
public byte? TypeId { get; set; }
public string? ApiKey { get; set; }
public string? ApiValue { get; set; }
public bool? ApiKeyAddToId { get; set; }
public string? Token { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public string? Domain { get; set; }
public string? Workstation { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT_AUTH",
EndpointAuth = this
};
}
}
public record InsertProfileProcedure : IInsertProcedure
{
public bool? Active { get; set; }
public byte? TypeId { get; set; }
public string? Mandantor { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public byte? LogLevelId { get; set; }
public short? LanguageId { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "PROFILE",
Profile = this
};
}
}
public record InsertResultProcedure : IInsertProcedure
{
public long? ActionId { get; set; }
public short? StatusId { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "RESULT",
Result = this
};
}
}
public record InsertEndpointParamsProcedure : IInsertProcedure
{
public bool? Active { get; set; }
public string? Description { get; set; }
public short? GroupId { get; set; }
public byte? Sequence { get; set; }
public string? Key { get; set; }
public string? Value { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
EndpointParams = this
};
}
}
public record InsertObjectProcedure : IRequest<long>
{
public string Entity { get; set; } = "ACTION";
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// </summary>
public string Entity { get; set; } = null!;
public string? AddedWho { get; set; }
public ActionInfo Action { get; init; } = new();
public EndpointInfo Endpoint { get; init; } = new();
public EndpointAuthInfo EndpointAuth { get; init; } = new();
public ProfileInfo Profile { get; init; } = new();
public ResultInfo Result { get; init; } = new();
public EndpointParamsInfo EndpointParams { get; init; } = new();
public record ActionInfo
{
public long? ProfileId { get; set; }
public bool? Active { get; set; }
public byte? Sequence { get; set; }
public long? EndpointId { get; set; }
public long? EndpointAuthId { get; set; }
public short? EndpointParamsId { get; set; }
public short? SqlConnectionId { get; set; }
public byte? TypeId { get; set; }
public string? PreSql { get; set; }
public string? HeaderSql { get; set; }
public string? BodySql { get; set; }
public string? PostSql { get; set; }
public byte? ErrorActionId { get; set; }
}
public record EndpointInfo
{
public bool? Active { get; set; }
public string? Description { get; set; }
public string? Uri { get; set; }
}
public record EndpointAuthInfo
{
public bool? Active { get; set; }
public string? Description { get; set; }
public byte? TypeId { get; set; }
public string? ApiKey { get; set; }
public string? ApiValue { get; set; }
public bool? ApiKeyAddToId { get; set; }
public string? Token { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public string? Domain { get; set; }
public string? Workstation { get; set; }
}
public record ProfileInfo
{
public bool? Active { get; set; }
public byte? TypeId { get; set; }
public string? Mandantor { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public byte? LogLevelId { get; set; }
public short? LanguageId { get; set; }
}
public record ResultInfo
{
public long? ActionId { get; set; }
public short? StatusId { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
}
public record EndpointParamsInfo
{
public bool? Active { get; set; }
public string? Description { get; set; }
public short? GroupId { get; set; }
public byte? Sequence { get; set; }
public string? Key { get; set; }
public string? Value { get; set; }
}
public InsertActionProcedure Action { get; set; } = new();
public InsertEndpointProcedure Endpoint { get; set; } = new();
public InsertEndpointAuthProcedure EndpointAuth { get; set; } = new();
public InsertProfileProcedure Profile { get; set; } = new();
public InsertResultProcedure Result { get; set; } = new();
public InsertEndpointParamsProcedure EndpointParams { get; set; } = new();
}
public class InsertObjectProcedureHandler(IRepository repo) : IRequestHandler<InsertObjectProcedure, long>