Compare commits
31 Commits
fb12cb6c98
...
35e03269e7
| Author | SHA1 | Date | |
|---|---|---|---|
| 35e03269e7 | |||
| 8b212d541e | |||
| dd4cecc15d | |||
| 0dedb506e1 | |||
| 24f146ca26 | |||
| 2692553865 | |||
| d90c2fab96 | |||
| 854e36e71f | |||
| 1d31f2aff9 | |||
| 11206cf84f | |||
| b48ebd8e88 | |||
| 12d17e0808 | |||
| 1dee3180d5 | |||
| bd4046a6c1 | |||
| af6f94c1ed | |||
| 7bfb56b664 | |||
| 1a6eced316 | |||
| c82749bcbf | |||
| e8fa149532 | |||
| aaa7beb92a | |||
| 5cce52ec27 | |||
| 3f36f048b2 | |||
| 92e8d9e778 | |||
| 2d04670fef | |||
| c0085b4c18 | |||
| 59ea5e3e67 | |||
| a9f2c4c2f7 | |||
| 001f4bf2c5 | |||
| bfe6c12ee0 | |||
| e1260e49f0 | |||
| 8b86eca838 |
@@ -66,7 +66,7 @@ public class ExceptionHandlingMiddleware
|
||||
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
details = new()
|
||||
{
|
||||
Title = "Bad Request",
|
||||
Title = "Bad Procedure",
|
||||
Detail = badRequestEx.Message
|
||||
};
|
||||
break;
|
||||
@@ -106,6 +106,23 @@ public class ExceptionHandlingMiddleware
|
||||
};
|
||||
break;
|
||||
|
||||
case InsertObjectFailedException insertFailedEx:
|
||||
logger.LogError(
|
||||
insertFailedEx,
|
||||
"Insert operation failed during request processing. {procedure}",
|
||||
JsonSerializer.Serialize(
|
||||
insertFailedEx.Procedure,
|
||||
options: new() { WriteIndented = true }
|
||||
));
|
||||
|
||||
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
details = new()
|
||||
{
|
||||
Title = "Insert Operation Failed",
|
||||
Detail = insertFailedEx.Message
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.LogError(exception, "Unhandled exception occurred.");
|
||||
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
@@ -120,4 +137,4 @@ public class ExceptionHandlingMiddleware
|
||||
if (details is not null)
|
||||
await context.Response.WriteAsJsonAsync(details);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
namespace ReC.Application.Common.Exceptions;
|
||||
|
||||
public class InsertObjectFailedException : Exception
|
||||
{
|
||||
public InsertObjectProcedure Procedure { get; }
|
||||
|
||||
public InsertObjectFailedException(InsertObjectProcedure procedure) : base()
|
||||
{
|
||||
Procedure = procedure;
|
||||
}
|
||||
|
||||
public InsertObjectFailedException(InsertObjectProcedure procedure, string? message) : base(message)
|
||||
{
|
||||
Procedure = procedure;
|
||||
}
|
||||
|
||||
public InsertObjectFailedException(InsertObjectProcedure procedure, string? message, Exception? innerException) : base(message, innerException)
|
||||
{
|
||||
Procedure = procedure;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReC.Domain.Entities;
|
||||
using ReC.Domain.QueryOutput;
|
||||
using ReC.Domain.Views;
|
||||
|
||||
namespace ReC.Application.Common.Interfaces;
|
||||
|
||||
public interface IRecDbContext
|
||||
{
|
||||
#region DbSets
|
||||
public DbSet<EndpointParam> EndpointParams { get; set; }
|
||||
|
||||
public DbSet<RecActionView> RecActionViews { get; set; }
|
||||
|
||||
public DbSet<ProfileView> ProfileViews { get; set; }
|
||||
|
||||
public DbSet<ResultView> RecResultViews { get; set; }
|
||||
|
||||
public DbSet<OutRes> OutRes { get; set; }
|
||||
|
||||
public DbSet<HeaderQueryResult> HeaderQueryResults { get; set; }
|
||||
@@ -26,5 +32,8 @@ public interface IRecDbContext
|
||||
|
||||
public DbSet<RecAction> RecActions { get; set; }
|
||||
|
||||
public DbSet<InsertObjectResult> RecResults { get; set; }
|
||||
#endregion DbSets
|
||||
|
||||
public Task<int> SaveChangesAsync(CancellationToken cancel = default);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
public interface IInsertProcedure
|
||||
{
|
||||
public InsertObjectProcedure ToObjectProcedure(string addedWho = "Rec.API");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
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(string addedWho = "Rec.API")
|
||||
{
|
||||
return new InsertObjectProcedure
|
||||
{
|
||||
Entity = "ACTION",
|
||||
Action = this
|
||||
}.AddedBy(addedWho);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
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(string addedWho = "Rec.API")
|
||||
{
|
||||
return new InsertObjectProcedure
|
||||
{
|
||||
Entity = "ENDPOINT_AUTH",
|
||||
EndpointAuth = this
|
||||
}.AddedBy(addedWho);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
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(string addedWho = "Rec.API")
|
||||
{
|
||||
return new InsertObjectProcedure
|
||||
{
|
||||
Entity = "ENDPOINT_PARAMS",
|
||||
EndpointParams = this
|
||||
}.AddedBy(addedWho);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
public record InsertEndpointProcedure : IInsertProcedure
|
||||
{
|
||||
public bool? Active { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Uri { get; set; }
|
||||
|
||||
public InsertObjectProcedure ToObjectProcedure(string addedWho = "Rec.API")
|
||||
{
|
||||
return new InsertObjectProcedure
|
||||
{
|
||||
Entity = "ENDPOINT",
|
||||
Endpoint = this
|
||||
}.AddedBy(addedWho);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using MediatR;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using ReC.Application.Common.Exceptions;
|
||||
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
public record InsertObjectProcedure : IRequest<long>
|
||||
{
|
||||
/// <summary>
|
||||
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
|
||||
/// </summary>
|
||||
public string Entity { get; set; } = null!;
|
||||
|
||||
internal string? AddedWho { get; private set; }
|
||||
|
||||
public InsertObjectProcedure AddedBy(string addedWho)
|
||||
{
|
||||
AddedWho = addedWho;
|
||||
return this;
|
||||
}
|
||||
|
||||
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 async Task<long> Handle(InsertObjectProcedure request, CancellationToken cancel)
|
||||
{
|
||||
var parameters = new[]
|
||||
{
|
||||
new SqlParameter("@pENTITY", request.Entity ?? (object)DBNull.Value),
|
||||
|
||||
new SqlParameter("@pADDED_WHO", (object?)request.AddedWho ?? DBNull.Value),
|
||||
new SqlParameter("@pADDED_WHEN", (object?)DateTime.UtcNow ?? DBNull.Value),
|
||||
|
||||
new SqlParameter("@pACTION_PROFILE_ID", (object?)request.Action.ProfileId ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_ACTIVE", (object?)request.Action.Active ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_SEQUENCE", (object?)request.Action.Sequence ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_ENDPOINT_ID", (object?)request.Action.EndpointId ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_ENDPOINT_AUTH_ID", (object?)request.Action.EndpointAuthId ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_ENDPOINT_PARAMS_ID", (object?)request.Action.EndpointParamsId ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_SQL_CONNECTION_ID", (object?)request.Action.SqlConnectionId ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_TYPE_ID", (object?)request.Action.TypeId ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_PRE_SQL", (object?)request.Action.PreSql ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_HEADER_SQL", (object?)request.Action.HeaderSql ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_BODY_SQL", (object?)request.Action.BodySql ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_POST_SQL", (object?)request.Action.PostSql ?? DBNull.Value),
|
||||
new SqlParameter("@pACTION_ERROR_ACTION_ID", (object?)request.Action.ErrorActionId ?? DBNull.Value),
|
||||
|
||||
new SqlParameter("@pENDPOINT_ACTIVE", (object?)request.Endpoint.Active ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_DESCRIPTION", (object?)request.Endpoint.Description ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_URI", (object?)request.Endpoint.Uri ?? DBNull.Value),
|
||||
|
||||
new SqlParameter("@pENDPOINT_AUTH_ACTIVE", (object?)request.EndpointAuth.Active ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_DESCRIPTION", (object?)request.EndpointAuth.Description ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_TYPE_ID", (object?)request.EndpointAuth.TypeId ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_API_KEY", (object?)request.EndpointAuth.ApiKey ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_API_VALUE", (object?)request.EndpointAuth.ApiValue ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_API_KEY_ADD_TO_ID", (object?)request.EndpointAuth.ApiKeyAddToId ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_TOKEN", (object?)request.EndpointAuth.Token ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_USERNAME", (object?)request.EndpointAuth.Username ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_PASSWORD", (object?)request.EndpointAuth.Password ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_DOMAIN", (object?)request.EndpointAuth.Domain ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_AUTH_WORKSTATION", (object?)request.EndpointAuth.Workstation ?? DBNull.Value),
|
||||
|
||||
new SqlParameter("@pPROFILE_ACTIVE", (object?)request.Profile.Active ?? DBNull.Value),
|
||||
new SqlParameter("@pPROFILE_TYPE_ID", (object?)request.Profile.TypeId ?? DBNull.Value),
|
||||
new SqlParameter("@pPROFILE_MANDANTOR", (object?)request.Profile.Mandantor ?? DBNull.Value),
|
||||
new SqlParameter("@pPROFILE_NAME", (object?)request.Profile.Name ?? DBNull.Value),
|
||||
new SqlParameter("@pPROFILE_DESCRIPTION", (object?)request.Profile.Description ?? DBNull.Value),
|
||||
new SqlParameter("@pPROFILE_LOG_LEVEL_ID", (object?)request.Profile.LogLevelId ?? DBNull.Value),
|
||||
new SqlParameter("@pPROFILE_LANGUAGE_ID", (object?)request.Profile.LanguageId ?? DBNull.Value),
|
||||
|
||||
new SqlParameter("@pRESULT_ACTION_ID", (object?)request.Result.ActionId ?? DBNull.Value),
|
||||
new SqlParameter("@pRESULT_STATUS_ID", (object?)request.Result.StatusId ?? DBNull.Value),
|
||||
new SqlParameter("@pRESULT_HEADER", (object?)request.Result.Header ?? DBNull.Value),
|
||||
new SqlParameter("@pRESULT_BODY", (object?)request.Result.Body ?? DBNull.Value),
|
||||
|
||||
new SqlParameter("@pENDPOINT_PARAMS_ACTIVE", (object?)request.EndpointParams.Active ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_PARAMS_DESCRIPTION", (object?)request.EndpointParams.Description ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_PARAMS_GROUP_ID", (object?)request.EndpointParams.GroupId ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_PARAMS_SEQUENCE", (object?)request.EndpointParams.Sequence ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_PARAMS_KEY", (object?)request.EndpointParams.Key ?? DBNull.Value),
|
||||
new SqlParameter("@pENDPOINT_PARAMS_VALUE", (object?)request.EndpointParams.Value ?? DBNull.Value),
|
||||
|
||||
new SqlParameter
|
||||
{
|
||||
ParameterName = "@oGUID",
|
||||
SqlDbType = System.Data.SqlDbType.BigInt,
|
||||
Direction = System.Data.ParameterDirection.Output
|
||||
}
|
||||
};
|
||||
|
||||
await repo.ExecuteQueryRawAsync(
|
||||
"EXEC [dbo].[PRREC_INSERT_OBJECT] " +
|
||||
"@pENTITY, @pADDED_WHO, @pADDED_WHEN, " +
|
||||
"@pACTION_PROFILE_ID, @pACTION_ACTIVE, @pACTION_SEQUENCE, @pACTION_ENDPOINT_ID, @pACTION_ENDPOINT_AUTH_ID, @pACTION_ENDPOINT_PARAMS_ID, @pACTION_SQL_CONNECTION_ID, @pACTION_TYPE_ID, @pACTION_PRE_SQL, @pACTION_HEADER_SQL, @pACTION_BODY_SQL, @pACTION_POST_SQL, @pACTION_ERROR_ACTION_ID, " +
|
||||
"@pENDPOINT_ACTIVE, @pENDPOINT_DESCRIPTION, @pENDPOINT_URI, " +
|
||||
"@pENDPOINT_AUTH_ACTIVE, @pENDPOINT_AUTH_DESCRIPTION, @pENDPOINT_AUTH_TYPE_ID, @pENDPOINT_AUTH_API_KEY, @pENDPOINT_AUTH_API_VALUE, @pENDPOINT_AUTH_API_KEY_ADD_TO_ID, @pENDPOINT_AUTH_TOKEN, @pENDPOINT_AUTH_USERNAME, @pENDPOINT_AUTH_PASSWORD, @pENDPOINT_AUTH_DOMAIN, @pENDPOINT_AUTH_WORKSTATION, " +
|
||||
"@pPROFILE_ACTIVE, @pPROFILE_TYPE_ID, @pPROFILE_MANDANTOR, @pPROFILE_NAME, @pPROFILE_DESCRIPTION, @pPROFILE_LOG_LEVEL_ID, @pPROFILE_LANGUAGE_ID, " +
|
||||
"@pRESULT_ACTION_ID, @pRESULT_STATUS_ID, @pRESULT_HEADER, @pRESULT_BODY, " +
|
||||
"@pENDPOINT_PARAMS_ACTIVE, @pENDPOINT_PARAMS_DESCRIPTION, @pENDPOINT_PARAMS_GROUP_ID, @pENDPOINT_PARAMS_SEQUENCE, @pENDPOINT_PARAMS_KEY, @pENDPOINT_PARAMS_VALUE, " +
|
||||
"@oGUID OUTPUT",
|
||||
parameters,
|
||||
cancel);
|
||||
|
||||
var guidParam = parameters.Last();
|
||||
|
||||
if (guidParam.Value != DBNull.Value)
|
||||
if (guidParam.Value is long longValue)
|
||||
return longValue;
|
||||
else if (long.TryParse(guidParam.Value.ToString(), out var guid))
|
||||
return guid;
|
||||
|
||||
throw new InsertObjectFailedException(request, "InsertObject stored procedure did not return a valid identifier.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
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(string addedWho = "Rec.API")
|
||||
{
|
||||
return new InsertObjectProcedure
|
||||
{
|
||||
Entity = "PROFILE",
|
||||
Profile = this
|
||||
}.AddedBy(addedWho);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace ReC.Application.Common.Procedures.InsertProcedure;
|
||||
|
||||
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(string addedWho = "Rec.API")
|
||||
{
|
||||
return new InsertObjectProcedure
|
||||
{
|
||||
Entity = "RESULT",
|
||||
Result = this
|
||||
}.AddedBy(addedWho);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
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.ActionProfileId)
|
||||
.NotNull()
|
||||
.WithMessage("ACTION requires ActionProfileId (maps to @pACTION_PROFILE_ID).");
|
||||
|
||||
RuleFor(x => x.ActionEndpointId)
|
||||
.NotNull()
|
||||
.WithMessage("ACTION requires ActionEndpointId (maps to @pACTION_ENDPOINT_ID).");
|
||||
});
|
||||
|
||||
// ENDPOINT validation
|
||||
When(x => x.Entity == "ENDPOINT", () =>
|
||||
{
|
||||
RuleFor(x => x.EndpointUri)
|
||||
.NotEmpty()
|
||||
.WithMessage("ENDPOINT requires EndpointUri (maps to @pENDPOINT_URI).")
|
||||
.MaximumLength(2000);
|
||||
});
|
||||
|
||||
// PROFILE validation
|
||||
When(x => x.Entity == "PROFILE", () =>
|
||||
{
|
||||
RuleFor(x => x.ProfileName)
|
||||
.NotEmpty()
|
||||
.WithMessage("PROFILE requires ProfileName (maps to @pPROFILE_NAME).")
|
||||
.MaximumLength(50);
|
||||
|
||||
RuleFor(x => x.ProfileMandantor)
|
||||
.MaximumLength(50)
|
||||
.When(x => x.ProfileMandantor != null);
|
||||
|
||||
RuleFor(x => x.ProfileDescription)
|
||||
.MaximumLength(250)
|
||||
.When(x => x.ProfileDescription != null);
|
||||
});
|
||||
|
||||
// RESULT validation
|
||||
When(x => x.Entity == "RESULT", () =>
|
||||
{
|
||||
RuleFor(x => x.ResultActionId)
|
||||
.NotNull()
|
||||
.WithMessage("RESULT requires ResultActionId (maps to @pRESULT_ACTION_ID).");
|
||||
|
||||
RuleFor(x => x.ResultStatusId)
|
||||
.NotNull()
|
||||
.WithMessage("RESULT requires ResultStatusId (maps to @pRESULT_STATUS_ID).");
|
||||
});
|
||||
|
||||
// ENDPOINT_PARAMS validation
|
||||
When(x => x.Entity == "ENDPOINT_PARAMS", () =>
|
||||
{
|
||||
RuleFor(x => x.EndpointParamsGroupId)
|
||||
.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.EndpointDescription)
|
||||
.MaximumLength(250)
|
||||
.When(x => x.EndpointDescription != null);
|
||||
|
||||
RuleFor(x => x.EndpointAuthDescription)
|
||||
.MaximumLength(250)
|
||||
.When(x => x.EndpointAuthDescription != null);
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,11 @@ public class ReadRecActionViewQueryHandler(IRepository<RecActionView> repo, IMap
|
||||
query = repo.Where(act => act.ProfileId == profileId);
|
||||
|
||||
if (request.Invoked is bool invoked)
|
||||
query = invoked ? query.Where(act => act.Root!.OutRes != null) : query.Where(act => act.Root!.OutRes == null);
|
||||
query = invoked
|
||||
? query.Where(act => act.Results!.Any())
|
||||
: query.Where(act => !act.Results!.Any());
|
||||
|
||||
var actions = await query.Include(act => act.EndpointAuth).ToListAsync(cancel);
|
||||
var actions = await query.ToListAsync(cancel);
|
||||
|
||||
if (actions.Count == 0)
|
||||
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace ReC.Domain.Entities;
|
||||
namespace ReC.Domain.QueryOutput;
|
||||
|
||||
public class BodyQueryResult
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace ReC.Domain.Entities;
|
||||
namespace ReC.Domain.QueryOutput;
|
||||
|
||||
public class HeaderQueryResult
|
||||
{
|
||||
8
src/ReC.Domain/QueryOutput/InsertObjectResult.cs
Normal file
8
src/ReC.Domain/QueryOutput/InsertObjectResult.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ReC.Domain.QueryOutput;
|
||||
|
||||
public class InsertObjectResult
|
||||
{
|
||||
public required long NewObjectId { get; set; }
|
||||
}
|
||||
@@ -6,6 +6,8 @@ namespace ReC.Domain.Views;
|
||||
[Table("VWREC_PROFILE", Schema = "dbo")]
|
||||
public record ProfileView
|
||||
{
|
||||
public virtual IEnumerable<RecActionView>? Actions { get; init; }
|
||||
|
||||
public long Id { get; init; }
|
||||
|
||||
public bool Active { get; init; }
|
||||
|
||||
@@ -15,9 +15,12 @@ namespace ReC.Domain.Views;
|
||||
[Table("VWREC_ACTION", Schema = "dbo")]
|
||||
public class RecActionView
|
||||
{
|
||||
public virtual IEnumerable<ResultView>? Results { get; set; }
|
||||
|
||||
public required long Id { get; set; }
|
||||
|
||||
[ForeignKey("Id")]
|
||||
[Obsolete("Use the related procedure or view.")]
|
||||
public RecAction? Root { get; set; }
|
||||
|
||||
public long? ProfileId { get; set; }
|
||||
@@ -34,6 +37,7 @@ public class RecActionView
|
||||
public long? EndpointId { get; set; }
|
||||
|
||||
[ForeignKey("EndpointId")]
|
||||
[Obsolete("Use the related procedure or view.")]
|
||||
public Endpoint? Endpoint { get; set; }
|
||||
|
||||
public string? EndpointUri { get; set; }
|
||||
@@ -41,6 +45,7 @@ public class RecActionView
|
||||
public long? EndpointAuthId { get; set; }
|
||||
|
||||
[ForeignKey("EndpointAuthId")]
|
||||
[Obsolete("Use the related procedure or view.")]
|
||||
public EndpointAuth? EndpointAuth { get; set; }
|
||||
|
||||
public EndpointAuthType? EndpointAuthType { get; set; }
|
||||
@@ -70,6 +75,7 @@ public class RecActionView
|
||||
public short? SqlConnectionId { get; set; }
|
||||
|
||||
[ForeignKey("SqlConnectionId")]
|
||||
[Obsolete("Use the related procedure or view.")]
|
||||
public Connection? SqlConnection { get; set; }
|
||||
|
||||
public string? SqlConnectionServer { get; set; }
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReC.Application.Common.Interfaces;
|
||||
using ReC.Domain.Entities;
|
||||
using ReC.Domain.QueryOutput;
|
||||
using ReC.Domain.Views;
|
||||
|
||||
namespace ReC.Infrastructure;
|
||||
|
||||
public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(options), IRecDbContext
|
||||
{
|
||||
#region DB Sets
|
||||
public DbSet<EndpointParam> EndpointParams { get; set; }
|
||||
|
||||
public DbSet<RecActionView> RecActionViews { get; set; }
|
||||
@@ -31,6 +33,10 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
||||
|
||||
public DbSet<RecAction> RecActions { get; set; }
|
||||
|
||||
public DbSet<InsertObjectResult> RecResults { get; set; }
|
||||
#endregion DB Sets
|
||||
|
||||
// TODO: Update to configure via appsettings.json
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
@@ -191,6 +197,10 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
||||
b.Property(e => e.FirstRun).HasColumnName("FIRST_RUN");
|
||||
b.Property(e => e.LastRun).HasColumnName("LAST_RUN");
|
||||
b.Property(e => e.LastResult).HasColumnName("LAST_RESULT");
|
||||
|
||||
b.HasMany(e => e.Actions)
|
||||
.WithOne(a => a.Profile)
|
||||
.HasForeignKey(a => a.ProfileId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<RecAction>(b =>
|
||||
@@ -262,6 +272,10 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
||||
b.Property(e => e.PostprocessingQuery).HasColumnName("POSTPROCESSING_QUERY");
|
||||
b.Property(e => e.ErrorAction).HasColumnName("ERROR_ACTION_ID");
|
||||
b.Property(e => e.ErrorActionName).HasColumnName("ERROR_ACTION");
|
||||
|
||||
b.HasMany(e => e.Results)
|
||||
.WithOne(r => r.Action)
|
||||
.HasForeignKey(r => r.ActionId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ResultView>(b =>
|
||||
@@ -281,6 +295,14 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
||||
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
|
||||
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
|
||||
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
|
||||
|
||||
b.HasOne(r => r.Action)
|
||||
.WithMany(a => a.Results)
|
||||
.HasForeignKey(r => r.ActionId);
|
||||
|
||||
b.HasOne(r => r.Profile)
|
||||
.WithMany()
|
||||
.HasForeignKey(r => r.ProfileId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<HeaderQueryResult>(b =>
|
||||
@@ -295,5 +317,10 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
||||
b.Property(e => e.RawBody).HasColumnName("REQUEST_BODY");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<InsertObjectResult>(b =>
|
||||
{
|
||||
b.HasNoKey();
|
||||
b.Property(e => e.NewObjectId).HasColumnName("oGUID");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user