Compare commits

...

152 Commits

Author SHA1 Message Date
27d731a5b0 Bump version to 2.0.0-beta in ReC.API.csproj
Updated <Version>, <AssemblyVersion>, <FileVersion>, and <InformationalVersion> fields from 1.0.3-beta to 2.0.0-beta to reflect a major version change, indicating significant updates or breaking changes in the project.
2026-01-22 10:41:26 +01:00
b8f797f14d Make EndpointAuthType non-nullable with default NoAuth
Changed EndpointAuthType in RecActionViewDto from nullable to non-nullable and set its default value to EndpointAuthType.NoAuth to ensure it always has a valid value.
2026-01-22 10:37:37 +01:00
6feef53733 Update namespaces and usings for Insert procedures
Refactored InsertActionProcedure to the RecActions.Commands namespace and updated its usings to import InsertObjectProcedure. Added missing using for RecActions.Commands in InsertObjectProcedure.cs. These changes improve code organization and clarify command responsibilities.
2026-01-22 10:17:08 +01:00
878e096c57 Refactor TypeId to use RestType enum in InsertActionProcedure
Changed TypeId from byte? to RestType? in InsertActionProcedure for stronger typing. Updated InsertObjectProcedureHandler to cast RestType to byte? when creating SQL parameters. Added using directive for ReC.Domain.Constants to support the new enum type.
2026-01-22 09:55:35 +01:00
2ded140ad5 Rename SqlExceptionNumber to BadRequestSqlExceptionNumber
Clarify intent by renaming SqlExceptionNumber to BadRequestSqlExceptionNumber in both configuration and code. This makes it explicit that these SQL exception numbers are mapped to HTTP 400 Bad Request errors. All relevant usages and settings have been updated accordingly.
2026-01-22 09:33:54 +01:00
e2ca249d13 Add SQL exception 50000 to handled exception numbers
Updated appsettings.json to include 50000 in the SqlExceptionNumber array, allowing the application to recognize and handle SQL exceptions with this number in addition to existing ones. This change can be applied at runtime without requiring a restart.
2026-01-22 09:31:41 +01:00
e782eab62a Refactor handlers to use IOptionsMonitor for SQL options
Refactored Delete, Insert, and Update procedure handlers to inject IOptionsMonitor<SqlExceptionOptions> instead of SqlExceptionOptions, enabling dynamic configuration updates. Updated all references to use CurrentValue. Added necessary using directives and cleaned up redundant usings in InsertObjectProcedure.cs.
2026-01-22 09:21:39 +01:00
d8e08b237d Simplify SqlException config structure in appsettings.json
Removed the "ErrorMessages" wrapper from the SqlException section,
placing "SqlExceptionNumber" directly under "SqlException".
No changes to the exception numbers themselves. Improved
readability and clarity of the configuration.
2026-01-22 02:04:52 +01:00
Developer 02
88cb1dc16a Handle SqlException in UpdateObjectProcedureHandler
Wrap stored procedure execution in try-catch to handle SqlException.
Throw BadRequestException for configured SQL error numbers.
Update constructor to accept SqlExceptionOptions.
Add necessary using directives for new exception handling.
2026-01-22 01:54:07 +01:00
Developer 02
8d6a09213e Simplify BadRequestException error message on insert failure
Replaced the detailed error message for insert failures with only the original exception message from SqlException, removing extra guidance about referenced entities.
2026-01-22 01:53:55 +01:00
Developer 02
54f412ced2 Improve error handling in DeleteObjectProcedureHandler
Refactored DeleteObjectProcedureHandler to inject SqlExceptionOptions and wrap stored procedure execution in a try-catch block. Added logic to throw custom exceptions (DeleteObjectFailedException, BadRequestException) based on result codes and SQL exception numbers, enhancing robustness and configurability of error handling.
2026-01-22 01:53:40 +01:00
Developer 02
51b9c62188 Add SqlException config options and update dependencies
Added ConfigureSqlException methods to DependencyInjection for flexible SQL exception handling configuration. Updated RecApplicationTestBase to use new options. Bumped DigitalData.Core.Exceptions to v1.1.1.
2026-01-22 01:49:59 +01:00
Developer 02
bb5525778d Improve error handling in InsertObjectProcedureHandler
Wrap SQL execution in try-catch and inject SqlExceptionOptions.
Throw BadRequestException with a clear message when insert fails due to missing referenced entities, based on SqlException number. Other SQL exceptions are rethrown. This provides better feedback for foreign key/reference errors.
2026-01-22 01:49:13 +01:00
Developer 02
ee793632df Add SQL exception handling configuration support
Updated Program.cs to configure SQL exception handling using the new "SqlException" section in appsettings.json. Renamed "SqlExceptionTranslator" to "SqlException" and added error message mappings for specific SQL exception numbers to enable custom exception translation.
2026-01-22 01:46:46 +01:00
Developer 02
22bb585f60 Refactor SQL exception handling and config structure
Simplify SQL exception tracking by replacing error message mappings
with a list of relevant error numbers in appsettings.json. Remove
custom error message logic and related classes, introducing
SqlExceptionOptions to hold tracked error codes.
2026-01-22 01:45:50 +01:00
Developer 02
ed7237c8dd Add SqlExceptionTranslator config and options class
Introduce SqlExceptionTranslator section in appsettings.json to map common SQL error codes to user-friendly messages. Add SqlExceptionTranslatorOptions class to manage error code/message mapping and support configuration binding.
2026-01-22 01:13:02 +01:00
Developer 02
f71bcf37e9 Add SqlExceptionTranslator for custom SQL error handling
Introduced SqlExceptionTranslator and ISqlExceptionTranslator to translate SQL exceptions into user-friendly error messages for bad request scenarios. Uses configurable options to identify relevant error numbers and format messages with templates.
2026-01-22 00:34:35 +01:00
Developer 02
c7e366af60 Refactor ResultController ctor, enhance BadRequest logging
Removed IConfiguration from ResultController constructor, now only using IMediator. Added logging for BadRequestException inner exceptions in ExceptionHandlingMiddleware for improved error diagnostics.
2026-01-21 22:24:41 +01:00
86f4e3141e Remove all 'fake' profile endpoints from controllers
Removed API endpoints for invoking, retrieving, and deleting RecActions and Results associated with fake/test profiles in RecActionController and ResultController. Only standard CRUD operations for real profiles are now exposed.
2026-01-21 12:06:19 +01:00
869ba9858f Update ProfileController to use CreatedAtAction in Post
Changed the Post method to return CreatedAtAction, providing a Location header linking to the new profile resource, in line with RESTful best practices.
2026-01-20 16:38:53 +01:00
5dee104377 Handle SQL exceptions in InsertActionProcedure test
Wrap InsertActionProcedure_runs_via_mediator in a try-catch block to handle SQL exceptions for duplicate key and foreign key violations, marking the test as passed with explanatory messages. Also, add EndpointId to the test data and improve assertion clarity. This increases test robustness against common DB constraint issues in integration testing.
2026-01-20 16:22:30 +01:00
36e1d5fad1 Update test assertions to allow any non-default int result
Previously, tests asserted that procedure results were exactly 0.
Now, assertions require only that results are not the default int
value, making the tests more flexible to non-zero outcomes.
2026-01-20 16:10:40 +01:00
304490d661 Add explicit @RC handling in SQL for delete/update procs
Updated DeleteObjectProcedureHandler and UpdateObjectProcedureHandler to declare, initialize, and select the @RC variable in their SQL command strings. This ensures the stored procedure return code is explicitly captured and returned by the query.
2026-01-20 15:39:54 +01:00
ff4ab9efe2 Handle NotFoundException gracefully in query tests
Updated ProfileQueryTests, RecActionQueryTests, and ResultQueryTests to catch NotFoundException and pass tests with an explanatory message when test data is missing or entities are not found. This improves test robustness and reduces false negatives due to unavailable test data. Also renamed a test in ResultQueryTests to reflect the new behavior.
2026-01-19 10:16:53 +01:00
470120e5e9 Add ProfileView entity mapping to RecDbContext
Mapped ProfileView to the VWREC_PROFILE view in the dbo schema.
Configured primary key and property-to-column mappings for all
relevant fields, enabling read access to profile data via EF Core.
2026-01-19 10:03:17 +01:00
ce35ef588f Add integration test project with MediatR procedure tests
Added ReC.Tests project with integration tests for stored procedure commands and queries via MediatR, covering endpoints, actions, results, and profiles. Introduced a test base for DI/configuration, helper for private property access, and updated the solution to include the new test suite. Tests use NUnit and cover both positive and negative scenarios.
2026-01-16 15:24:51 +01:00
df665e3b98 Remove ReC.Abstractions.Application from solution
Deleted the "ReC.Abstractions.Application" project from ReC.sln, including its project entry, build configurations, and nested project references.
2026-01-16 14:40:12 +01:00
4bc6df4d91 Revert "Refactor BaseCrudApi to use generic type parameters"
This reverts commit 5197ad1481.
2026-01-16 14:39:12 +01:00
383932e7e7 Remove [Table] attributes from DTO classes
Removed explicit table mapping attributes from EndpointAuthDto, ProfileDto, and RecActionDto to decouple DTOs from database schema definitions.
2026-01-16 13:17:44 +01:00
e3494d50b7 Add ReC.Abstractions.Application project to solution
Added new ReC.Abstractions.Application project targeting .NET 8.0, with implicit usings and nullable enabled. Updated solution file to include the project under the "core" folder and configured build settings for Debug and Release.
2026-01-16 13:06:37 +01:00
5197ad1481 Refactor BaseCrudApi to use generic type parameters
BaseCrudApi is now defined as BaseCrudApi<TCreate, TUpdate, TDelete>,
with each CRUD method using its respective type parameter. This
improves type safety and clarity for API payloads. Method signatures
and XML documentation have been updated accordingly.
2026-01-16 12:29:17 +01:00
dbfb7e7e47 Refactor API classes to use BaseCrudApi for CRUD ops
Introduce BaseCrudApi to encapsulate common CRUD logic for API resource classes. Refactor CommonApi, EndpointAuthApi, EndpointParamsApi, EndpointsApi, ProfileApi, RecActionApi, and ResultApi to inherit from BaseCrudApi, removing duplicated CRUD methods and constructors. This centralizes CRUD operations, reduces code duplication, and improves maintainability.
2026-01-16 11:53:14 +01:00
b9a40bb12e Refactor API method names for consistency and clarity
Renamed public API methods across ReC.Client.Api classes to use concise and uniform names (e.g., CreateAsync, UpdateAsync, DeleteAsync, GetAsync, InvokeAsync). Removed obsolete NETFRAMEWORK preprocessor blocks. Updated summary comment for Results property in ReCClient.cs. These changes improve naming consistency and code clarity throughout the client library.
2026-01-16 11:42:03 +01:00
8ddaf1d13e Update ResultApi to use "api/Result" endpoint paths
Replaced all occurrences of "api/OutRes" with "api/Result" in ResultApi.cs for GET, POST, PUT, and DELETE operations. This ensures all result-related API requests now target the correct "Result" endpoint.
2026-01-16 11:37:38 +01:00
14532a15bf Add NETFRAMEWORK-specific usings to API files
Added conditional using directives for System.Net.Http, System.Threading, and System.Threading.Tasks in multiple API files. These usings are now included only when targeting .NET Framework, improving compatibility and preventing unnecessary imports on other platforms.
2026-01-16 11:35:37 +01:00
0149a77f21 Add ReCClientHelpers for query and JSON request helpers
Introduced internal static class ReCClientHelpers with methods to build query strings from key/value pairs and to create JsonContent payloads for HTTP requests. Includes conditional compilation for .NET Framework compatibility and XML documentation for both methods. Added necessary using directives.
2026-01-16 11:34:19 +01:00
a17d260c6c Refactor ReCClient to use modular API group classes
Refactored ReCClient to expose grouped endpoint APIs as properties (e.g., RecActions, Results, Profiles, etc.), each handled by its own class. Removed direct endpoint methods from ReCClient and delegated them to these new API classes. Cleaned up using directives and improved code modularity for better maintainability and discoverability.
2026-01-16 11:34:06 +01:00
b639df0a39 Add ResultApi for HTTP access to output result endpoints
Introduced the ResultApi class in the ReC.Client.Api namespace to provide asynchronous methods for retrieving, creating, updating, and deleting output results via HTTP. The class uses an injected HttpClient, supports cancellation tokens, and leverages helper methods for query construction and JSON serialization.
2026-01-16 11:33:51 +01:00
0fddf5669f Add RecActionApi client for RecAction endpoint operations
Introduced RecActionApi in ReC.Client.Api to provide a typed API client for RecAction endpoints. Includes methods for invoking, retrieving, creating, updating, and deleting Rec actions, with support for cancellation tokens and helper-based serialization. All methods are documented with XML comments.
2026-01-16 11:33:36 +01:00
9c46b9f2da Add ProfileApi for profile CRUD operations via HttpClient
Introduced ProfileApi class in ReC.Client.Api to handle profile-related API endpoints. Supports retrieving, creating, updating, and deleting profiles using an injected HttpClient. Methods accept cancellation tokens and utilize helper methods for query building and JSON serialization. Includes XML documentation for all methods and parameters.
2026-01-16 11:32:44 +01:00
87d9769d9b Add EndpointsApi for CRUD operations on endpoints
Introduced EndpointsApi class in ReC.Client.Api to handle create, update, and delete operations for endpoint definitions via HTTP requests. Methods are generic, support cancellation tokens, and use a helper for JSON serialization of payloads.
2026-01-16 11:32:31 +01:00
19ecf104fa Add EndpointParamsApi for endpoint parameter operations
Introduced the EndpointParamsApi class in ReC.Client.Api to handle create, update, and delete operations for endpoint parameters via HTTP. Methods support generic payloads, cancellation tokens, and use JSON serialization helpers. Added necessary using directives for HTTP and threading.
2026-01-16 11:30:46 +01:00
5b5b034e78 Add EndpointAuthApi for endpoint authentication operations
Introduced the EndpointAuthApi class in ReC.Client.Api to handle endpoint authentication API interactions. This class provides async methods for creating, updating, and deleting endpoint authentication configurations using HttpClient, with support for cancellation tokens and JSON payload serialization. XML documentation is included for clarity.
2026-01-16 11:30:30 +01:00
5ebb3f72e3 Add CommonApi for generic HTTP object operations
Introduced the CommonApi class in the ReC.Client.Api namespace to provide generic methods for creating, updating, and deleting objects via HTTP. The class uses an injected HttpClient and supports asynchronous operations with optional cancellation tokens. All methods serialize payloads to JSON using ReCClientHelpers.ToJsonContent. XML documentation was added for clarity.
2026-01-16 11:29:54 +01:00
3cfecbf598 Rename OutResController to ResultController and update docs
Renamed the controller class to ResultController for clarity and added the ReC.Application.Results.Queries using directive. Updated class documentation and parameter descriptions to better reflect the controller's purpose.
2026-01-16 11:17:41 +01:00
4895b9c8f8 Refactor: move OutResults to Results namespace
Refactored all "Result" related command and query classes from ReC.Application.OutResults to ReC.Application.Results. Updated all relevant using statements and reorganized files accordingly. No functional changes; this improves project structure and clarity.
2026-01-16 11:13:06 +01:00
36fe78e152 Remove obsolete CreateResultViewCommand and handler
Deleted the CreateResultViewCommand.cs file, including the obsolete CreateResultViewCommand and CreateResultViewCommandHandler classes. These were previously used for creating ResultView entities, but are now replaced by related procedures or views. All associated code and using directives have been removed.
2026-01-16 11:09:02 +01:00
489180f5a1 Restructure solution folders in ReC.sln
Added "infrastructure", "presentation", and "core" solution folders. Moved projects into these new folders and updated the NestedProjects section to reflect the new organization. Adjusted parent GUIDs accordingly.
2026-01-16 11:07:19 +01:00
b65810bbbb Add XML docs to ResultType enum members
Added summary XML documentation to each member of the ResultType enum in the ReC.Client namespace, clarifying the purpose of Full, OnlyHeader, and OnlyBody options.
2026-01-16 11:05:17 +01:00
278fcfd75b Remove obsolete sync API methods from ReCClient
All synchronous (blocking) HTTP API methods have been removed from the ReCClient class, leaving only their asynchronous counterparts. These sync methods were previously marked as [Obsolete] and simply wrapped the async methods with .GetAwaiter().GetResult(). Additionally, the ToJsonContent method's return type was updated from HttpContent to JsonContent for improved type specificity.
2026-01-16 11:04:11 +01:00
41db75b183 Add TaskSyncExtensions for sync Task execution (.NET FW)
Introduced TaskSyncExtensions class with Sync extension methods to allow synchronous execution of Task and Task<TResult> instances. This enables blocking on async code and is conditionally compiled for .NET Framework builds.
2026-01-16 11:03:53 +01:00
f4a921e268 Adjust BuildQuery param types for .NET Framework compatibility
Use conditional compilation to set BuildQuery's tuple Value type
to object for .NET Framework and object? for other targets,
ensuring compatibility with nullable reference types across
different .NET versions.
2026-01-16 10:58:26 +01:00
cdb52dc6fd Add strongly-typed HTTP API methods to ReCClient
Introduce async/sync methods for all major API controllers in ReCClient, supporting GET, POST, PUT, and DELETE with JSON serialization. Add utility methods for query building and JSON content. Mark sync wrappers as [Obsolete]. Add System.Net.Http.Json dependency and supporting usings. Introduce ResultType enum. This greatly expands ReCClient's API coverage and usability.
2026-01-16 10:54:46 +01:00
f14f6c1f15 Rename GetProfile method to Get in ProfileController
Renamed the GetProfile method to Get in the ProfileController to standardize method naming. No changes were made to the method's functionality or parameters.
2026-01-16 10:48:42 +01:00
6a24719342 Remove obsolete MappingProfile classes from Endpoints/RecActions
Removed AutoMapper MappingProfile classes from ReC.Application.Endpoints and ReC.Application.RecActions. These profiles mapped command objects to DTOs with default values. The change reflects a move toward using procedures or views for these mappings.
2026-01-16 10:40:28 +01:00
631ab8cba5 Remove obsolete OutRes command/query validators
Deleted DeleteOutResCommandValidator and ReadOutResQueryValidator classes, which were marked as obsolete. These validators are no longer needed due to a shift toward using related procedures or views for validation.
2026-01-16 10:37:57 +01:00
872878b9d7 Remove obsolete OutRes and RecAction CQRS classes
Removed deprecated command, query, and mapping classes for OutRes and RecAction entities, including their handlers and AutoMapper profiles. These components were previously marked as obsolete and have been superseded by database procedures or views. This cleanup eliminates redundant code and enforces the use of the updated data access patterns.
2026-01-16 10:36:43 +01:00
5a30b0ece4 Remove ObtainEndpointCommand and its handler
Deleted the ObtainEndpointCommand, its handler, and related using directives. This command was previously used to obtain or create Endpoint entities by URI, but has been removed in favor of using a related procedure or view as indicated by its Obsolete attribute.
2026-01-16 10:36:10 +01:00
37200617ea Remove unused entity-to-DTO mappings from DtoMappingProfile
Cleaned up DtoMappingProfile by removing mappings for several domain entities (OutRes, Connection, Endpoint, EndpointAuth, EndpointParam, Profile, RecAction) to their DTOs. Only view-to-DTO mappings remain. Also removed unused using directives.
2026-01-16 10:35:21 +01:00
8ab66db1f2 Remove obsolete entity DbSets and configs from RecDbContext
Removed all DbSet properties and Fluent API configurations for obsolete domain entities (EndpointParam, OutRes, Connection, Endpoint, EndpointAuth, Profile, RecAction) from RecDbContext. These entities are now accessed via views, further enforcing the transition to view-based data access. Only view-based models remain configured in the context.
2026-01-16 10:29:27 +01:00
cbd52721ac Remove obsolete DbSets from IRecDbContext interface
Removed DbSet properties for entities marked as obsolete in IRecDbContext, including EndpointParam, OutRes, Connection, Endpoint, EndpointAuth, Profile, and RecAction. Retained only DbSets for views and query results to encourage use of views instead of direct entity access. This streamlines the interface and aligns with the intended data access pattern.
2026-01-16 10:24:09 +01:00
3003559d7a Remove obsolete navigation properties from RecActionView
Removed Root, Endpoint, EndpointAuth, and SqlConnection navigation properties from RecActionView, along with their [ForeignKey] and [Obsolete] attributes. This streamlines the data model by retaining only foreign key IDs and related string properties, reducing direct entity navigation in favor of using related procedures or views.
2026-01-16 10:21:50 +01:00
6cabdbb6a3 Remove obsolete entity classes in favor of views
Removed Connection, Endpoint, EndpointAuth, EndpointParam, OutRes, Profile, and RecAction classes, which represented database tables and were marked as obsolete. This cleanup supports the transition to using database views or an updated data access approach. All related code, including attributes and properties, has been deleted.
2026-01-16 10:20:22 +01:00
4dd54e206e Update EndpointAuth references to fully qualified name
Replaced unqualified EndpointAuth with Domain.Entities.EndpointAuth
in DtoMappingProfile and IRecDbContext to improve clarity and
avoid potential naming conflicts.
2026-01-16 10:18:40 +01:00
84cf5c8e4d Add EndpointsController for endpoint CRUD operations
Introduced EndpointsController with POST, PUT, and DELETE API endpoints for managing endpoints. Utilizes MediatR to handle insert, update, and delete procedures, and retrieves configuration values as needed. Includes proper routing and response type annotations.
2026-01-16 10:15:07 +01:00
84d6e7a511 Add EndpointParamsController for CRUD via procedures
Introduced EndpointParamsController to manage endpoint parameter records using stored procedures. The controller supports POST (insert), PUT (update), and DELETE operations, leverages MediatR for command handling, and uses dependency injection for configuration and mediator services. Endpoints are documented and specify response types.
2026-01-16 10:13:33 +01:00
89238cc2d1 Add EndpointAuthController with CRUD endpoints
Introduced EndpointAuthController to manage endpoint authentication records via MediatR and procedure-based commands. Added POST (insert), PUT (update), and DELETE (range delete) endpoints. Controller uses dependency injection and provides XML documentation for each action.
2026-01-16 10:12:11 +01:00
7b177f21c8 Remove ResultViewController and related API endpoints
Removed the entire ResultViewController.cs file, including all endpoints for result view queries and insertions. This eliminates support for fake profile IDs, result type filtering, and all related API logic from the codebase.
2026-01-16 10:08:47 +01:00
2deb235c8d Update Post to use CreatedAtAction with Location header
Refactored the Post method to return a 201 Created response using CreatedAtAction. This change adds a Location header pointing to the Get action with the relevant actionId, and includes both the new record's ID and actionId in the response body. This improves API usability and aligns with RESTful conventions.
2026-01-16 10:07:21 +01:00
c452724c9e Rename controller methods for consistency and clarity
Renamed CreateAction to Create and UpdateAction to Update in RecActionController to improve naming consistency. No changes to method logic or signatures.
2026-01-16 10:02:16 +01:00
13e65774cc Add procedure-based update and delete endpoints to controller
Refactored RecActionController to support update via a new PUT endpoint using UpdateActionProcedure. Changed DELETE endpoints to use DeleteActionProcedure payloads instead of command objects, removing obsolete attributes. Updated using statements for new procedure types and standardized payload handling for update and delete operations.
2026-01-16 10:01:08 +01:00
f2d2dc9a32 Add procedure-based CRUD endpoints to ProfileController
Extended ProfileController with POST, PUT, and DELETE endpoints for profile management using InsertProfileProcedure, UpdateProfileProcedure, and DeleteProfileProcedure. Added necessary using directives and XML documentation for each new endpoint.
2026-01-16 09:57:18 +01:00
459620e1dd Refactor update procedures: rename Guid to Id
Renamed all `Guid` properties and parameters to `Id` in update procedure interfaces, records, and handlers. This clarifies that the identifier is a numeric ID, not a GUID, and improves consistency across the codebase. All related method signatures and usages have been updated accordingly.
2026-01-16 09:53:50 +01:00
df2541108b Add POST/PUT endpoints for RESULT insert and update
Added POST endpoint to insert RESULT records and PUT endpoint to update RESULT records in OutResController. Integrated InsertResultProcedure and UpdateResultProcedure with MediatR, returning appropriate status codes. Updated using directives accordingly.
2026-01-16 09:51:30 +01:00
5dcd5313a5 Refactor EndpointParams procedures to Commands namespace
Moved Delete, Insert, and UpdateEndpointParamsProcedure classes from Common.Procedures to EndpointParams.Commands for better organization. Updated related imports in InsertObjectProcedure.cs and UpdateObjectProcedure.cs to reflect the new namespace. No functional changes to the procedures themselves.
2026-01-16 09:44:46 +01:00
ef9d725f59 Refactor endpoint procedures to Endpoints.Commands namespace
Moved Delete/Insert/UpdateEndpointProcedure classes from Common.Procedures to Endpoints.Commands namespace. Updated using directives accordingly for improved code organization and maintainability. No changes to class logic.
2026-01-16 09:41:19 +01:00
6f4ab073df Move EndpointAuth procedures to dedicated namespace
Refactored Delete/Insert/UpdateEndpointAuthProcedure records into the new ReC.Application.EndpointAuth.Commands namespace for better organization. Updated using statements in related files to ensure compatibility. No functional changes to the procedure records themselves.
2026-01-16 09:38:59 +01:00
f6b95331e1 Refactor procedure classes into feature-based namespaces
Moved Insert, Update, and Delete procedure records for Action, Profile, and Result entities from common namespaces to feature-specific namespaces. Updated all relevant using directives and controller references. No logic changes; this improves code organization and maintainability.
2026-01-16 09:34:41 +01:00
82de285891 Refactor OutResController to use DeleteResultProcedure
Refactored DELETE endpoints in OutResController to use the new DeleteResultProcedure payload instead of DeleteOutResCommand. Updated endpoints to call mediator.ExecuteDeleteProcedure and revised XML docs accordingly. Removed obsolete attributes and command references. The "fake" profile deletion now uses the procedure with the fake profile ID.
2026-01-16 09:18:15 +01:00
Developer 02
cbd86de3e8 Add handling for update and delete exceptions
Enhanced `ExceptionHandlingMiddleware` to handle
`UpdateObjectFailedException` and `DeleteObjectFailedException`.
Logs exception details, including serialized procedure data,
and sets HTTP status to `500 Internal Server Error`.
Improves error differentiation and response for specific failure cases.
2026-01-16 01:10:57 +01:00
Developer 02
a5160b35dd Add HTTP DELETE endpoint to CommonController
A new `DeleteObject` method has been added to the `CommonController` class to handle HTTP DELETE requests. This method is asynchronous and processes a `DeleteObjectProcedure` object passed in the request body using the `mediator.Send` function. The result is returned as an HTTP 200 OK response. The `[HttpDelete]` attribute has been applied to the method to designate it as a DELETE endpoint.
2026-01-16 01:08:30 +01:00
Developer 02
60e1627494 Add UpdateObject endpoint and enhance procedure support
Enhanced `CommonController` to support object operations:
- Added `using` statements for Insert, Update, and Delete procedures.
- Updated constructor to inject `IMediator` for request handling.
- Introduced `UpdateObject` endpoint with HTTP PUT support.
  - Processes `UpdateObjectProcedure` via MediatR.
  - Returns HTTP 200 OK with the result.
2026-01-16 01:08:20 +01:00
Developer 02
b9f08bc21c Add DeleteActionProcedure for ACTION entity deletion
Introduced a new `DeleteActionProcedure` record in the
`ReC.Application.Common.Procedures.DeleteProcedure` namespace.

This record implements the `IDeleteProcedure` interface and includes
the following properties:
- `Start`: Starting GUID/ID (inclusive).
- `End`: Ending GUID/ID (inclusive), defaults to `Start` if 0.
- `Force`: Allows deletion even if dependent RESULT data exists.

Added a `ToObjectProcedure` method to convert `DeleteActionProcedure`
to a `DeleteObjectProcedure` with the entity set to `"ACTION"`.
2026-01-16 01:06:56 +01:00
Developer 02
758616c95e Add DeleteEndpointAuthProcedure for endpoint deletion
Introduce the `DeleteEndpointAuthProcedure` record in the new
`ReC.Application.Common.Procedures.DeleteProcedure` namespace.
This record implements the `IDeleteProcedure` interface and
provides properties for specifying a range of GUID/IDs (`Start`
and `End`) and a `Force` flag to allow deletion despite dependent
data.

Add the `ToObjectProcedure` method to convert the record into a
`DeleteObjectProcedure` with the entity set to `"ENDPOINT_AUTH"`.
2026-01-16 01:06:45 +01:00
Developer 02
7376b49e38 Add DeleteEndpointParamsProcedure record
A new `DeleteEndpointParamsProcedure` record was introduced in the
`ReC.Application.Common.Procedures.DeleteProcedure` namespace. This
record implements the `IDeleteProcedure` interface and provides
properties for specifying a range of GUID/IDs (`Start` and `End`)
and a `Force` flag to allow deletion even with dependent data.

The record includes a `ToObjectProcedure` method to convert its
data into a `DeleteObjectProcedure` instance, setting the entity
to `"ENDPOINT_PARAMS"` and mapping the `Start`, `End`, and `Force`
properties.
2026-01-16 01:06:33 +01:00
Developer 02
b65c354ef0 Add DeleteEndpointProcedure for endpoint deletion
Introduced a new `DeleteEndpointProcedure` record in the
`ReC.Application.Common.Procedures.DeleteProcedure` namespace.

This record implements the `IDeleteProcedure` interface and includes
properties for specifying the start and end GUID/ID range, as well as
a `Force` flag to allow deletion even with dependent data.

Added a `ToObjectProcedure` method to convert the record into a
`DeleteObjectProcedure` with the entity set to "ENDPOINT".
2026-01-16 01:06:22 +01:00
Developer 02
38258a98c1 Add DeleteProfileProcedure for profile deletion logic
Introduce the `DeleteProfileProcedure` record in the new
`ReC.Application.Common.Procedures.DeleteProcedure` namespace.
This record implements the `IDeleteProcedure` interface and
provides properties for specifying a range of GUID/IDs
(`Start`, `End`) and a `Force` flag to allow deletion even
with dependent ACTION data.

Added a `ToObjectProcedure` method to convert
`DeleteProfileProcedure` instances into `DeleteObjectProcedure`
objects, setting the `Entity` to `"PROFILE"`.
2026-01-16 01:06:12 +01:00
Developer 02
7666708ab5 Add DeleteResultProcedure for RESULT entity deletion
Introduced a new `DeleteResultProcedure` record in the
`ReC.Application.Common.Procedures.DeleteProcedure` namespace.

This record implements the `IDeleteProcedure` interface and provides
properties for specifying a range of GUID/IDs (`Start` and `End`)
and a `Force` flag.

Added a `ToObjectProcedure` method to convert the record into a
`DeleteObjectProcedure` with the entity set to "RESULT".
2026-01-16 01:06:00 +01:00
Developer 02
d3b67bc429 Add IDeleteProcedure interface for delete operations
Introduced a new namespace `ReC.Application.Common.Procedures.DeleteProcedure` and added the `IDeleteProcedure` interface. This interface defines a `ToObjectProcedure` method, which returns a `DeleteObjectProcedure` object. These changes aim to standardize and encapsulate delete-related procedures in the application.
2026-01-16 01:05:46 +01:00
Developer 02
97f992aef5 Add DeleteObjectProcedure for entity deletion handling
Introduce `DeleteObjectProcedure` to encapsulate parameters for
delete operations, including entity, ID range, and force flag.
Add `DeleteObjectProcedureExtensions` for convenient invocation
via `ISender`. Implement `DeleteObjectProcedureHandler` to
execute the `[dbo].[PRREC_DELETE_OBJECT]` stored procedure
using dynamic SQL parameters.

Throw `DeleteObjectFailedException` on failure and ensure
`End` defaults to `Start` if unset. Add XML documentation
for improved code clarity. Include necessary `using`
directives for dependencies.
2026-01-16 01:05:28 +01:00
Developer 02
cc6f93ae1c Add DeleteObjectFailedException for delete operation errors
A new `DeleteObjectFailedException` class was introduced in the
`ReC.Application.Common.Exceptions` namespace to handle errors
related to failed delete operations.

This class includes:
- A `Procedure` property of type `DeleteObjectProcedure` to
  provide context about the failed operation.
- Three constructors to support different levels of detail
  (procedure only, procedure with a message, and procedure with
  a message and inner exception).

Additionally, a `using` directive for the
`ReC.Application.Common.Procedures.DeleteProcedure` namespace
was added to support the `DeleteObjectProcedure` type.
2026-01-16 01:05:10 +01:00
Developer 02
402990bd3c Add UpdateResultProcedure record for result updates
Introduced a new `UpdateResultProcedure` record in the
`ReC.Application.Common.Procedures.UpdateProcedure` namespace.
This record implements the `IUpdateProcedure` interface and
includes properties for `ActionId`, `StatusId`, `Header`, and
`Body`.

Added a `ToObjectProcedure` method to convert the record into
an `UpdateObjectProcedure` instance, setting the `Entity` to
"RESULT", and allowing optional tracking of changes via the
`ChangedBy` method.
2026-01-16 00:59:43 +01:00
Developer 02
43cdef4910 Add UpdateProfileProcedure record for profile updates
Introduced a new namespace `ReC.Application.Common.Procedures.UpdateProcedure`.
Added the `UpdateProfileProcedure` record implementing the `IUpdateProcedure` interface.
This record includes several nullable properties such as `Active`, `TypeId`, `Name`, `Description`, and others.
Added the `ToObjectProcedure` method to convert the record into an `UpdateObjectProcedure` instance, setting the entity to "PROFILE" and supporting optional change tracking via `ChangedBy`.
2026-01-16 00:59:33 +01:00
Developer 02
348a55fc60 Add UpdateEndpointProcedure record for endpoint updates
A new `UpdateEndpointProcedure` record was introduced in the
`ReC.Application.Common.Procedures.UpdateProcedure` namespace.
This record implements the `IUpdateProcedure` interface and
includes nullable properties `Active`, `Description`, and `Uri`.

The `ToObjectProcedure` method was added to convert the record
into an `UpdateObjectProcedure` instance, setting the `Entity`
to `"ENDPOINT"`, the `Guid` to the provided parameter, and the
`Endpoint` to the current instance. The method also supports
tracking changes via the optional `changedWho` parameter.
2026-01-16 00:59:23 +01:00
Developer 02
719bc9c941 Add UpdateEndpointParamsProcedure record
A new `UpdateEndpointParamsProcedure` record has been added under the `ReC.Application.Common.Procedures.UpdateProcedure` namespace. This record implements the `IUpdateProcedure` interface and includes nullable properties such as `Active`, `Description`, `GroupId`, `Sequence`, `Key`, and `Value`.

Additionally, a `ToObjectProcedure` method has been introduced, which converts the record into an `UpdateObjectProcedure` instance with the `Entity` set to `"ENDPOINT_PARAMS"`, and supports optional tracking of the user who made the change.
2026-01-16 00:59:10 +01:00
Developer 02
37381af042 Add UpdateEndpointAuthProcedure for endpoint updates
Introduce the `UpdateEndpointAuthProcedure` record in the
`ReC.Application.Common.Procedures.UpdateProcedure` namespace.

This class implements the `IUpdateProcedure` interface and includes
properties for managing endpoint authentication details such as
`Active`, `Description`, `TypeId`, `ApiKey`, `ApiValue`, `Token`,
`Username`, `Password`, `Domain`, and `Workstation`.

Add the `ToObjectProcedure` method to convert the procedure into
an `UpdateObjectProcedure` instance, setting the entity to
`ENDPOINT_AUTH` and allowing optional tracking of the user who
made the changes.
2026-01-16 00:58:55 +01:00
Developer 02
34fe996d91 Add UpdateActionProcedure record for update operations
Introduced a new `UpdateActionProcedure` record in the
`ReC.Application.Common.Procedures.UpdateProcedure` namespace.
This record implements the `IUpdateProcedure` interface and
includes several nullable properties such as `ProfileId`,
`Active`, `Sequence`, `EndpointId`, and others to support
update operations.

Added a `ToObjectProcedure` method to the record, which
creates and returns an `UpdateObjectProcedure` instance
with the entity set to "ACTION" and other relevant details.
This method also supports tracking changes via the `ChangedBy`
method.
2026-01-16 00:58:42 +01:00
Developer 02
252fc10243 Add IUpdateProcedure interface for update handling
Introduced a new namespace `ReC.Application.Common.Procedures.UpdateProcedure` and added the `IUpdateProcedure` interface. This interface defines a `ToObjectProcedure` method for converting to an `UpdateObjectProcedure`. The method accepts a `guid` parameter and an optional `changedWho` parameter to track changes. This addition establishes a contract for handling update procedures.
2026-01-16 00:58:26 +01:00
Developer 02
c8a9245b54 Add UpdateObjectProcedure for entity updates
Introduce `UpdateObjectProcedure` to handle updates for various
entities using a stored procedure. Implement MediatR-based
request/response pattern with `IRequest<int>` and add the
`UpdateObjectProcedureHandler` to execute the update logic.

Include an extension method `ExecuteUpdateProcedure` for
simplified execution of update requests. Add exception handling
via `UpdateObjectFailedException` to manage update failures.

Integrate dependencies on `DigitalData.Core.Abstraction.Application.Repository`,
`MediatR`, and `Microsoft.Data.SqlClient`. Ensure extensibility
and reliability in the update process.
2026-01-16 00:58:11 +01:00
Developer 02
c56bcc198e Add UpdateObjectFailedException for update operation errors
A new exception class, `UpdateObjectFailedException`, was added to the `ReC.Application.Common.Exceptions` namespace to handle failures during update operations.

The class includes a `Procedure` property of type `UpdateObjectProcedure` to store the associated procedure. It provides three constructors to support different levels of detail: one with just the procedure, one with a procedure and a custom message, and one with a procedure, a custom message, and an inner exception.

The `UpdateObjectProcedure` type is referenced from the `ReC.Application.Common.Procedures.UpdateProcedure` namespace, which is now included via a `using` directive.
2026-01-16 00:57:37 +01:00
Developer 02
538abec212 Add entity configurations and suppress obsolete warnings
Introduced entity configurations in `RecDbContext` for `Connection`, `Endpoint`, `EndpointAuth`, `EndpointParam`, `OutRes`, `Profile`, `ProfileView`, `RecAction`, and `RecActionView`. Mapped entities to corresponding tables or views with column configurations.

Added relationships:
- `Profile` to `Actions` (one-to-many).
- `RecAction` to `OutRes` (one-to-one with cascade delete).

Suppressed CS0618 warnings in `OnModelCreating` to handle obsolete members.
2026-01-15 23:59:13 +01:00
Developer 02
19666e649d Add obsolete DbSets and transition to Views in RecDbContext
Several new DbSet properties were added to the RecDbContext
class, marked as `[Obsolete("Use Views instead.")]`. These
include `EndpointParams`, `OutRes`, `Connections`, `Endpoints`,
`EndpointAuths`, `Profiles`, and `RecActions`.

Non-obsolete DbSets such as `RecActionViews`, `ProfileViews`,
`RecResultViews`, `HeaderQueryResults`, `BodyQueryResults`,
and `RecResults` were also added or retained.

These changes indicate a shift towards using Views for database
operations while maintaining backward compatibility with the
older DbSet properties.
2026-01-15 23:56:06 +01:00
Developer 02
1df9235036 Disambiguate Profile mapping in AutoMapper configuration
Updated the mapping configuration in `DtoMappingProfile` to use
the fully qualified name `Domain.Entities.Profile` for the
`Profile` entity. This change resolves potential ambiguity with
other classes named `Profile` in the codebase.
2026-01-15 23:54:28 +01:00
dd9c1c7ca2 Change default addedWho param to null in ToObjectProcedure
Updated ToObjectProcedure methods in Insert*Procedure records to use null as the default value for the addedWho parameter instead of "Rec.API". This affects InsertActionProcedure, InsertEndpointAuthProcedure, InsertEndpointParamsProcedure, InsertEndpointProcedure, and InsertProfileProcedure.
2026-01-14 17:14:17 +01:00
f9cc735318 Update AddedBy to default to "ReC.API" if no value provided
The AddedBy method in InsertObjectProcedure now accepts an optional parameter and sets AddedWho to "ReC.API" when no argument is supplied, ensuring a consistent default value.
2026-01-14 17:12:15 +01:00
2a8eb3c0ad Mark legacy DbSets as obsolete in IRecDbContext
Several entity-based DbSet properties in IRecDbContext are now marked with [Obsolete("Use Views instead.")], guiding developers to use view-based DbSets. The Profiles DbSet is now explicitly typed as Domain.Entities.Profile. No functional code was removed.
2026-01-14 17:10:55 +01:00
7a4cdb3d1f Support querying multiple profile views in ReadProfileView
Refactored ReadProfileViewQuery and handler to return multiple profiles as IEnumerable<ProfileViewDto>. Made Id parameter optional to allow fetching all profiles. Updated exception handling for empty results.
2026-01-14 16:30:41 +01:00
453b6d1813 Add ProfileController with MediatR GET endpoint
Introduced ProfileController to the API, implementing a GET endpoint that uses MediatR to handle ReadProfileViewQuery requests and return profile data. This supports CQRS and structured profile retrieval.
2026-01-14 16:23:00 +01:00
bd2b5ff62f Add ReadProfileViewQuery and handler for profile views
Introduce CQRS/MediatR query and handler to fetch ProfileView by Id,
optionally including related Actions. Uses repository and AutoMapper,
throws NotFoundException if profile is missing, and returns ProfileViewDto.
2026-01-14 16:12:54 +01:00
849de7a204 Replace CreateResultViewCommand with InsertResultProcedure
Updated ResultViewController to use InsertResultProcedure instead of CreateResultViewCommand. Changed import statements, method parameters, and response construction to reflect the new procedure type.
2026-01-14 15:31:16 +01:00
c7423fb6fd Refactor RecAction creation and remove fake endpoint
Refactored the CreateAction endpoint to use InsertActionProcedure and mediator.ExecuteInsertProcedure, replacing the obsolete CreateRecActionCommand. Removed the deprecated CreateFakeAction endpoint and all related code from RecActionController.
2026-01-14 15:25:40 +01:00
ad51e4b1eb Update OutResController to use ReadResultViewQuery
Switched GET endpoints to ReadResultViewQuery for modernized query handling. Removed [Obsolete] from the controller class, but added it to DELETE endpoints to mark them as deprecated. Updated "fake" profile GET endpoints to use the new query model and removed obsolete warnings from these methods.
2026-01-14 15:10:20 +01:00
df2ebe0cc2 Refactor to use ExecuteInsertProcedure for result insert
Replaced sender.Send and ToObjectProcedure with sender.ExecuteInsertProcedure, passing the InsertResultProcedure object, AddedWho config, and cancellation token directly. This simplifies and clarifies the result insertion process.
2026-01-14 15:00:22 +01:00
5c06f287ab Refactor insert procedure API and add extension method
Changed IInsertProcedure.ToObjectProcedure to accept an optional addedWho parameter. Introduced InsertObjectProcedureExtensions with an ExecuteInsertProcedure extension for ISender, defaulting addedWho to "Rec.API" if not specified.
2026-01-14 14:56:10 +01:00
c3e3a0377d Switch to InsertResultProcedure for result handling
Replaced CreateOutResCommand with InsertResultProcedure when sending results. Updated property names (StatusId instead of Status) and now use ToObjectProcedure to include AddedWho. Added InsertProcedure namespace import.
2026-01-14 14:40:30 +01:00
cf34a54170 Mark CreateResultViewCommand as obsolete, add handler
CreateResultViewCommand is now marked obsolete, advising use of related procedures or views instead. Added an obsolete CreateResultViewCommandHandler that delegates creation to the repository.
2026-01-14 14:36:30 +01:00
16f48f125b Refactor ToObjectProcedure default parameter handling
Changed ToObjectProcedure to use a nullable addedWho parameter and set "Rec.API" as a fallback within the method, ensuring consistent default behavior.
2026-01-14 14:32:17 +01:00
e3faa2f570 Mark entity classes as obsolete; add table attributes
Marked Connection, Endpoint, EndpointAuth, EndpointParam, OutRes, Profile, and RecAction classes as obsolete with [Obsolete("Use Views instead.")]. Added or updated [Table] attributes to specify database tables and schemas for each class. This signals a transition to using Views instead of these entities.
2026-01-14 13:41:52 +01:00
0d30b5ff87 Register default repository for TRecDbContext
Also register the default repository for TRecDbContext in dependency injection, ensuring both custom and default repositories are available for use.
2026-01-14 13:32:09 +01:00
563375f6e3 Refactor validator to use nested property accessors
Update InsertObjectProcedureValidator to reference nested properties (e.g., x.Action.ProfileId instead of x.ActionProfileId) throughout all entity validation rules. Adjust .When conditions accordingly to match the new data model structure with grouped sub-objects.
2026-01-14 13:17:10 +01:00
3864b0f68b Add CommonController with POST endpoint using MediatR
Introduced CommonController in the ReC.API.Controllers namespace with a POST endpoint at "api/common". The endpoint accepts an InsertObjectProcedure from the request body, sends it via MediatR, and returns a 201 Created response with the generated ID.
2026-01-14 13:13:23 +01:00
35e03269e7 Add DbSets for EndpointParam and view entities
Added DbSet properties for EndpointParam, RecActionView, and ProfileView to both IRecDbContext and RecDbContext. This enables querying and interaction with these entities and views in the database. Grouped the new DbSets under a #region for better code organization.
2026-01-14 12:00:36 +01:00
8b212d541e Refactor AddedWho assignment in InsertObjectProcedure
AddedWho is now set via the AddedBy method instead of direct assignment in object initializers. The property is made internal with a private setter to prevent external modification. All ToObjectProcedure methods in insert procedure records are updated to use AddedBy for consistency and encapsulation.
2026-01-14 11:51:42 +01:00
dd4cecc15d Rename InsertObjectFailedException.Request to Procedure
Updated ExceptionHandlingMiddleware to use the new Procedure property name when logging InsertObjectFailedException. Changed error title for BadRequestException to "Bad Procedure". Removed unused System.Text.Json using directive from InsertObjectProcedure.cs.
2026-01-14 09:54:19 +01:00
0dedb506e1 Handle InsertObjectFailedException in middleware
Add specific handling for InsertObjectFailedException in ExceptionHandlingMiddleware, including detailed logging and custom error response. Refactor InsertObjectFailedException to expose the request data via a public property for improved error reporting.
2026-01-14 09:51:40 +01:00
24f146ca26 Refactor InsertObjectFailedException for more context
InsertObjectFailedException now requires an InsertObjectProcedure
instance, improving error context. Exception throwing in
InsertObjectProcedureHandler updated to pass the procedure object
instead of just a message and serialized request.
2026-01-14 09:44:31 +01:00
2692553865 Add 'addedWho' param to insert procedures for auditing
Updated IInsertProcedure and all implementations to accept an optional 'addedWho' parameter in ToObjectProcedure, defaulting to "Rec.API". This enables tracking of the entity responsible for insert operations.
2026-01-14 09:37:17 +01:00
d90c2fab96 Refactor: split insert procedures into separate files
Refactored insert procedure-related classes by moving each record type (Action, Endpoint, EndpointAuth, Profile, Result, EndpointParams) and the IInsertProcedure interface into their own files under the new InsertProcedure namespace. Updated InsertObjectProcedureValidator to use the new namespace. This improves code organization, readability, and maintainability.
2026-01-14 09:26:27 +01:00
854e36e71f 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.
2026-01-14 09:18:52 +01:00
1d31f2aff9 Refactor InsertObjectProcedure to use nested records
Reorganized InsertObjectProcedure by grouping related properties into nested record types (Action, Endpoint, EndpointAuth, Profile, Result, EndpointParams) for better encapsulation and maintainability. Updated handler logic to use new structure and set AddedWhen to DateTime.UtcNow. Improved error logging and added System.Text.Json usage.
2026-01-12 16:47:57 +01:00
11206cf84f Throw exception on failed InsertObject identifier return
Replace default return of 0 with InsertObjectFailedException when the stored procedure does not return a valid identifier. Exception message includes serialized request for easier debugging. Added necessary imports for exception and JSON serialization.
2026-01-12 16:27:45 +01:00
b48ebd8e88 Refactor InsertObjectFailedException constructors
Refactored InsertObjectFailedException to use explicit constructors: parameterless, message-only, and message with inner exception. Removed constructors with optional parameters for clearer and more standard .NET exception handling.
2026-01-12 16:21:16 +01:00
12d17e0808 Add InsertObjectFailedException custom exception class
Introduced InsertObjectFailedException in the ReC.Application.Common.Exceptions namespace. This exception provides constructors for custom messages and inner exceptions, and is intended to signal failures during object insertion operations.
2026-01-12 16:16:52 +01:00
1dee3180d5 Refactor InsertObjectProcedure into entity-based regions
Organized properties into regions by target entity for clarity.
No functional changes; update improves code readability
and maintainability.
2026-01-12 16:07:52 +01:00
bd4046a6c1 Add InsertObjectProcedureValidator with entity-specific rules
Introduced InsertObjectProcedureValidator using FluentValidation to enforce required fields and string length constraints for InsertObjectProcedure. Validation rules are applied conditionally based on the Entity type, ensuring correct data for ACTION, ENDPOINT, PROFILE, RESULT, and ENDPOINT_PARAMS. Optional string fields also receive length checks.
2026-01-12 16:03:10 +01:00
af6f94c1ed Improve handling of stored procedure return value type
Check if return value is already a long before parsing its
string representation. This enhances robustness and efficiency
when the value is of the correct type.
2026-01-12 15:48:03 +01:00
7bfb56b664 Add InsertObjectProcedure MediatR command and handler
Introduces InsertObjectProcedure and its handler to support generic, parameterized insertion of various object types (ACTION, ENDPOINT, etc.) via a single stored procedure. The handler maps request properties to SQL parameters, executes the procedure, and returns the output GUID. This enables flexible and unified object creation through MediatR.
2026-01-12 15:19:54 +01:00
1a6eced316 Rename InsertObject to InsertObjectProcedure
Renamed the InsertObject MediatR request record to InsertObjectProcedure and moved it from InsertObject.cs to InsertObjectProcedure.cs. The structure and functionality remain unchanged; it still defines an Entity property with a default value of "ACTION".
2026-01-12 14:35:16 +01:00
c82749bcbf Add TODO comment for appsettings.json config in DbContext
A TODO comment was added above OnModelCreating in RecDbContext to note that configuration should be updated to use appsettings.json in the future. No functional changes were made.
2026-01-12 14:25:15 +01:00
e8fa149532 Move InsertObjectResult mapping to Fluent API
Removed [Column] attribute from InsertObjectResult and configured column mapping for NewObjectId in RecDbContext using the Fluent API. This centralizes entity mapping logic in the DbContext.
2026-01-12 14:20:41 +01:00
aaa7beb92a Add RecResults DbSet for InsertObjectResult entities
Added RecResults DbSet to IRecDbContext and RecDbContext to support managing InsertObjectResult entities. Updated IRecDbContext to include the new DbSet and ensured SaveChangesAsync is defined. Enables querying and persisting InsertObjectResult via EF Core.
2026-01-12 14:19:19 +01:00
5cce52ec27 Add ProfileViews and RecResultViews to IRecDbContext
Updated IRecDbContext to include DbSet properties for ProfileView and ResultView entities, enabling management of these collections within the context.
2026-01-12 14:17:34 +01:00
3f36f048b2 Add InsertObjectResult class for object insert results
Introduced InsertObjectResult in ReC.Domain.QueryOutput with a required NewObjectId property mapped to the "oGUID" column. This class will be used to represent the result of object insert operations. Added necessary using directive for data annotations.
2026-01-12 14:17:04 +01:00
92e8d9e778 Move query result classes to QueryOutput namespace
BodyQueryResult and HeaderQueryResult were relocated from ReC.Domain.Entities to ReC.Domain.QueryOutput. Updated all references in IRecDbContext and RecDbContext to use the new namespace.
2026-01-12 14:11:05 +01:00
2d04670fef Set default Entity to "ACTION" in InsertObject
Added XML summary to Entity property describing valid values.
Changed default value from null to "ACTION" for clarity.
2026-01-12 14:08:03 +01:00
c0085b4c18 Add InsertObject record for MediatR-based insert requests
Introduced InsertObject record in ReC.Application.Common.Procedures namespace. This record implements MediatR's IRequest<long> and includes a non-nullable Entity property to support object insertion operations.
2026-01-12 13:54:04 +01:00
59ea5e3e67 Update action invocation logic and remove EndpointAuth include
Changed invocation filter to use Results.Any() instead of Root.OutRes.
Removed eager loading of EndpointAuth from the query.
2026-01-12 13:26:54 +01:00
a9f2c4c2f7 Add Action and Profile relationships to Result entity
Added navigation properties and foreign key relationships from Result to Action (one-to-many) and Profile (many-to-one) entities using ActionId and ProfileId. This enhances entity associations in the data model.
2026-01-12 13:03:56 +01:00
001f4bf2c5 Configure one-to-many relationship for Profile-Actions
Added entity mapping to establish a one-to-many relationship between profiles and actions, with actions referencing their parent profile via the ProfileId foreign key.
2026-01-12 12:54:00 +01:00
bfe6c12ee0 Annotate ProfileView and add Actions property
ProfileView is now mapped to the VWREC_PROFILE table using the
[Table] attribute. Added an Actions property to support related
RecActionView collections.
2026-01-12 12:50:05 +01:00
e1260e49f0 Add one-to-many Action-Results relationship mapping
Added entity configuration to define a one-to-many relationship between Actions and Results. Each Action can have multiple Results, and each Result references its parent Action via the ActionId foreign key.
2026-01-12 12:47:21 +01:00
8b86eca838 Add obsolete navigation props to RecActionView class
Added Results, Root, Endpoint, EndpointAuth, and SqlConnection navigation properties to RecActionView, all marked as [Obsolete] to guide usage toward related procedures or views. Foreign key attributes applied where relevant.
2026-01-12 12:39:53 +01:00
107 changed files with 2781 additions and 1112 deletions

28
ReC.sln
View File

@@ -20,6 +20,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
assets\icon.png = assets\icon.png
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastructure", "{3F88DACC-CEC0-4D9A-8BAA-37F67B02DC04}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "presentation", "presentation", "{3D6EF9B9-D00D-432A-8477-067902B5CE8E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{2CEF945E-94D6-4273-9BE1-20B628CD0A57}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8353C9B1-CC4A-4097-A936-C06D4C618415}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Tests", "tests\ReC.Tests\ReC.Tests.csproj", "{457ED5AC-F4A0-41C3-9758-4A3C272EDC11}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -46,16 +56,24 @@ Global
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Release|Any CPU.Build.0 = Release|Any CPU
{457ED5AC-F4A0-41C3-9758-4A3C272EDC11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{457ED5AC-F4A0-41C3-9758-4A3C272EDC11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{457ED5AC-F4A0-41C3-9758-4A3C272EDC11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{457ED5AC-F4A0-41C3-9758-4A3C272EDC11}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{420218AD-3C27-4003-9A84-36C92352F175} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{2917BEA4-6C70-40CD-BD46-57D4ADB40296} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{587A4D14-EFDA-4BE3-8912-D3AF84743079} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{109645F5-441D-476B-B7D2-FBEAA8EBAE14} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{420218AD-3C27-4003-9A84-36C92352F175} = {3D6EF9B9-D00D-432A-8477-067902B5CE8E}
{2917BEA4-6C70-40CD-BD46-57D4ADB40296} = {2CEF945E-94D6-4273-9BE1-20B628CD0A57}
{587A4D14-EFDA-4BE3-8912-D3AF84743079} = {3F88DACC-CEC0-4D9A-8BAA-37F67B02DC04}
{109645F5-441D-476B-B7D2-FBEAA8EBAE14} = {2CEF945E-94D6-4273-9BE1-20B628CD0A57}
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B} = {3D6EF9B9-D00D-432A-8477-067902B5CE8E}
{3F88DACC-CEC0-4D9A-8BAA-37F67B02DC04} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{3D6EF9B9-D00D-432A-8477-067902B5CE8E} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{2CEF945E-94D6-4273-9BE1-20B628CD0A57} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{457ED5AC-F4A0-41C3-9758-4A3C272EDC11} = {8353C9B1-CC4A-4097-A936-C06D4C618415}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F7B09104-4072-4635-9492-9C7C68D96ABD}

View File

@@ -0,0 +1,33 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class CommonController(IMediator mediator) : ControllerBase
{
[HttpPost]
public async Task<IActionResult> CreateObject([FromBody] InsertObjectProcedure procedure, CancellationToken cancel)
{
var id = await mediator.Send(procedure, cancel);
return StatusCode(StatusCodes.Status201Created, id);
}
[HttpPut]
public async Task<IActionResult> UpdateObject([FromBody] UpdateObjectProcedure procedure, CancellationToken cancel)
{
var result = await mediator.Send(procedure, cancel);
return Ok(result);
}
[HttpDelete]
public async Task<IActionResult> DeleteObject([FromBody] DeleteObjectProcedure procedure, CancellationToken cancel)
{
var result = await mediator.Send(procedure, cancel);
return Ok(result);
}
}

View File

@@ -0,0 +1,56 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.EndpointAuth.Commands;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class EndpointAuthController(IMediator mediator, IConfiguration config) : ControllerBase
{
/// <summary>
/// Inserts an endpoint authentication record via the ENDPOINT_AUTH insert procedure.
/// </summary>
/// <param name="procedure">InsertEndpointAuthProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The created ENDPOINT_AUTH identifier.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> Post([FromBody] InsertEndpointAuthProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel);
return StatusCode(StatusCodes.Status201Created, id);
}
/// <summary>
/// Updates an endpoint authentication record via the ENDPOINT_AUTH update procedure.
/// </summary>
/// <param name="id">ENDPOINT_AUTH identifier to update.</param>
/// <param name="procedure">UpdateEndpointAuthProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateEndpointAuthProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
/// <summary>
/// Deletes endpoint authentication records via the ENDPOINT_AUTH delete procedure for the specified id range.
/// </summary>
/// <param name="procedure">DeleteEndpointAuthProcedure payload (Start, End, Force).</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromBody] DeleteEndpointAuthProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
}

View File

@@ -0,0 +1,56 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.EndpointParams.Commands;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class EndpointParamsController(IMediator mediator, IConfiguration config) : ControllerBase
{
/// <summary>
/// Inserts endpoint parameter records via the ENDPOINT_PARAMS insert procedure.
/// </summary>
/// <param name="procedure">InsertEndpointParamsProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The created ENDPOINT_PARAMS identifier.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> Post([FromBody] InsertEndpointParamsProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel);
return StatusCode(StatusCodes.Status201Created, id);
}
/// <summary>
/// Updates endpoint parameter records via the ENDPOINT_PARAMS update procedure.
/// </summary>
/// <param name="id">ENDPOINT_PARAMS identifier to update.</param>
/// <param name="procedure">UpdateEndpointParamsProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateEndpointParamsProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
/// <summary>
/// Deletes endpoint parameter records via the ENDPOINT_PARAMS delete procedure for the specified id range.
/// </summary>
/// <param name="procedure">DeleteEndpointParamsProcedure payload (Start, End, Force).</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromBody] DeleteEndpointParamsProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
}

View File

@@ -0,0 +1,56 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Endpoints.Commands;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class EndpointsController(IMediator mediator, IConfiguration config) : ControllerBase
{
/// <summary>
/// Inserts an endpoint via the ENDPOINT insert procedure.
/// </summary>
/// <param name="procedure">InsertEndpointProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The created ENDPOINT identifier.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> Post([FromBody] InsertEndpointProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, config["AddedWho"], cancel);
return StatusCode(StatusCodes.Status201Created, id);
}
/// <summary>
/// Updates an endpoint via the ENDPOINT update procedure.
/// </summary>
/// <param name="id">ENDPOINT identifier to update.</param>
/// <param name="procedure">UpdateEndpointProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateEndpointProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
/// <summary>
/// Deletes endpoints via the ENDPOINT delete procedure for the specified id range.
/// </summary>
/// <param name="procedure">DeleteEndpointProcedure payload (Start, End, Force).</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromBody] DeleteEndpointProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
}

View File

@@ -1,91 +0,0 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.API.Extensions;
using ReC.API.Models;
using ReC.Application.OutResults.Commands;
using ReC.Application.OutResults.Queries;
namespace ReC.API.Controllers;
[Obsolete("This controller is deprecated and will be removed in future versions. Use the new ResultViewController instead.")]
[Route("api/[controller]")]
[ApiController]
public class OutResController(IMediator mediator, IConfiguration config) : ControllerBase
{
/// <summary>
/// Gets output results based on the provided query parameters.
/// </summary>
/// <param name="query">The query to filter output results.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>A list of output results matching the query.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
/// <summary>
/// Gets output results for a fake/test profile.
/// </summary>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>A list of output results for the fake profile.</returns>
[HttpGet("fake")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Obsolete("Use the related procedure or view.")]
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadOutResQuery()
{
ProfileId = config.GetFakeProfileId()
}, cancel));
/// <summary>
/// Gets a specific output result for a fake/test profile and action.
/// </summary>
/// <param name="actionId">The ID of the action to retrieve the result for.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <param name="resultType">Specifies which part of the result to return (Full, OnlyHeader, or OnlyBody).</param>
/// <returns>The requested output result or a part of it (header/body).</returns>
[HttpGet("fake/{actionId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Obsolete("Use the related procedure or view.")]
public async Task<IActionResult> Get([FromRoute] long actionId, CancellationToken cancel, ResultType resultType = ResultType.Full)
{
var res = (await mediator.Send(new ReadOutResQuery()
{
ProfileId = config.GetFakeProfileId(),
ActionId = actionId
}, cancel)).First();
return resultType switch
{
ResultType.OnlyBody => res.Body is null ? NotFound() : Ok(res.Body.JsonToDynamic()),
ResultType.OnlyHeader => res.Header is null ? NotFound() : Ok(res.Header.JsonToDynamic()),
_ => Ok(res),
};
}
/// <summary>
/// Deletes output results based on the provided criteria.
/// </summary>
/// <param name="command">The command containing the deletion criteria, such as ActionId or ProfileId.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An empty response indicating success.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromQuery] DeleteOutResCommand command, CancellationToken cancel)
{
await mediator.Send(command, cancel);
return NoContent();
}
/// <summary>
/// Deletes all output results for a fake/test profile.
/// </summary>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An empty response indicating success.</returns>
[HttpDelete("fake")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Delete(CancellationToken cancel)
{
await mediator.Send(new DeleteOutResCommand() { ProfileId = config.GetFakeProfileId() }, cancel);
return NoContent();
}
}

View File

@@ -0,0 +1,63 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Profile.Commands;
using ReC.Application.Profile.Queries;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ProfileController(IMediator mediator) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> Get([FromQuery] ReadProfileViewQuery query, CancellationToken cancel)
{
return Ok(await mediator.Send(query, cancel));
}
/// <summary>
/// Inserts a profile via the PROFILE insert procedure.
/// </summary>
/// <param name="procedure">InsertProfileProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The created profile identifier.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> Post([FromBody] InsertProfileProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, cancel: cancel);
return CreatedAtAction(nameof(Get), new { id }, id);
}
/// <summary>
/// Updates a profile via the PROFILE update procedure.
/// </summary>
/// <param name="id">Profile identifier to update.</param>
/// <param name="procedure">UpdateProfileProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateProfileProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
/// <summary>
/// Deletes profile records via the PROFILE delete procedure for the specified id range.
/// </summary>
/// <param name="procedure">DeleteProfileProcedure payload (Start, End, Force).</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromBody] DeleteProfileProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
}

View File

@@ -1,10 +1,10 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.API.Extensions;
using ReC.API.Models;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.RecActions.Commands;
using ReC.Application.RecActions.Queries;
using System.Text.Json;
namespace ReC.API.Controllers;
@@ -26,19 +26,6 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
return Accepted();
}
/// <summary>
/// Invokes a batch of RecActions for a fake/test profile.
/// </summary>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
[HttpPost("invoke/fake")]
[ProducesResponseType(StatusCodes.Status202Accepted)]
public async Task<IActionResult> Invoke(CancellationToken cancel)
{
await mediator.InvokeBatchRecActionView(config.GetFakeProfileId(), cancel);
return Accepted();
}
#region CRUD
/// <summary>
/// Gets all RecActions for a given profile.
@@ -50,20 +37,6 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get([FromQuery] ReadRecActionViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
/// <summary>
/// Gets all RecActions for a fake/test profile.
/// </summary>
/// <param name="cancel">A token to cancel the operation.</param>
/// <param name="invoked"></param>
/// <returns>A list of RecActions for the fake profile.</returns>
[HttpGet("fake")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get(CancellationToken cancel, [FromQuery] bool invoked = false) => Ok(await mediator.Send(new ReadRecActionViewQuery()
{
ProfileId = config.GetFakeProfileId(),
Invoked = invoked
}, cancel));
/// <summary>
/// Creates a new RecAction.
/// </summary>
@@ -72,83 +45,39 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
/// <returns>An HTTP 201 Created response.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[Obsolete("Use the related procedure.")]
public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel)
public async Task<IActionResult> Create([FromBody] InsertActionProcedure command, CancellationToken cancel)
{
await mediator.Send(command, cancel);
await mediator.ExecuteInsertProcedure(command, config["AddedWho"], cancel);
return CreatedAtAction(nameof(CreateAction), null);
return StatusCode(StatusCodes.Status201Created);
}
/// <summary>
/// Creates a new fake RecAction for testing purposes.
/// Updates a RecAction via the ACTION update procedure.
/// </summary>
/// <param name="id">RecAction identifier to update.</param>
/// <param name="procedure">UpdateActionProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <param name="request">The optional request body and header for the fake action.</param>
/// <param name="endpointUri">The target endpoint URI.</param>
/// <param name="endpointPath">The optional path to append to the endpoint URI.</param>
/// <param name="type">The HTTP method type (e.g., GET, POST).</param>
/// <returns>An HTTP 201 Created response.</returns>
[HttpPost("fake")]
[ProducesResponseType(StatusCodes.Status201Created)]
[Obsolete("Use the related procedure.")]
public async Task<IActionResult> CreateFakeAction(
CancellationToken cancel,
[FromBody] FakeRequest? request = null,
[FromQuery] string endpointUri = "https://jsonplaceholder.typicode.com/posts",
[FromQuery] string? endpointPath = "1",
[FromQuery] string type = "GET")
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Update([FromRoute] long id, [FromBody] UpdateActionProcedure procedure, CancellationToken cancel)
{
if (endpointPath is not null)
endpointUri = new Uri(new Uri(endpointUri.TrimEnd('/') + "/"), endpointPath.TrimStart('/')).ToString();
var bodyJson = request?.Body is not null ? JsonSerializer.Serialize(request.Body, options: new() { WriteIndented = false }) : null;
var headerJson = request?.Header is not null ? JsonSerializer.Serialize(request.Header, options: new() { WriteIndented = false }) : null;
await mediator.Send(new CreateRecActionCommand()
{
ProfileId = config.GetFakeProfileId(),
EndpointUri = endpointUri,
Type = type,
BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;",
HeaderQuery = headerJson is not null ? $@"SELECT '{headerJson}' AS REQUEST_HEADER;" : null,
Active = true,
EndpointAuthId = 4
}, cancel);
return CreatedAtAction(nameof(CreateFakeAction), null);
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
/// <summary>
/// Deletes all RecActions associated with a specific profile.
/// Deletes RecActions via the ACTION delete procedure for the specified id range.
/// </summary>
/// <param name="cmd"></param>
/// <param name="procedure">DeleteActionProcedure payload (Start, End, Force).</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[Obsolete("Use the related procedure.")]
public async Task<IActionResult> Delete([FromQuery] DeleteRecActionsCommand cmd, CancellationToken cancel)
public async Task<IActionResult> Delete([FromBody] DeleteActionProcedure procedure, CancellationToken cancel)
{
await mediator.Send(cmd, cancel);
return NoContent();
}
/// <summary>
/// Deletes all RecActions for a fake/test profile.
/// </summary>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
[HttpDelete("fake")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[Obsolete("Use the related procedure.")]
public async Task<IActionResult> Delete(CancellationToken cancel)
{
await mediator.Send(new DeleteRecActionsCommand()
{
ProfileId = config.GetFakeProfileId()
}, cancel);
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
#endregion CRUD

View File

@@ -0,0 +1,69 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.API.Extensions;
using ReC.API.Models;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Results.Commands;
using ReC.Application.Results.Queries;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ResultController(IMediator mediator) : ControllerBase
{
/// <summary>
/// Gets output results based on the provided query parameters.
/// </summary>
/// <param name="query">The query to filter output results.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>A list of output results matching the query.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get([FromQuery] ReadResultViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
/// <summary>
/// Inserts a RESULT record via the insert procedure.
/// </summary>
/// <param name="procedure">InsertResultProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The created RESULT identifier.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> Post([FromBody] InsertResultProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, cancel: cancel);
return CreatedAtAction(nameof(Get), new { actionId = procedure.ActionId }, new { id, procedure.ActionId });
}
/// <summary>
/// Updates a RESULT record via the update procedure.
/// </summary>
/// <param name="id">RESULT identifier to update.</param>
/// <param name="procedure">UpdateResultProcedure payload.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpPut("{id:long}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateResultProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
return NoContent();
}
/// <summary>
/// Deletes RESULT records via the delete procedure for the specified id range.
/// </summary>
/// <param name="procedure">DeleteResultProcedure payload (Start, End, Force).</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>No content on success.</returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromBody] DeleteResultProcedure procedure, CancellationToken cancel)
{
await mediator.ExecuteDeleteProcedure(procedure, cancel);
return NoContent();
}
}

View File

@@ -1,49 +0,0 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.API.Extensions;
using ReC.API.Models;
using ReC.Application.OutResults.Commands;
using ReC.Application.OutResults.Queries;
namespace ReC.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ResultViewController(IMediator mediator, IConfiguration config) : ControllerBase
{
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get([FromQuery] ReadResultViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
[HttpGet("fake")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadResultViewQuery()
{
ProfileId = config.GetFakeProfileId()
}, cancel));
[HttpGet("fake/{actionId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get([FromRoute] long actionId, CancellationToken cancel, ResultType resultType = ResultType.Full)
{
var res = (await mediator.Send(new ReadResultViewQuery()
{
ProfileId = config.GetFakeProfileId(),
ActionId = actionId
}, cancel)).First();
return resultType switch
{
ResultType.OnlyBody => res.Body is null ? NotFound() : Ok(res.Body.JsonToDynamic()),
ResultType.OnlyHeader => res.Header is null ? NotFound() : Ok(res.Header.JsonToDynamic()),
_ => Ok(res),
};
}
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateResultViewCommand command, CancellationToken cancel)
{
await mediator.Send(command, cancel);
return CreatedAtAction(nameof(Get), new { actionId = command.ActionId }, command);
}
}

View File

@@ -63,10 +63,17 @@ public class ExceptionHandlingMiddleware
switch (exception)
{
case BadRequestException badRequestEx:
if (badRequestEx.InnerException is not null)
{
logger.LogError(
badRequestEx.InnerException,
"BadRequestException inner exception captured.");
}
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
details = new()
{
Title = "Bad Request",
Title = "Bad Procedure",
Detail = badRequestEx.Message
};
break;
@@ -106,6 +113,57 @@ 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;
case UpdateObjectFailedException updateFailedEx:
logger.LogError(
updateFailedEx,
"Update operation failed during request processing. {procedure}",
JsonSerializer.Serialize(
updateFailedEx.Procedure,
options: new() { WriteIndented = true }
));
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
details = new()
{
Title = "Update Operation Failed",
Detail = updateFailedEx.Message
};
break;
case DeleteObjectFailedException deleteFailedEx:
logger.LogError(
deleteFailedEx,
"Delete operation failed during request processing. {procedure}",
JsonSerializer.Serialize(
deleteFailedEx.Procedure,
options: new() { WriteIndented = true }
));
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
details = new()
{
Title = "Delete Operation Failed",
Detail = deleteFailedEx.Message
};
break;
default:
logger.LogError(exception, "Unhandled exception occurred.");
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
@@ -120,4 +178,4 @@ public class ExceptionHandlingMiddleware
if (details is not null)
await context.Response.WriteAsJsonAsync(details);
}
}
}

View File

@@ -37,6 +37,7 @@ try
{
options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"];
options.ConfigureRecActions(config.GetSection("RecAction"));
options.ConfigureSqlException(config.GetSection("SqlException"));
});
builder.Services.AddRecInfrastructure(options =>

View File

@@ -10,10 +10,10 @@
<Product>ReC.API</Product>
<PackageIcon>Assets\icon.ico</PackageIcon>
<PackageTags>digital data rest-caller rec api</PackageTags>
<Version>1.0.3-beta</Version>
<AssemblyVersion>1.0.3.0</AssemblyVersion>
<FileVersion>1.0.3.0</FileVersion>
<InformationalVersion>1.0.3-beta</InformationalVersion>
<Version>2.0.0-beta</Version>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<InformationalVersion>2.0.0-beta</InformationalVersion>
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>

View File

@@ -8,6 +8,11 @@
"RecAction": {
"MaxConcurrentInvocations": 5
},
// Bad request SqlException numbers numbers can be updated at runtime; no restart required.
"SqlException": {
// https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlexception.number
"BadRequestSqlExceptionNumbers": [ 515, 547, 2601, 2627, 50000 ]
},
"AddedWho": "ReC.API",
"FakeProfileId": 2
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -1,5 +1,4 @@
using ReC.Domain.Entities;
using ReC.Domain.Views;
using ReC.Domain.Views;
namespace ReC.Application.Common.Dto;
@@ -8,16 +7,6 @@ public class DtoMappingProfile : AutoMapper.Profile
public DtoMappingProfile()
{
CreateMap<RecActionView, RecActionViewDto>();
CreateMap<OutRes, OutResDto>();
CreateMap<Connection, ConnectionDto>();
CreateMap<EndpointAuth, EndpointAuthDto>();
CreateMap<Endpoint, EndpointDto>();
CreateMap<EndpointParam, EndpointParamDto>();
CreateMap<Profile, ProfileDto>();
CreateMap<RecAction, RecActionDto>();
CreateMap<ResultView, ResultViewDto>();
CreateMap<ProfileView, ProfileViewDto>();
}

View File

@@ -3,7 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
[Table("TBREC_CFG_ENDPOINT_AUTH")]
public record EndpointAuthDto
{
public long? Id { get; set; }

View File

@@ -2,7 +2,6 @@
namespace ReC.Application.Common.Dto;
[Table("TBREC_CFG_PROFILE", Schema = "dbo")]
public record ProfileDto
{
public long Id { get; set; }

View File

@@ -3,7 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
[Table("TBREC_CFG_ACTION")]
public record RecActionDto
{
public long? Id { get; set; }

View File

@@ -20,7 +20,7 @@ public record RecActionViewDto
public long? EndpointAuthId { get; init; }
public EndpointAuthType? EndpointAuthType { get; init; }
public EndpointAuthType EndpointAuthType { get; init; } = EndpointAuthType.NoAuth;
public string? EndpointAuthTypeName { get; init; }

View File

@@ -0,0 +1,23 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.Common.Exceptions;
public class DeleteObjectFailedException : Exception
{
public DeleteObjectProcedure Procedure { get; }
public DeleteObjectFailedException(DeleteObjectProcedure procedure) : base()
{
Procedure = procedure;
}
public DeleteObjectFailedException(DeleteObjectProcedure procedure, string? message) : base(message)
{
Procedure = procedure;
}
public DeleteObjectFailedException(DeleteObjectProcedure procedure, string? message, Exception? innerException) : base(message, innerException)
{
Procedure = procedure;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,23 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.Common.Exceptions;
public class UpdateObjectFailedException : Exception
{
public UpdateObjectProcedure Procedure { get; }
public UpdateObjectFailedException(UpdateObjectProcedure procedure) : base()
{
Procedure = procedure;
}
public UpdateObjectFailedException(UpdateObjectProcedure procedure, string? message) : base(message)
{
Procedure = procedure;
}
public UpdateObjectFailedException(UpdateObjectProcedure procedure, string? message, Exception? innerException) : base(message, innerException)
{
Procedure = procedure;
}
}

View File

@@ -1,30 +1,24 @@
using Microsoft.EntityFrameworkCore;
using ReC.Domain.Entities;
using ReC.Domain.QueryOutput;
using ReC.Domain.Views;
namespace ReC.Application.Common.Interfaces;
public interface IRecDbContext
{
public DbSet<EndpointParam> EndpointParams { get; set; }
#region DbSets
public DbSet<RecActionView> RecActionViews { get; set; }
public DbSet<OutRes> OutRes { get; set; }
public DbSet<ProfileView> ProfileViews { get; set; }
public DbSet<ResultView> RecResultViews { get; set; }
public DbSet<HeaderQueryResult> HeaderQueryResults { get; set; }
public DbSet<BodyQueryResult> BodyQueryResults { get; set; }
public DbSet<Connection> Connections { get; set; }
public DbSet<Endpoint> Endpoints { get; set; }
public DbSet<EndpointAuth> EndpointAuths { get; set; }
public DbSet<Profile> Profiles { get; set; }
public DbSet<RecAction> RecActions { get; set; }
public DbSet<InsertObjectResult> RecResults { get; set; }
#endregion DbSets
public Task<int> SaveChangesAsync(CancellationToken cancel = default);
}

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Options;
public class SqlExceptionOptions
{
public HashSet<int> BadRequestSqlExceptionNumbers { get; set; } = [];
}

View File

@@ -0,0 +1,91 @@
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
namespace ReC.Application.Common.Procedures.DeleteProcedure;
public record DeleteObjectProcedure : IRequest<int>
{
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// </summary>
public string Entity { get; set; } = null!;
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// If true, delete even if dependent data exists
/// </summary>
public bool Force { get; set; }
}
public static class DeleteObjectProcedureExtensions
{
public static Task<int> ExecuteDeleteProcedure(this ISender sender, IDeleteProcedure procedure, CancellationToken cancel = default)
{
return sender.Send(procedure.ToObjectProcedure(), cancel);
}
public static Task<int> ExecuteDeleteProcedure(this ISender sender, string entity, long start, long end = 0, bool force = false, CancellationToken cancel = default)
{
return sender.Send(new DeleteObjectProcedure
{
Entity = entity,
Start = start,
End = end,
Force = force
}, cancel);
}
}
public class DeleteObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : IRequestHandler<DeleteObjectProcedure, int>
{
public async Task<int> Handle(DeleteObjectProcedure request, CancellationToken cancel)
{
var parameters = new[]
{
new SqlParameter("@pENTITY", request.Entity ?? (object)DBNull.Value),
new SqlParameter("@pSTART", request.Start.ToString()),
new SqlParameter("@pEND", request.End.ToString()),
new SqlParameter("@pFORCE", (object?)request.Force ?? DBNull.Value)
};
try
{
var result = await repo.ExecuteQueryRawAsync(
"DECLARE @RC SMALLINT = 0; " +
"EXEC @RC = [dbo].[PRREC_DELETE_OBJECT] " +
"@pENTITY, @pSTART, @pEND, @pFORCE; " +
"SELECT @RC;",
parameters,
cancel);
// The stored procedure returns 0 on success, error codes > 0 on failure
if (result > 0)
{
throw new DeleteObjectFailedException(request, $"DeleteObject stored procedure failed with error code: {result}");
}
return result;
}
catch (SqlException ex)
{
if (sqlExOpt.CurrentValue.BadRequestSqlExceptionNumbers.Contains(ex.Number))
throw new BadRequestException(ex.Message, ex);
else
throw;
}
}
}

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Procedures.DeleteProcedure;
public interface IDeleteProcedure
{
public DeleteObjectProcedure ToObjectProcedure();
}

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Procedures.InsertProcedure;
public interface IInsertProcedure
{
public InsertObjectProcedure ToObjectProcedure(string? addedWho = null);
}

View File

@@ -0,0 +1,150 @@
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
using ReC.Application.EndpointAuth.Commands;
using ReC.Application.EndpointParams.Commands;
using ReC.Application.Endpoints.Commands;
using ReC.Application.Profile.Commands;
using ReC.Application.RecActions.Commands;
using ReC.Application.Results.Commands;
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 = null)
{
AddedWho = addedWho ?? "ReC.API";
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 static class InsertObjectProcedureExtensions
{
public static Task<long> ExecuteInsertProcedure(this ISender sender, IInsertProcedure procedure, string? addedWho = null, CancellationToken cancel = default)
{
return sender.Send(procedure.ToObjectProcedure(addedWho ?? "Rec.API"), cancel);
}
}
public class InsertObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : 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?)(byte?)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
}
};
try
{
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);
}
catch (SqlException ex)
{
if (sqlExOpt.CurrentValue.BadRequestSqlExceptionNumbers.Contains(ex.Number))
throw new BadRequestException(ex.Message, ex);
else
throw;
}
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.");
}
}

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Procedures.UpdateProcedure;
public interface IUpdateProcedure
{
public UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null);
}

View File

@@ -0,0 +1,151 @@
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
using ReC.Application.EndpointAuth.Commands;
using ReC.Application.EndpointParams.Commands;
using ReC.Application.Endpoints.Commands;
using ReC.Application.Profile.Commands;
using ReC.Application.RecActions.Commands;
using ReC.Application.Results.Commands;
namespace ReC.Application.Common.Procedures.UpdateProcedure;
public record UpdateObjectProcedure : IRequest<int>
{
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// </summary>
public string Entity { get; set; } = null!;
/// <summary>
/// Target GUID to update (required)
/// </summary>
public long Id { get; set; }
internal string? ChangedWho { get; private set; }
public UpdateObjectProcedure ChangedBy(string? changedWho = null)
{
ChangedWho = changedWho ?? "ReC.API";
return this;
}
public UpdateActionProcedure Action { get; set; } = new();
public UpdateEndpointProcedure Endpoint { get; set; } = new();
public UpdateEndpointAuthProcedure EndpointAuth { get; set; } = new();
public UpdateProfileProcedure Profile { get; set; } = new();
public UpdateResultProcedure Result { get; set; } = new();
public UpdateEndpointParamsProcedure EndpointParams { get; set; } = new();
}
public static class UpdateObjectProcedureExtensions
{
public static Task<int> ExecuteUpdateProcedure(this ISender sender, IUpdateProcedure procedure, long id, string? changedWho = null, CancellationToken cancel = default)
{
return sender.Send(procedure.ToObjectProcedure(id, changedWho ?? "ReC.API"), cancel);
}
}
public class UpdateObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : IRequestHandler<UpdateObjectProcedure, int>
{
public async Task<int> Handle(UpdateObjectProcedure request, CancellationToken cancel)
{
var parameters = new[]
{
new SqlParameter("@pENTITY", request.Entity ?? (object)DBNull.Value),
new SqlParameter("@pGUID", (object?)request.Id ?? DBNull.Value),
new SqlParameter("@pCHANGED_WHO", (object?)request.ChangedWho ?? DBNull.Value),
new SqlParameter("@pCHANGED_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("@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("@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("@pPROFILE_FIRST_RUN", (object?)request.Profile.FirstRun ?? DBNull.Value),
new SqlParameter("@pPROFILE_LAST_RUN", (object?)request.Profile.LastRun ?? DBNull.Value),
new SqlParameter("@pPROFILE_LAST_RESULT", (object?)request.Profile.LastResult ?? 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)
};
try
{
var result = await repo.ExecuteQueryRawAsync(
"DECLARE @RC SMALLINT = 0; " +
"EXEC @RC = [dbo].[PRREC_UPDATE_OBJECT] " +
"@pENTITY, @pGUID, @pCHANGED_WHO, @pCHANGED_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, " +
"@pENDPOINT_PARAMS_ACTIVE, @pENDPOINT_PARAMS_DESCRIPTION, @pENDPOINT_PARAMS_GROUP_ID, @pENDPOINT_PARAMS_SEQUENCE, @pENDPOINT_PARAMS_KEY, @pENDPOINT_PARAMS_VALUE, " +
"@pPROFILE_ACTIVE, @pPROFILE_TYPE_ID, @pPROFILE_MANDANTOR, @pPROFILE_NAME, @pPROFILE_DESCRIPTION, @pPROFILE_LOG_LEVEL_ID, @pPROFILE_LANGUAGE_ID, @pPROFILE_FIRST_RUN, @pPROFILE_LAST_RUN, @pPROFILE_LAST_RESULT, " +
"@pRESULT_ACTION_ID, @pRESULT_STATUS_ID, @pRESULT_HEADER, @pRESULT_BODY; " +
"SELECT @RC;",
parameters,
cancel);
// The stored procedure returns 0 on success, error codes > 0 on failure
if (result > 0)
{
throw new UpdateObjectFailedException(request, $"UpdateObject stored procedure failed with error code: {result}");
}
return result;
}
catch (SqlException ex)
{
if (sqlExOpt.CurrentValue.BadRequestSqlExceptionNumbers.Contains(ex.Number))
throw new BadRequestException(ex.Message, ex);
else
throw;
}
}
}

View File

@@ -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.Action.ProfileId)
.NotNull()
.WithMessage("ACTION requires ActionProfileId (maps to @pACTION_PROFILE_ID).");
RuleFor(x => x.Action.EndpointId)
.NotNull()
.WithMessage("ACTION requires ActionEndpointId (maps to @pACTION_ENDPOINT_ID).");
});
// ENDPOINT validation
When(x => x.Entity == "ENDPOINT", () =>
{
RuleFor(x => x.Endpoint.Uri)
.NotEmpty()
.WithMessage("ENDPOINT requires EndpointUri (maps to @pENDPOINT_URI).")
.MaximumLength(2000);
});
// PROFILE validation
When(x => x.Entity == "PROFILE", () =>
{
RuleFor(x => x.Profile.Name)
.NotEmpty()
.WithMessage("PROFILE requires ProfileName (maps to @pPROFILE_NAME).")
.MaximumLength(50);
RuleFor(x => x.Profile.Mandantor)
.MaximumLength(50)
.When(x => x.Profile.Mandantor != null);
RuleFor(x => x.Profile.Description)
.MaximumLength(250)
.When(x => x.Profile.Description != null);
});
// RESULT validation
When(x => x.Entity == "RESULT", () =>
{
RuleFor(x => x.Result.ActionId)
.NotNull()
.WithMessage("RESULT requires ResultActionId (maps to @pRESULT_ACTION_ID).");
RuleFor(x => x.Result.StatusId)
.NotNull()
.WithMessage("RESULT requires ResultStatusId (maps to @pRESULT_STATUS_ID).");
});
// ENDPOINT_PARAMS validation
When(x => x.Entity == "ENDPOINT_PARAMS", () =>
{
RuleFor(x => x.EndpointParams.GroupId)
.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.Endpoint.Description)
.MaximumLength(250)
.When(x => x.Endpoint.Description != null);
RuleFor(x => x.EndpointAuth.Description)
.MaximumLength(250)
.When(x => x.EndpointAuth.Description != null);
}
}

View File

@@ -2,9 +2,11 @@
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using ReC.Application.Common.Behaviors;
using ReC.Application.Common.Constants;
using ReC.Application.Common.Options;
using ReC.Application.Common.Procedures;
using System.Reflection;
namespace ReC.Application;
@@ -116,5 +118,23 @@ public static class DependencyInjection
return this;
}
#endregion ConfigureRecActions
#region ConfigureSqlException
public ConfigurationOptions ConfigureSqlException(Action<SqlExceptionOptions> configure)
{
_configActions.Enqueue(services => services.Configure(configure));
return this;
}
public ConfigurationOptions ConfigureSqlException(IConfiguration configuration)
{
_configActions.Enqueue(services =>
{
services.Configure<SqlExceptionOptions>(configuration);
});
return this;
}
#endregion ConfigureSqlException
}
}

View File

@@ -0,0 +1,32 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.EndpointAuth.Commands;
public record DeleteEndpointAuthProcedure : IDeleteProcedure
{
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// If true, delete even if dependent ACTION data exists
/// </summary>
public bool Force { get; set; }
public DeleteObjectProcedure ToObjectProcedure()
{
return new DeleteObjectProcedure
{
Entity = "ENDPOINT_AUTH",
Start = Start,
End = End,
Force = Force
};
}
}

View File

@@ -0,0 +1,27 @@
using ReC.Application.Common.Procedures.InsertProcedure;
namespace ReC.Application.EndpointAuth.Commands;
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 = null)
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT_AUTH",
EndpointAuth = this
}.AddedBy(addedWho);
}
}

View File

@@ -0,0 +1,28 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.EndpointAuth.Commands;
public record UpdateEndpointAuthProcedure : IUpdateProcedure
{
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 UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null)
{
return new UpdateObjectProcedure
{
Entity = "ENDPOINT_AUTH",
Id = id,
EndpointAuth = this
}.ChangedBy(changedWho);
}
}

View File

@@ -0,0 +1,32 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.EndpointParams.Commands;
public record DeleteEndpointParamsProcedure : IDeleteProcedure
{
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// If true, delete even if dependent ACTION data exists
/// </summary>
public bool Force { get; set; }
public DeleteObjectProcedure ToObjectProcedure()
{
return new DeleteObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
Start = Start,
End = End,
Force = Force
};
}
}

View File

@@ -0,0 +1,22 @@
using ReC.Application.Common.Procedures.InsertProcedure;
namespace ReC.Application.EndpointParams.Commands;
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 = null)
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
EndpointParams = this
}.AddedBy(addedWho);
}
}

View File

@@ -0,0 +1,23 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.EndpointParams.Commands;
public record UpdateEndpointParamsProcedure : IUpdateProcedure
{
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 UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null)
{
return new UpdateObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
Id = id,
EndpointParams = this
}.ChangedBy(changedWho);
}
}

View File

@@ -0,0 +1,32 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.Endpoints.Commands;
public record DeleteEndpointProcedure : IDeleteProcedure
{
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// If true, delete even if dependent ACTION data exists
/// </summary>
public bool Force { get; set; }
public DeleteObjectProcedure ToObjectProcedure()
{
return new DeleteObjectProcedure
{
Entity = "ENDPOINT",
Start = Start,
End = End,
Force = Force
};
}
}

View File

@@ -0,0 +1,19 @@
using ReC.Application.Common.Procedures.InsertProcedure;
namespace ReC.Application.Endpoints.Commands;
public record InsertEndpointProcedure : IInsertProcedure
{
public bool? Active { get; set; }
public string? Description { get; set; }
public string? Uri { get; set; }
public InsertObjectProcedure ToObjectProcedure(string? addedWho = null)
{
return new InsertObjectProcedure
{
Entity = "ENDPOINT",
Endpoint = this
}.AddedBy(addedWho);
}
}

View File

@@ -1,29 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Application.Common.Dto;
using ReC.Domain.Entities;
namespace ReC.Application.Endpoints.Commands;
[Obsolete("Use the related procedure or view.")]
public class ObtainEndpointCommand : IRequest<EndpointDto>
{
public string Uri { get; init; } = null!;
}
[Obsolete("Use the related procedure or view.")]
public class ObtainEndpointCommandHandler(IRepository<Endpoint> repo, IMapper mapper) : IRequestHandler<ObtainEndpointCommand, EndpointDto>
{
public async Task<EndpointDto> Handle(ObtainEndpointCommand request, CancellationToken cancel)
{
var endpoint = await repo.Where(e => e.Uri == request.Uri).FirstOrDefaultAsync(cancel);
if (endpoint is not null)
return mapper.Map<EndpointDto>(endpoint);
endpoint = await repo.CreateAsync(request, cancel);
return mapper.Map<EndpointDto>(endpoint);
}
}

View File

@@ -0,0 +1,20 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.Endpoints.Commands;
public record UpdateEndpointProcedure : IUpdateProcedure
{
public bool? Active { get; set; }
public string? Description { get; set; }
public string? Uri { get; set; }
public UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null)
{
return new UpdateObjectProcedure
{
Entity = "ENDPOINT",
Id = id,
Endpoint = this
}.ChangedBy(changedWho);
}
}

View File

@@ -1,17 +0,0 @@
using ReC.Application.Endpoints.Commands;
using ReC.Application.Common.Dto;
namespace ReC.Application.Endpoints;
// TODO: update to inject AddedWho from the current host/user contex
public class MappingProfile : AutoMapper.Profile
{
[Obsolete("Use the related procedure or view.")]
public MappingProfile()
{
CreateMap<ObtainEndpointCommand, EndpointDto>()
.ForMember(e => e.Active, exp => exp.MapFrom(cmd => true))
.ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow))
.ForMember(e => e.AddedWho, exp => exp.MapFrom(cmd => "ReC.API"));
}
}

View File

@@ -1,30 +0,0 @@
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using ReC.Domain.Entities;
namespace ReC.Application.OutResults.Commands;
[Obsolete("Use the related procedure or view.")]
public class CreateOutResCommand : IRequest
{
public required long ActionId { get; set; }
public short? Status { get; set; }
public string? Message { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public string? AddedWho { get; set; }
}
[Obsolete("Use the related procedure or view.")]
public class CreateOutResCommandHandler(IRepository<OutRes> repo) : IRequestHandler<CreateOutResCommand>
{
public Task Handle(CreateOutResCommand request, CancellationToken cancel)
{
return repo.CreateAsync(request, cancel);
}
}

View File

@@ -1,26 +0,0 @@
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using ReC.Application.Common.Interfaces;
using ReC.Domain.Views;
using System.Text.Json.Serialization;
namespace ReC.Application.OutResults.Commands;
public class CreateResultViewCommand : IAuthScoped, IRequest
{
public required long ActionId { get; set; }
public required short StatusCode { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
[JsonIgnore]
public AuthScope Scope { get; } = new();
}
public class CreateResultViewCommandHandler(IRepository<ResultView> repo) : IRequestHandler<CreateResultViewCommand>
{
public Task Handle(CreateResultViewCommand request, CancellationToken cancel) => repo.CreateAsync(request, cancel);
}

View File

@@ -1,48 +0,0 @@
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using ReC.Domain.Entities;
namespace ReC.Application.OutResults.Commands;
/// <summary>
/// Represents the command to delete output results based on specified criteria.
/// </summary>
/// <remarks>
/// Deletion can be performed by providing either an <see cref="ActionId"/> or a <see cref="ProfileId"/>.
/// At least one of these properties must be set for the operation to proceed.
/// </remarks>
[Obsolete("Use the related procedure or view.")]
public record DeleteOutResCommand : IRequest
{
/// <summary>
/// Gets the unique identifier for the action whose output results should be deleted.
/// </summary>
public long? ActionId { get; init; }
/// <summary>
/// Gets the unique identifier for the profile whose associated action's output results should be deleted.
/// </summary>
public long? ProfileId { get; init; }
}
/// <summary>
/// Handles the execution of the <see cref="DeleteOutResCommand"/>.
/// </summary>
[Obsolete("Use the related procedure or view.")]
public class DeleteOutResCommandHandler(IRepository<OutRes> repo) : IRequestHandler<DeleteOutResCommand>
{
/// <summary>
/// Processes the delete command by removing matching <see cref="OutRes"/> entities from the repository.
/// </summary>
/// <param name="request">The command containing the deletion criteria.</param>
/// <param name="cancel">A cancellation token that can be used to cancel the work.</param>
/// <returns>A task that represents the asynchronous delete operation.</returns>
/// <remarks>
/// The handler deletes records where <c>OutRes.ActionId</c> matches <see cref="DeleteOutResCommand.ActionId"/>
/// or where the associated <c>Action.ProfileId</c> matches <see cref="DeleteOutResCommand.ProfileId"/>.
/// </remarks>
public Task Handle(DeleteOutResCommand request, CancellationToken cancel)
{
return repo.DeleteAsync(x => x.ActionId == request.ActionId || x.Action!.ProfileId == request.ProfileId, cancel);
}
}

View File

@@ -1,15 +0,0 @@
using FluentValidation;
namespace ReC.Application.OutResults.Commands;
[Obsolete("Use the related procedure or view.")]
public class DeleteOutResCommandValidator : AbstractValidator<DeleteOutResCommand>
{
public DeleteOutResCommandValidator()
{
RuleFor(x => x)
.Must(x => x.ActionId.HasValue || x.ProfileId.HasValue)
.WithMessage("At least one of ActionId or ProfileId must be provided.")
.WithName("Identifier");
}
}

View File

@@ -1,20 +0,0 @@
using ReC.Application.OutResults.Commands;
using ReC.Domain.Entities;
using ReC.Domain.Views;
namespace ReC.Application.OutResults;
// TODO: update to inject AddedWho from the current host/user contex
public class MappingProfiles : AutoMapper.Profile
{
[Obsolete("Use the related procedure or view.")]
public MappingProfiles()
{
CreateMap<CreateOutResCommand, OutRes>()
.ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow))
.ForMember(e => e.AddedWho, exp => exp.MapFrom(cmd => "ReC.API"));
CreateMap<CreateResultViewCommand, ResultView>()
.ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow));
}
}

View File

@@ -1,39 +0,0 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Application.Common.Dto;
using ReC.Domain.Entities;
namespace ReC.Application.OutResults.Queries;
[Obsolete("Use the related procedure or view.")]
public record ReadOutResQuery : IRequest<IEnumerable<OutResDto>>
{
public long? ProfileId { get; init; }
public long? ActionId { get; init; }
}
[Obsolete("Use the related procedure or view.")]
public class ReadOutResHandler(IRepository<OutRes> repo, IMapper mapper) : IRequestHandler<ReadOutResQuery, IEnumerable<OutResDto>>
{
public async Task<IEnumerable<OutResDto>> Handle(ReadOutResQuery request, CancellationToken cancel)
{
var q = repo.Query;
if(request.ActionId is long actionId)
q = q.Where(res => res.ActionId == actionId);
if(request.ProfileId is long profileId)
q = q.Where(res => res.Action!.ProfileId == profileId);
var resList = await q.ToListAsync(cancel);
if (resList.Count == 0)
throw new NotFoundException();
return mapper.Map<IEnumerable<OutResDto>>(resList);
}
}

View File

@@ -1,15 +0,0 @@
using FluentValidation;
namespace ReC.Application.OutResults.Queries;
[Obsolete("Use the related procedure or view.")]
public class ReadOutResQueryValidator : AbstractValidator<ReadOutResQuery>
{
public ReadOutResQueryValidator()
{
RuleFor(x => x)
.Must(x => x.ActionId.HasValue || x.ProfileId.HasValue)
.WithMessage("At least one of ActionId or ProfileId must be provided.")
.WithName("Identifier");
}
}

View File

@@ -0,0 +1,32 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.Profile.Commands;
public record DeleteProfileProcedure : IDeleteProcedure
{
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// If true, delete even if dependent ACTION data exists
/// </summary>
public bool Force { get; set; }
public DeleteObjectProcedure ToObjectProcedure()
{
return new DeleteObjectProcedure
{
Entity = "PROFILE",
Start = Start,
End = End,
Force = Force
};
}
}

View File

@@ -0,0 +1,23 @@
using ReC.Application.Common.Procedures.InsertProcedure;
namespace ReC.Application.Profile.Commands;
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 = null)
{
return new InsertObjectProcedure
{
Entity = "PROFILE",
Profile = this
}.AddedBy(addedWho);
}
}

View File

@@ -0,0 +1,27 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.Profile.Commands;
public record UpdateProfileProcedure : IUpdateProcedure
{
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 DateTime? FirstRun { get; set; }
public DateTime? LastRun { get; set; }
public string? LastResult { get; set; }
public UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null)
{
return new UpdateObjectProcedure
{
Entity = "PROFILE",
Id = id,
Profile = this
}.ChangedBy(changedWho);
}
}

View File

@@ -0,0 +1,36 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Application.Common.Dto;
using ReC.Domain.Views;
namespace ReC.Application.Profile.Queries;
public record ReadProfileViewQuery : IRequest<IEnumerable<ProfileViewDto>>
{
public long? Id { get; init; } = null;
public bool IncludeActions { get; init; } = true;
}
public class ReadProfileViewQueryHandler(IRepository<ProfileView> repo, IMapper mapper)
: IRequestHandler<ReadProfileViewQuery, IEnumerable<ProfileViewDto>>
{
public async Task<IEnumerable<ProfileViewDto>> Handle(ReadProfileViewQuery request, CancellationToken cancel)
{
var query = request.IncludeActions
? repo.Query.Include(p => p.Actions)
: repo.Query;
if (request.Id is long id)
query = query.Where(p => p.Id == id);
var profiles = await query.ToListAsync(cancel);
return profiles is null || profiles.Count == 0
? throw new NotFoundException($"Profile {request.Id} not found.")
: mapper.Map<IEnumerable<ProfileViewDto>>(profiles);
}
}

View File

@@ -10,7 +10,7 @@
<PackageReference Include="AutoMapper" Version="15.1.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.6.0" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.1" />
<PackageReference Include="FluentValidation" Version="12.1.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.0" />
<PackageReference Include="MediatR" Version="13.1.0" />

View File

@@ -1,47 +0,0 @@
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using ReC.Domain.Entities;
using ReC.Application.Endpoints.Commands;
namespace ReC.Application.RecActions.Commands;
[Obsolete("Use the related procedure or view.")]
public record CreateRecActionCommand : IRequest
{
public long ProfileId { get; init; }
public bool Active { get; init; } = true;
public long? EndpointId { get; set; }
public string? EndpointUri { get; init; }
public string Type { get; init; } = null!;
public string? HeaderQuery { get; init; }
public string BodyQuery { get; init; } = null!;
public byte Sequence { get; set; } = 1;
public long? EndpointAuthId { get; set; }
}
[Obsolete("Use the related procedure or view.")]
public class CreateRecActionCommandHandler(ISender sender, IRepository<RecAction> repo) : IRequestHandler<CreateRecActionCommand>
{
public async Task Handle(CreateRecActionCommand request, CancellationToken cancel)
{
if(request.EndpointId is null)
if(request.EndpointUri is string endpointUri)
{
var endpoint = await sender.Send(new ObtainEndpointCommand { Uri = endpointUri }, cancel);
request.EndpointId = endpoint.Id;
}
else
throw new BadRequestException("Either EndpointId or EndpointUri must be provided.");
await repo.CreateAsync(request, cancel);
}
}

View File

@@ -0,0 +1,32 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.RecActions.Commands;
public record DeleteActionProcedure : IDeleteProcedure
{
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// If true, delete even if dependent RESULT data exists
/// </summary>
public bool Force { get; set; }
public DeleteObjectProcedure ToObjectProcedure()
{
return new DeleteObjectProcedure
{
Entity = "ACTION",
Start = Start,
End = End,
Force = Force
};
}
}

View File

@@ -1,26 +0,0 @@
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Domain.Entities;
namespace ReC.Application.RecActions.Commands;
[Obsolete("Use the related procedure or view.")]
public class DeleteRecActionsCommand : IRequest
{
public required long ProfileId { get; init; }
}
[Obsolete("Use the related procedure or view.")]
public class DeleteRecActionsCommandHandler(IRepository<RecAction> repo) : IRequestHandler<DeleteRecActionsCommand>
{
public async Task Handle(DeleteRecActionsCommand request, CancellationToken cancel)
{
// TODO: update DeleteAsync (in Core) to return number of deleted records
if (!await repo.Where(act => act.ProfileId == request.ProfileId).AnyAsync(cancel))
throw new NotFoundException();
await repo.DeleteAsync(act => act.ProfileId == request.ProfileId, cancel);
}
}

View File

@@ -0,0 +1,30 @@
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Domain.Constants;
namespace ReC.Application.RecActions.Commands;
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 RestType? 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 = null)
{
return new InsertObjectProcedure
{
Entity = "ACTION",
Action = this
}.AddedBy(addedWho);
}
}

View File

@@ -4,7 +4,8 @@ using ReC.Application.Common;
using ReC.Application.Common.Constants;
using ReC.Application.Common.Dto;
using ReC.Application.Common.Exceptions;
using ReC.Application.OutResults.Commands;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Results.Commands;
using ReC.Domain.Constants;
using System.Net;
using System.Net.Http.Headers;
@@ -133,14 +134,13 @@ public class InvokeRecActionViewCommandHandler(
var statusCode = (short)response.StatusCode;
await sender.Send(new CreateOutResCommand
await sender.ExecuteInsertProcedure(new InsertResultProcedure()
{
Status = statusCode,
StatusId = statusCode,
ActionId = action.Id,
Header = JsonSerializer.Serialize(resHeaders, options: new() { WriteIndented = false }),
Body = resBody,
AddedWho = config?["AddedWho"]
}, cancel);
Body = resBody
}, config?["AddedWho"], cancel);
return response.IsSuccessStatusCode;
}

View File

@@ -0,0 +1,30 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.RecActions.Commands;
public record UpdateActionProcedure : IUpdateProcedure
{
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 UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null)
{
return new UpdateObjectProcedure
{
Entity = "ACTION",
Id = id,
Action = this
}.ChangedBy(changedWho);
}
}

View File

@@ -1,17 +0,0 @@
using ReC.Application.Common.Dto;
using ReC.Application.RecActions.Commands;
namespace ReC.Application.RecActions;
// TODO: update to inject AddedWho from the current host/user contex
public class MappingProfile : AutoMapper.Profile
{
[Obsolete("Use the related procedure or view.")]
public MappingProfile()
{
CreateMap<CreateRecActionCommand, RecActionDto>()
.ForMember(e => e.Active, exp => exp.MapFrom(cmd => true))
.ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow))
.ForMember(e => e.AddedWho, exp => exp.MapFrom(cmd => "ReC.API"));
}
}

View File

@@ -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}.");

View File

@@ -0,0 +1,32 @@
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.Results.Commands;
public record DeleteResultProcedure : IDeleteProcedure
{
/// <summary>
/// Start GUID/ID (inclusive)
/// </summary>
public long Start { get; set; }
/// <summary>
/// End GUID/ID (inclusive). If 0, will be set to Start value.
/// </summary>
public long End { get; set; }
/// <summary>
/// Force parameter (not used for RESULT entity as it has no dependencies)
/// </summary>
public bool Force { get; set; }
public DeleteObjectProcedure ToObjectProcedure()
{
return new DeleteObjectProcedure
{
Entity = "RESULT",
Start = Start,
End = End,
Force = Force
};
}
}

View File

@@ -0,0 +1,20 @@
using ReC.Application.Common.Procedures.InsertProcedure;
namespace ReC.Application.Results.Commands;
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 = null)
{
return new InsertObjectProcedure
{
Entity = "RESULT",
Result = this
}.AddedBy(addedWho ?? "Rec.API");
}
}

View File

@@ -0,0 +1,21 @@
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.Results.Commands;
public record UpdateResultProcedure : IUpdateProcedure
{
public long? ActionId { get; set; }
public short? StatusId { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public UpdateObjectProcedure ToObjectProcedure(long id, string? changedWho = null)
{
return new UpdateObjectProcedure
{
Entity = "RESULT",
Id = id,
Result = this
}.ChangedBy(changedWho);
}
}

View File

@@ -7,7 +7,7 @@ using ReC.Application.Common.Dto;
using ReC.Domain.Views;
using System.Text.Json;
namespace ReC.Application.OutResults.Queries;
namespace ReC.Application.Results.Queries;
public record ReadResultViewQuery : IRequest<IEnumerable<ResultViewDto>>
{

View File

@@ -0,0 +1,71 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides shared CRUD operations for API resources.
/// </summary>
public abstract class BaseCrudApi
{
/// <summary>
/// The HTTP client used to send requests.
/// </summary>
protected readonly HttpClient Http;
/// <summary>
/// The base resource path for the API endpoint.
/// </summary>
protected readonly string ResourcePath;
/// <summary>
/// Initializes a new instance of the <see cref="BaseCrudApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="resourcePath">The base resource path for the API endpoint.</param>
protected BaseCrudApi(HttpClient http, string resourcePath)
{
Http = http ?? throw new ArgumentNullException(nameof(http));
ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
}
/// <summary>
/// Creates a resource.
/// </summary>
/// <typeparam name="T">The payload type.</typeparam>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> CreateAsync<T>(T payload, CancellationToken cancel = default)
=> Http.PostAsync(ResourcePath, ReCClientHelpers.ToJsonContent(payload), cancel);
/// <summary>
/// Updates a resource by identifier.
/// </summary>
/// <typeparam name="T">The payload type.</typeparam>
/// <param name="id">The resource identifier.</param>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T payload, CancellationToken cancel = default)
=> Http.PutAsync($"{ResourcePath}/{id}", ReCClientHelpers.ToJsonContent(payload), cancel);
/// <summary>
/// Deletes resources with identifiers supplied in the payload.
/// </summary>
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> DeleteAsync<T>(T payload, CancellationToken cancel = default)
{
var request = new HttpRequestMessage(HttpMethod.Delete, ResourcePath)
{
Content = ReCClientHelpers.ToJsonContent(payload)
};
return Http.SendAsync(request, cancel);
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to common object endpoints.
/// </summary>
public class CommonApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="CommonApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public CommonApi(HttpClient http) : base(http, "api/Common")
{
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to endpoint authentication endpoints.
/// </summary>
public class EndpointAuthApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="EndpointAuthApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public EndpointAuthApi(HttpClient http) : base(http, "api/EndpointAuth")
{
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to endpoint parameter endpoints.
/// </summary>
public class EndpointParamsApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="EndpointParamsApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public EndpointParamsApi(HttpClient http) : base(http, "api/EndpointParams")
{
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to endpoint definitions.
/// </summary>
public class EndpointsApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="EndpointsApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public EndpointsApi(HttpClient http) : base(http, "api/Endpoints")
{
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to profile endpoints.
/// </summary>
public class ProfileApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="ProfileApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public ProfileApi(HttpClient http) : base(http, "api/Profile")
{
}
/// <summary>
/// Retrieves a profile by identifier.
/// </summary>
/// <param name="id">The profile identifier.</param>
/// <param name="includeActions">Whether to include related actions.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> GetAsync(long id, bool includeActions = false, CancellationToken cancel = default)
{
var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions));
return Http.GetAsync($"{ResourcePath}{query}", cancel);
}
}
}

View File

@@ -0,0 +1,45 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to RecAction endpoints.
/// </summary>
public class RecActionApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="RecActionApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public RecActionApi(HttpClient http) : base(http, "api/RecAction")
{
}
/// <summary>
/// Invokes a ReC action for the specified profile.
/// </summary>
/// <param name="profileId">The profile identifier.</param>
/// <param name="cancellationToken">A token to cancel the operation.</param>
/// <returns><see langword="true"/> if the request succeeds; otherwise, <see langword="false"/>.</returns>
public async Task<bool> InvokeAsync(int profileId, CancellationToken cancellationToken = default)
{
var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content: null, cancellationToken);
return resp.IsSuccessStatusCode;
}
/// <summary>
/// Retrieves Rec actions.
/// </summary>
/// <param name="profileId">Optional profile filter.</param>
/// <param name="invoked">Optional invoked filter.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
{
var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked));
return Http.GetAsync($"{ResourcePath}{query}", cancel);
}
}
}

View File

@@ -0,0 +1,34 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to output result endpoints.
/// </summary>
public class ResultApi : BaseCrudApi
{
/// <summary>
/// Initializes a new instance of the <see cref="ResultApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public ResultApi(HttpClient http) : base(http, "api/Result")
{
}
/// <summary>
/// Retrieves results with optional filters.
/// </summary>
/// <param name="id">Optional result identifier.</param>
/// <param name="actionId">Optional action identifier.</param>
/// <param name="profileId">Optional profile identifier.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> GetAsync(long? id = null, long? actionId = null, long? profileId = null, CancellationToken cancel = default)
{
var query = ReCClientHelpers.BuildQuery(("Id", id), ("ActionId", actionId), ("ProfileId", profileId));
return Http.GetAsync($"{ResourcePath}{query}", cancel);
}
}
}

View File

@@ -30,8 +30,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@@ -1,11 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
#if NETFRAMEWORK
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
#endif
using ReC.Client.Api;
namespace ReC.Client
{
@@ -21,6 +17,41 @@ namespace ReC.Client
/// </summary>
public static readonly string ClientName = Guid.NewGuid().ToString();
/// <summary>
/// Provides access to RecAction endpoints.
/// </summary>
public RecActionApi RecActions { get; }
/// <summary>
/// Provides access to Result endpoints.
/// </summary>
public ResultApi Results { get; }
/// <summary>
/// Provides access to Profile endpoints.
/// </summary>
public ProfileApi Profiles { get; }
/// <summary>
/// Provides access to EndpointAuth endpoints.
/// </summary>
public EndpointAuthApi EndpointAuth { get; }
/// <summary>
/// Provides access to EndpointParams endpoints.
/// </summary>
public EndpointParamsApi EndpointParams { get; }
/// <summary>
/// Provides access to Endpoints endpoints.
/// </summary>
public EndpointsApi Endpoints { get; }
/// <summary>
/// Provides access to Common endpoints.
/// </summary>
public CommonApi Common { get; }
/// <summary>
/// Initializes a new instance of the <see cref="ReCClient"/> class.
/// </summary>
@@ -28,37 +59,13 @@ namespace ReC.Client
public ReCClient(IHttpClientFactory httpClientFactory)
{
_http = httpClientFactory.CreateClient(ClientName);
}
/// <summary>
/// Asynchronously invokes a ReC action for a specific profile.
/// </summary>
/// <remarks>
/// This method sends a POST request to the <c>api/RecAction/invoke/{profileId}</c> endpoint.
/// </remarks>
/// <param name="profileId">The ID of the profile to invoke the action for.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous operation. The task result is <see langword="true"/> if the request was successful; otherwise, <see langword="false"/>.</returns>
public async Task<bool> InvokeRecActionAsync(int profileId, CancellationToken cancellationToken = default)
{
var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken);
return resp.IsSuccessStatusCode;
}
/// <summary>
/// Synchronously invokes a ReC action for a specific profile.
/// </summary>
/// <remarks>
/// This method sends a POST request to the <c>api/RecAction/invoke/{profileId}</c> endpoint.
/// This is the synchronous version of <see cref="InvokeRecActionAsync(int, CancellationToken)"/>.
/// </remarks>
/// <param name="profileId">The ID of the profile to invoke the action for.</param>
/// <returns><see langword="true"/> if the request was successful; otherwise, <see langword="false"/>.</returns>
[Obsolete("Use InvokeRecActionAsync instead to avoid potential deadlocks and improve performance.")]
public bool InvokeRecAction(int profileId)
{
var resp = _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null).GetAwaiter().GetResult();
return resp.IsSuccessStatusCode;
RecActions = new RecActionApi(_http);
Results = new ResultApi(_http);
Profiles = new ProfileApi(_http);
EndpointAuth = new EndpointAuthApi(_http);
EndpointParams = new EndpointParamsApi(_http);
Endpoints = new EndpointsApi(_http);
Common = new CommonApi(_http);
}
#region Static
@@ -121,4 +128,23 @@ namespace ReC.Client
}
#endregion
}
/// <summary>
/// Specifies which part of the result to return for result view endpoints.
/// </summary>
public enum ResultType
{
/// <summary>
/// Returns both header and body.
/// </summary>
Full,
/// <summary>
/// Returns only the header portion of the result.
/// </summary>
OnlyHeader,
/// <summary>
/// Returns only the body portion of the result.
/// </summary>
OnlyBody
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Globalization;
using System.Linq;
using System.Net.Http.Json;
#if NETFRAMEWORK
using System.Net.Http;
#endif
namespace ReC.Client
{
/// <summary>
/// Provides shared helpers for composing requests.
/// </summary>
internal static class ReCClientHelpers
{
#if NETFRAMEWORK
/// <summary>
/// Builds a query string from the provided key/value pairs, skipping null values.
/// </summary>
/// <param name="parameters">The key/value pairs to include in the query string.</param>
/// <returns>A query string beginning with '?', or an empty string if no values are provided.</returns>
public static string BuildQuery(params (string Key, object Value)[] parameters)
#else
/// <summary>
/// Builds a query string from the provided key/value pairs, skipping null values.
/// </summary>
/// <param name="parameters">The key/value pairs to include in the query string.</param>
/// <returns>A query string beginning with '?', or an empty string if no values are provided.</returns>
public static string BuildQuery(params (string Key, object? Value)[] parameters)
#endif
{
var parts = parameters
.Where(p => p.Value != null)
.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(Convert.ToString(p.Value, CultureInfo.InvariantCulture) ?? string.Empty)}");
var query = string.Join("&", parts);
return string.IsNullOrWhiteSpace(query) ? string.Empty : $"?{query}";
}
/// <summary>
/// Creates a JSON content payload from the provided object.
/// </summary>
/// <typeparam name="T">The type of the payload.</typeparam>
/// <param name="payload">The payload to serialize.</param>
/// <returns>A <see cref="JsonContent"/> instance ready for HTTP requests.</returns>
public static JsonContent ToJsonContent<T>(T payload) => JsonContent.Create(payload);
}
}

View File

@@ -0,0 +1,26 @@
#if NETFRAMEWORK
using System.Threading.Tasks;
#endif
namespace ReC.Client
{
/// <summary>
/// Provides synchronous wrappers for Task-based operations.
/// </summary>
public static class TaskSyncExtensions
{
/// <summary>
/// Blocks until the task completes and propagates any exception.
/// </summary>
/// <param name="task">The task to wait for.</param>
public static void Sync(this Task task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
/// <summary>
/// Blocks until the task completes and returns its result, propagating any exception.
/// </summary>
/// <typeparam name="TResult">The type of the task result.</typeparam>
/// <param name="task">The task to wait for.</param>
/// <returns>The result of the completed task.</returns>
public static TResult Sync<TResult>(this Task<TResult> task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
}
}

View File

@@ -1,35 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBDD_CONNECTION")]
public class Connection
{
public short? Id { get; set; }
public string? Bezeichnung { get; set; }
public string? SqlProvider { get; set; }
public string? Server { get; set; }
public string? Datenbank { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public string? Bemerkung { get; set; }
public bool? Aktiv { get; set; }
public string? ErstelltWer { get; set; }
public DateTime? ErstelltWann { get; set; }
public string? GeandertWer { get; set; }
public DateTime? GeaendertWann { get; set; }
public bool? SysConnection { get; set; }
}

View File

@@ -1,23 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ENDPOINT")]
public class Endpoint
{
public long Id { get; set; }
public bool? Active { get; set; }
public string? Description { get; set; }
public string? Uri { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,40 +0,0 @@
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ENDPOINT_AUTH")]
public class EndpointAuth
{
public long? Id { get; set; }
public bool? Active { get; set; }
public string? Description { get; set; }
public EndpointAuthType? Type { get; set; }
public string? ApiKey { get; set; }
public string? ApiValue { get; set; }
public ApiKeyLocation? ApiKeyAddTo { 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 string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,34 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
/// <summary>
/// Represents the TBREC_CFG_ENDPOINT_PARAMS table.
/// All properties are nullable to provide flexibility on the database side,
/// preventing breaking changes if columns are altered to be nullable in production.
/// </summary>
[Table("TBREC_CFG_ENDPOINT_PARAMS", Schema = "dbo")]
public class EndpointParam
{
public long? Id { get; set; }
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 string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,27 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_OUT_RESULT", Schema = "dbo")]
public class OutRes
{
public long? Id { get; set; }
public long? ActionId { get; set; }
public RecAction? Action { get; set; }
public short? Status { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,31 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_PROFILE", Schema = "dbo")]
public class Profile
{
public long Id { get; set; }
public bool? Active { get; set; }
public string? Type { get; set; }
public string? Mandantor { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? LogLevel { get; set; }
public string? Language { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,54 +0,0 @@
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Entities;
[Table("TBREC_CFG_ACTION")]
public class RecAction
{
public long? Id { get; set; }
public long? ProfileId { get; set; }
public Profile? Profile { get; set; }
public bool? Active { get; set; }
public byte? Sequence { get; set; }
public long? EndpointId { get; set; }
public Endpoint? Endpoint { get; set; }
public long? EndpointAuthId { get; set; }
public EndpointAuth? EndpointAuth { get; set; }
public short? EndpointParamsId { get; set; }
public short? SqlConnectionId { get; set; }
public Connection? SqlConnection { get; set; }
public string? Type { get; set; }
public string? PreprocessingQuery { get; set; }
public string? HeaderQuery { get; set; }
public string? BodyQuery { get; set; }
public string? PostprocessingQuery { get; set; }
public ErrorAction? ErrorAction { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
public OutRes? OutRes { get; set; }
}

View File

@@ -1,4 +1,4 @@
namespace ReC.Domain.Entities;
namespace ReC.Domain.QueryOutput;
public class BodyQueryResult
{

View File

@@ -1,4 +1,4 @@
namespace ReC.Domain.Entities;
namespace ReC.Domain.QueryOutput;
public class HeaderQueryResult
{

View File

@@ -0,0 +1,8 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.QueryOutput;
public class InsertObjectResult
{
public required long NewObjectId { get; set; }
}

View File

@@ -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; }

View File

@@ -1,5 +1,4 @@
using ReC.Domain.Constants;
using ReC.Domain.Entities;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Views;
@@ -15,10 +14,9 @@ namespace ReC.Domain.Views;
[Table("VWREC_ACTION", Schema = "dbo")]
public class RecActionView
{
public required long Id { get; set; }
public virtual IEnumerable<ResultView>? Results { get; set; }
[ForeignKey("Id")]
public RecAction? Root { get; set; }
public required long Id { get; set; }
public long? ProfileId { get; set; }
@@ -33,16 +31,10 @@ public class RecActionView
public long? EndpointId { get; set; }
[ForeignKey("EndpointId")]
public Endpoint? Endpoint { get; set; }
public string? EndpointUri { get; set; }
public long? EndpointAuthId { get; set; }
[ForeignKey("EndpointAuthId")]
public EndpointAuth? EndpointAuth { get; set; }
public EndpointAuthType? EndpointAuthType { get; set; }
public string? EndpointAuthTypeName { get; set; }
@@ -69,9 +61,6 @@ public class RecActionView
public short? SqlConnectionId { get; set; }
[ForeignKey("SqlConnectionId")]
public Connection? SqlConnection { get; set; }
public string? SqlConnectionServer { get; set; }
public string? SqlConnectionDb { get; set; }

View File

@@ -23,7 +23,11 @@ public static class DependencyInjection
services.AddScoped<IRecDbContext>(provider => provider.GetRequiredService<TRecDbContext>());
services.AddDbRepository(opt => opt.RegisterFromAssembly<TRecDbContext>(typeof(RecActionView).Assembly));
services.AddDbRepository(opt =>
{
opt.RegisterFromAssembly<TRecDbContext>(typeof(RecActionView).Assembly);
opt.RegisterDefaultRepository<TRecDbContext>();
});
services.AddValidatorsFromAssembly(typeof(AuthScopedValidator).Assembly);

View File

@@ -1,229 +1,31 @@
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
{
public DbSet<EndpointParam> EndpointParams { get; set; }
#region DB Sets
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; }
public DbSet<BodyQueryResult> BodyQueryResults { get; set; }
public DbSet<Connection> Connections { get; set; }
public DbSet<Endpoint> Endpoints { get; set; }
public DbSet<EndpointAuth> EndpointAuths { get; set; }
public DbSet<Profile> Profiles { get; set; }
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);
modelBuilder.Entity<Connection>(b =>
{
b.ToTable("TBDD_CONNECTION");
b.HasKey(e => e.Id);
b.Property(e => e.Id)
.HasColumnName("GUID")
.ValueGeneratedOnAdd();
b.Property(e => e.Bezeichnung).HasColumnName("BEZEICHNUNG");
b.Property(e => e.SqlProvider).HasColumnName("SQL_PROVIDER");
b.Property(e => e.Server).HasColumnName("SERVER");
b.Property(e => e.Datenbank).HasColumnName("DATENBANK");
b.Property(e => e.Username).HasColumnName("USERNAME");
b.Property(e => e.Password).HasColumnName("PASSWORD");
b.Property(e => e.Bemerkung).HasColumnName("BEMERKUNG");
b.Property(e => e.Aktiv).HasColumnName("AKTIV");
b.Property(e => e.ErstelltWer).HasColumnName("ERSTELLTWER");
b.Property(e => e.ErstelltWann).HasColumnName("ERSTELLTWANN");
b.Property(e => e.GeandertWer).HasColumnName("GEANDERTWER");
b.Property(e => e.GeaendertWann).HasColumnName("GEAENDERTWANN");
b.Property(e => e.SysConnection).HasColumnName("SYS_CONNECTION");
});
modelBuilder.Entity<Endpoint>(b =>
{
b.ToTable("TBREC_CFG_ENDPOINT");
b.HasKey(e => e.Id);
b.Property(e => e.Id)
.HasColumnName("GUID")
.ValueGeneratedOnAdd();
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.Description).HasColumnName("DESCRIPTION");
b.Property(e => e.Uri).HasColumnName("URI");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
});
modelBuilder.Entity<EndpointAuth>(b =>
{
b.ToTable("TBREC_CFG_ENDPOINT_AUTH");
b.HasKey(e => e.Id);
b.Property(e => e.Id)
.HasColumnName("GUID")
.ValueGeneratedOnAdd();
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.Description).HasColumnName("DESCRIPTION");
b.Property(e => e.Type).HasColumnName("TYPE");
b.Property(e => e.ApiKey).HasColumnName("API_KEY");
b.Property(e => e.ApiValue).HasColumnName("API_VALUE");
b.Property(e => e.ApiKeyAddTo).HasColumnName("API_KEY_ADD_TO");
b.Property(e => e.Token).HasColumnName("TOKEN");
b.Property(e => e.Username).HasColumnName("USERNAME");
b.Property(e => e.Password).HasColumnName("PASSWORD");
b.Property(e => e.Domain).HasColumnName("DOMAIN");
b.Property(e => e.Workstation).HasColumnName("WORKSTATION");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
});
modelBuilder.Entity<EndpointParam>(b =>
{
b.ToTable("TBREC_CFG_ENDPOINT_PARAMS", "dbo");
b.HasKey(e => e.Id);
b.Property(e => e.Id).HasColumnName("GUID");
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.Description).HasColumnName("DESCRIPTION");
b.Property(e => e.GroupId).HasColumnName("GROUP_ID");
b.Property(e => e.Sequence).HasColumnName("SEQUENCE");
b.Property(e => e.Key).HasColumnName("KEY");
b.Property(e => e.Value).HasColumnName("VALUE");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
});
modelBuilder.Entity<OutRes>(b =>
{
b.ToTable("TBREC_OUT_RESULT", "dbo");
b.HasKey(e => e.Id);
b.Property(e => e.Id)
.HasColumnName("GUID")
.ValueGeneratedOnAdd();
b.Property(e => e.ActionId).HasColumnName("ACTION_ID");
b.Property(e => e.Status).HasColumnName("STATUS_ID");
b.Property(e => e.Header).HasColumnName("RESULT_HEADER");
b.Property(e => e.Body).HasColumnName("RESULT_BODY");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
});
modelBuilder.Entity<Profile>(b =>
{
b.ToTable("TBREC_CFG_PROFILE", "dbo");
b.HasKey(e => e.Id);
b.Property(e => e.Id)
.HasColumnName("GUID")
.ValueGeneratedOnAdd();
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.Type).HasColumnName("TYPE");
b.Property(e => e.Mandantor).HasColumnName("MANDANTOR");
b.Property(e => e.Name).HasColumnName("PROFILE_NAME");
b.Property(e => e.Description).HasColumnName("DESCRIPTION");
b.Property(e => e.LogLevel).HasColumnName("LOG_LEVEL");
b.Property(e => e.Language).HasColumnName("LANGUAGE");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
b.Property(e => e.AddedWhen).HasColumnName("ADDED_WHEN");
b.Property(e => e.ChangedWho).HasColumnName("CHANGED_WHO");
b.Property(e => e.ChangedWhen).HasColumnName("CHANGED_WHEN");
});
modelBuilder.Entity<ProfileView>(b =>
{
b.ToView("VWREC_PROFILE", "dbo");
b.HasKey(e => e.Id);
b.Property(e => e.Id).HasColumnName("PROFILE_GUID");
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.TypeId).HasColumnName("TYPE_ID");
b.Property(e => e.Type).HasColumnName("TYPE");
b.Property(e => e.Mandantor).HasColumnName("MANDANTOR");
b.Property(e => e.ProfileName).HasColumnName("PROFILE_NAME");
b.Property(e => e.Description).HasColumnName("DESCRIPTION");
b.Property(e => e.LogLevelId).HasColumnName("LOG_LEVEL_ID");
b.Property(e => e.LogLevel).HasColumnName("LOG_LEVEL");
b.Property(e => e.LanguageId).HasColumnName("LANGUAGE_ID");
b.Property(e => e.Language).HasColumnName("LANGUAGE");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
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.Property(e => e.FirstRun).HasColumnName("FIRST_RUN");
b.Property(e => e.LastRun).HasColumnName("LAST_RUN");
b.Property(e => e.LastResult).HasColumnName("LAST_RESULT");
});
modelBuilder.Entity<RecAction>(b =>
{
b.ToTable("TBREC_CFG_ACTION");
b.HasKey(e => e.Id);
b.Property(e => e.Id).HasColumnName("GUID");
b.Property(e => e.ProfileId).HasColumnName("PROFILE_ID");
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.Sequence).HasColumnName("SEQUENCE");
b.Property(e => e.EndpointId).HasColumnName("ENDPOINT_ID");
b.Property(e => e.EndpointAuthId).HasColumnName("ENDPOINT_AUTH_ID");
b.Property(e => e.EndpointParamsId).HasColumnName("ENDPOINT_PARAMS_ID");
b.Property(e => e.SqlConnectionId).HasColumnName("SQL_CONNECTION_ID");
b.Property(e => e.Type).HasColumnName("TYPE");
b.Property(e => e.PreprocessingQuery).HasColumnName("PREPROCESSING_QUERY");
b.Property(e => e.HeaderQuery).HasColumnName("HEADER_QUERY");
b.Property(e => e.BodyQuery).HasColumnName("BODY_QUERY");
b.Property(e => e.PostprocessingQuery).HasColumnName("POSTPROCESSING_QUERY");
b.Property(e => e.ErrorAction).HasColumnName("ERROR_ACTION");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
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(act => act.OutRes)
.WithOne(res => res.Action)
.HasForeignKey<OutRes>(res => res.ActionId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<RecActionView>(b =>
{
b.ToView("VWREC_ACTION", "dbo");
@@ -262,6 +64,34 @@ 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<ProfileView>(b =>
{
b.ToView("VWREC_PROFILE", "dbo");
b.HasKey(e => e.Id);
b.Property(e => e.Id).HasColumnName("PROFILE_GUID");
b.Property(e => e.Active).HasColumnName("ACTIVE");
b.Property(e => e.TypeId).HasColumnName("TYPE_ID");
b.Property(e => e.Type).HasColumnName("TYPE");
b.Property(e => e.Mandantor).HasColumnName("MANDANTOR");
b.Property(e => e.ProfileName).HasColumnName("PROFILE_NAME");
b.Property(e => e.Description).HasColumnName("DESCRIPTION");
b.Property(e => e.LogLevelId).HasColumnName("LOG_LEVEL_ID");
b.Property(e => e.LogLevel).HasColumnName("LOG_LEVEL");
b.Property(e => e.LanguageId).HasColumnName("LANGUAGE_ID");
b.Property(e => e.Language).HasColumnName("LANGUAGE");
b.Property(e => e.AddedWho).HasColumnName("ADDED_WHO");
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.Property(e => e.FirstRun).HasColumnName("FIRST_RUN");
b.Property(e => e.LastRun).HasColumnName("LAST_RUN");
b.Property(e => e.LastResult).HasColumnName("LAST_RESULT");
});
modelBuilder.Entity<ResultView>(b =>
@@ -281,6 +111,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 +133,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");
});
}
}

View File

@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.EndpointAuth.Commands;
using ReC.Tests.Application;
namespace ReC.Tests.Application.EndpointAuth;
[TestFixture]
public class EndpointAuthProcedureTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task InsertEndpointAuthProcedure_runs_via_mediator()
{
var procedure = new InsertEndpointAuthProcedure { Active = true, Description = "auth", TypeId = 1, ApiKey = "key", ApiValue = "value" };
var objectProc = procedure.ToObjectProcedure("ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.GreaterThan(0));
}
[Test]
public async Task UpdateEndpointAuthProcedure_runs_via_mediator()
{
var procedure = new UpdateEndpointAuthProcedure { Active = false, Description = "auth-update", TypeId = 2 };
var objectProc = procedure.ToObjectProcedure(15, "ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
[Test]
public async Task DeleteEndpointAuthProcedure_runs_via_mediator()
{
var procedure = new DeleteEndpointAuthProcedure { Start = 3, End = 4, Force = false };
var objectProc = procedure.ToObjectProcedure();
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
}

View File

@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.EndpointParams.Commands;
using ReC.Tests.Application;
namespace ReC.Tests.Application.EndpointParams;
[TestFixture]
public class EndpointParamsProcedureTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task InsertEndpointParamsProcedure_runs_via_mediator()
{
var procedure = new InsertEndpointParamsProcedure { Active = true, Description = "param", GroupId = 1, Sequence = 1, Key = "k", Value = "v" };
var objectProc = procedure.ToObjectProcedure("ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.GreaterThan(0));
}
[Test]
public async Task UpdateEndpointParamsProcedure_runs_via_mediator()
{
var procedure = new UpdateEndpointParamsProcedure { Active = false, Description = "param-update", GroupId = 2, Sequence = 2, Key = "k2", Value = "v2" };
var objectProc = procedure.ToObjectProcedure(25, "ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
[Test]
public async Task DeleteEndpointParamsProcedure_runs_via_mediator()
{
var procedure = new DeleteEndpointParamsProcedure { Start = 5, End = 6, Force = true };
var objectProc = procedure.ToObjectProcedure();
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
}

View File

@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Endpoints.Commands;
using ReC.Tests.Application;
namespace ReC.Tests.Application.Endpoints;
[TestFixture]
public class EndpointProcedureTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task InsertEndpointProcedure_runs_via_mediator()
{
var procedure = new InsertEndpointProcedure { Active = true, Description = "desc", Uri = "http://example" };
var objectProc = procedure.ToObjectProcedure("ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.GreaterThan(0));
}
[Test]
public async Task UpdateEndpointProcedure_runs_via_mediator()
{
var procedure = new UpdateEndpointProcedure { Active = false, Description = "updated", Uri = "http://updated" };
var objectProc = procedure.ToObjectProcedure(12, "ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
[Test]
public async Task DeleteEndpointProcedure_runs_via_mediator()
{
var procedure = new DeleteEndpointProcedure { Start = 1, End = 2, Force = true };
var objectProc = procedure.ToObjectProcedure();
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
}

View File

@@ -0,0 +1,58 @@
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Profile.Commands;
using ReC.Tests.Application;
namespace ReC.Tests.Application.Procedures;
[TestFixture]
public class ProcedureExecutionTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task ExecuteInsertProcedure_runs_with_addedWho()
{
var procedure = new InsertProfileProcedure { Name = "name" };
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.ExecuteInsertProcedure(procedure, "ReC.Tests");
Assert.That(result, Is.GreaterThan(0));
}
[Test]
public async Task ExecuteUpdateProcedure_runs_with_changedWho()
{
var procedure = new UpdateProfileProcedure { Name = "updated" };
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.ExecuteUpdateProcedure(procedure, 123, "ReC.Tests");
Assert.That(result, Is.Not.EqualTo(default(int)));
}
[Test]
public async Task ExecuteDeleteProcedure_runs()
{
var procedure = new DeleteProfileProcedure { Start = 1, End = 2, Force = true };
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.ExecuteDeleteProcedure(procedure);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
}

View File

@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Profile.Commands;
using ReC.Tests.Application;
namespace ReC.Tests.Application.Profile;
[TestFixture]
public class ProfileProcedureTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task InsertProfileProcedure_runs_via_mediator()
{
var procedure = new InsertProfileProcedure { Active = true, TypeId = 1, Name = "name", Mandantor = "man" };
var objectProc = procedure.ToObjectProcedure("ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.GreaterThan(0));
}
[Test]
public async Task UpdateProfileProcedure_runs_via_mediator()
{
var procedure = new UpdateProfileProcedure { Active = false, TypeId = 2, Name = "updated", Mandantor = "man2" };
var objectProc = procedure.ToObjectProcedure(45, "ReC.Tests");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
[Test]
public async Task DeleteProfileProcedure_runs_via_mediator()
{
var procedure = new DeleteProfileProcedure { Start = 9, End = 10, Force = false };
var objectProc = procedure.ToObjectProcedure();
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(objectProc);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
}

View File

@@ -0,0 +1,51 @@
using System.Linq;
using System.Threading.Tasks;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using ReC.Application.Profile.Queries;
using ReC.Tests.Application;
namespace ReC.Tests.Application.Profile;
[TestFixture]
public class ProfileQueryTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task ReadProfileViewQuery_returns_profile_from_database()
{
var profileId = Configuration.GetValue<long?>("FakeProfileId");
Assert.That(profileId, Is.Not.Null.And.GreaterThan(0), "FakeProfileId must be configured in appsettings.json");
var (sender, scope) = CreateScopedSender();
using var _ = scope;
try
{
var profiles = await sender.Send(new ReadProfileViewQuery
{
Id = profileId,
IncludeActions = false
});
var profile = profiles.Single();
Assert.That(profile.Id, Is.EqualTo(profileId));
Assert.That(profile.ProfileName, Is.Not.Null.And.Not.Empty);
Assert.That(profile.Active, Is.True);
}
catch (NotFoundException)
{
Assert.Pass("NotFound is acceptable when profile does not exist");
}
}
}

Some files were not shown because too many files have changed in this diff Show More