From 854e36e71f6d0f0d002ae2d5099cefe4a2e1163b Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 14 Jan 2026 09:18:52 +0100 Subject: [PATCH] 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. --- .../Procedures/InsertObjectProcedure.cs | 184 ++++++++++++------ 1 file changed, 123 insertions(+), 61 deletions(-) diff --git a/src/ReC.Application/Common/Procedures/InsertObjectProcedure.cs b/src/ReC.Application/Common/Procedures/InsertObjectProcedure.cs index 79800ca..3b1c58b 100644 --- a/src/ReC.Application/Common/Procedures/InsertObjectProcedure.cs +++ b/src/ReC.Application/Common/Procedures/InsertObjectProcedure.cs @@ -6,88 +6,150 @@ using System.Text.Json; namespace ReC.Application.Common.Procedures; -public record InsertObjectProcedure : IRequest +public interface IInsertProcedure { - public string Entity { get; set; } = "ACTION"; - - 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 InsertObjectProcedure ToObjectProcedure(); +} - public record ActionInfo +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() { - 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; } + return new InsertObjectProcedure + { + Entity = "ACTION", + Action = this + }; } +} - public record EndpointInfo +public record InsertEndpointProcedure : IInsertProcedure +{ + public bool? Active { get; set; } + public string? Description { get; set; } + public string? Uri { get; set; } + + public InsertObjectProcedure ToObjectProcedure() { - public bool? Active { get; set; } - public string? Description { get; set; } - public string? Uri { get; set; } + return new InsertObjectProcedure + { + Entity = "ENDPOINT", + Endpoint = this + }; } +} - public record EndpointAuthInfo +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() { - 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; } + return new InsertObjectProcedure + { + Entity = "ENDPOINT_AUTH", + EndpointAuth = this + }; } +} - public record ProfileInfo +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() { - 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; } + 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 record ResultInfo + public InsertObjectProcedure ToObjectProcedure() { - public long? ActionId { get; set; } - public short? StatusId { get; set; } - public string? Header { get; set; } - public string? Body { get; set; } + return new InsertObjectProcedure + { + Entity = "RESULT", + Result = this + }; } +} - public record EndpointParamsInfo +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() { - 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; } + return new InsertObjectProcedure + { + Entity = "ENDPOINT_PARAMS", + EndpointParams = this + }; } } +public record InsertObjectProcedure : IRequest +{ + /// + /// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT + /// + public string Entity { get; set; } = null!; + + public string? AddedWho { 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 { public async Task Handle(InsertObjectProcedure request, CancellationToken cancel)