Add EntityType enum and support in StoredProcedureBuilder
Introduced the EntityType enum to represent target entities for stored procedure operations, along with XML documentation and mapping comments. Added EntityTypeExtensions with a ToDbString method for consistent DB string conversion. Updated StoredProcedureBuilder to support adding EntityType parameters, improving type safety and maintainability. Minor formatting and using directive adjustments included.
This commit is contained in:
51
src/ReC.Application/Common/Procedures/EntityType.cs
Normal file
51
src/ReC.Application/Common/Procedures/EntityType.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace ReC.Application.Common.Procedures;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the target entity type for stored procedure operations (Insert, Update, Delete).
|
||||
/// </summary>
|
||||
public enum EntityType
|
||||
{
|
||||
/// <summary>
|
||||
/// A scheduled or configured action within a profile that invokes an endpoint (maps to TBREC_CFG_ACTION).
|
||||
/// </summary>
|
||||
Action,
|
||||
|
||||
/// <summary>
|
||||
/// A REST endpoint URI configuration (maps to TBREC_CFG_ENDPOINT).
|
||||
/// </summary>
|
||||
Endpoint,
|
||||
|
||||
/// <summary>
|
||||
/// Authentication credentials for an endpoint such as API key, Bearer token, or NTLM (maps to TBREC_CFG_ENDPOINT_AUTH).
|
||||
/// </summary>
|
||||
EndpointAuth,
|
||||
|
||||
/// <summary>
|
||||
/// Key-value parameters attached to an endpoint (maps to TBREC_CFG_ENDPOINT_PARAMS).
|
||||
/// </summary>
|
||||
EndpointParams,
|
||||
|
||||
/// <summary>
|
||||
/// A profile that groups one or more actions and defines execution settings (maps to TBREC_CFG_PROFILE).
|
||||
/// </summary>
|
||||
Profile,
|
||||
|
||||
/// <summary>
|
||||
/// The outcome of an action invocation including HTTP status, headers, body, and error details (maps to TBREC_OUT_RESULT).
|
||||
/// </summary>
|
||||
Result
|
||||
}
|
||||
|
||||
public static class EntityTypeExtensions
|
||||
{
|
||||
public static string ToDbString(this EntityType entityType) => entityType switch
|
||||
{
|
||||
EntityType.Action => "ACTION",
|
||||
EntityType.Endpoint => "ENDPOINT",
|
||||
EntityType.EndpointAuth => "ENDPOINT_AUTH",
|
||||
EntityType.EndpointParams => "ENDPOINT_PARAMS",
|
||||
EntityType.Profile => "PROFILE",
|
||||
EntityType.Result => "RESULT",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(entityType), $"Not expected entity type value: {entityType}")
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
|
||||
@@ -30,6 +31,22 @@ internal sealed class StoredProcedureBuilder(string procedureName, string? retur
|
||||
return this;
|
||||
}
|
||||
|
||||
public StoredProcedureBuilder Add(string name, EntityType entityType)
|
||||
{
|
||||
var entityTypeStr = entityType switch
|
||||
{
|
||||
EntityType.Action => "ACTION",
|
||||
EntityType.Endpoint => "ENDPOINT",
|
||||
EntityType.EndpointAuth => "ENDPOINT_AUTH",
|
||||
EntityType.EndpointParams => "ENDPOINT_PARAMS",
|
||||
EntityType.Profile => "PROFILE",
|
||||
EntityType.Result => "RESULT",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(entityType), $"Not expected entity type value: {entityType}")
|
||||
};
|
||||
|
||||
return Add(name, entityTypeStr);
|
||||
}
|
||||
|
||||
public StoredProcedureBuilder AddOutput(string name, SqlDbType dbType)
|
||||
{
|
||||
_execSql.AppendLine($"{_separator}@{name} = @{name} OUTPUT");
|
||||
|
||||
Reference in New Issue
Block a user