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,21 +6,13 @@ using System.Text.Json;
namespace ReC.Application.Common.Procedures; namespace ReC.Application.Common.Procedures;
public record InsertObjectProcedure : IRequest<long> public interface IInsertProcedure
{ {
public string Entity { get; set; } = "ACTION"; public InsertObjectProcedure ToObjectProcedure();
}
public string? AddedWho { get; set; } public record InsertActionProcedure : IInsertProcedure
{
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 long? ProfileId { get; set; }
public bool? Active { get; set; } public bool? Active { get; set; }
public byte? Sequence { get; set; } public byte? Sequence { get; set; }
@@ -34,17 +26,35 @@ public record InsertObjectProcedure : IRequest<long>
public string? BodySql { get; set; } public string? BodySql { get; set; }
public string? PostSql { get; set; } public string? PostSql { get; set; }
public byte? ErrorActionId { get; set; } public byte? ErrorActionId { get; set; }
}
public record EndpointInfo public InsertObjectProcedure ToObjectProcedure()
{ {
return new InsertObjectProcedure
{
Entity = "ACTION",
Action = this
};
}
}
public record InsertEndpointProcedure : IInsertProcedure
{
public bool? Active { get; set; } public bool? Active { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public string? Uri { get; set; } public string? Uri { get; set; }
}
public record EndpointAuthInfo public InsertObjectProcedure ToObjectProcedure()
{ {
return new InsertObjectProcedure
{
Entity = "ENDPOINT",
Endpoint = this
};
}
}
public record InsertEndpointAuthProcedure : IInsertProcedure
{
public bool? Active { get; set; } public bool? Active { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public byte? TypeId { get; set; } public byte? TypeId { get; set; }
@@ -56,10 +66,19 @@ public record InsertObjectProcedure : IRequest<long>
public string? Password { get; set; } public string? Password { get; set; }
public string? Domain { get; set; } public string? Domain { get; set; }
public string? Workstation { get; set; } public string? Workstation { get; set; }
}
public record ProfileInfo public InsertObjectProcedure ToObjectProcedure()
{ {
return new InsertObjectProcedure
{
Entity = "ENDPOINT_AUTH",
EndpointAuth = this
};
}
}
public record InsertProfileProcedure : IInsertProcedure
{
public bool? Active { get; set; } public bool? Active { get; set; }
public byte? TypeId { get; set; } public byte? TypeId { get; set; }
public string? Mandantor { get; set; } public string? Mandantor { get; set; }
@@ -67,27 +86,70 @@ public record InsertObjectProcedure : IRequest<long>
public string? Description { get; set; } public string? Description { get; set; }
public byte? LogLevelId { get; set; } public byte? LogLevelId { get; set; }
public short? LanguageId { get; set; } public short? LanguageId { get; set; }
}
public record ResultInfo public InsertObjectProcedure ToObjectProcedure()
{ {
return new InsertObjectProcedure
{
Entity = "PROFILE",
Profile = this
};
}
}
public record InsertResultProcedure : IInsertProcedure
{
public long? ActionId { get; set; } public long? ActionId { get; set; }
public short? StatusId { get; set; } public short? StatusId { get; set; }
public string? Header { get; set; } public string? Header { get; set; }
public string? Body { get; set; } public string? Body { get; set; }
}
public record EndpointParamsInfo public InsertObjectProcedure ToObjectProcedure()
{ {
return new InsertObjectProcedure
{
Entity = "RESULT",
Result = this
};
}
}
public record InsertEndpointParamsProcedure : IInsertProcedure
{
public bool? Active { get; set; } public bool? Active { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public short? GroupId { get; set; } public short? GroupId { get; set; }
public byte? Sequence { get; set; } public byte? Sequence { get; set; }
public string? Key { get; set; } public string? Key { get; set; }
public string? Value { get; set; } public string? Value { get; set; }
public InsertObjectProcedure ToObjectProcedure()
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
EndpointParams = this
};
} }
} }
public record InsertObjectProcedure : IRequest<long>
{
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// </summary>
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<InsertObjectProcedure, long> public class InsertObjectProcedureHandler(IRepository repo) : IRequestHandler<InsertObjectProcedure, long>
{ {
public async Task<long> Handle(InsertObjectProcedure request, CancellationToken cancel) public async Task<long> Handle(InsertObjectProcedure request, CancellationToken cancel)