166 Commits

Author SHA1 Message Date
1a0da4140b Add EndpointAuthId to support endpoint authentication
Introduced a new `EndpointAuthId` property in `RecActionController` and `CreateRecActionCommand` to enable handling of endpoint authentication. Updated the `RecActionController` to initialize `EndpointAuthId` with a default value of `1`. Modified the `CreateRecActionCommand` record to include a nullable `EndpointAuthId` property of type `long?`, allowing optional specification of authentication details.
2025-12-03 13:43:08 +01:00
94561fe014 Add Sequence property to CreateRecActionCommand
A new `Sequence` property of type `byte` was added to the
`CreateRecActionCommand` record. It is initialized with a
default value of `1` and includes a `set` accessor, making
it mutable. This property allows the record to store or
manipulate sequence-related information, enhancing its
functionality.
2025-12-03 13:20:46 +01:00
4e107d928e Enhance mapping in MappingProfile.cs
Updated the `MappingProfile` class to include custom mappings for the `CreateRecActionCommand` to `RecAction` transformation:
- Set `Active` to `true` by default.
- Set `AddedWhen` to the current UTC time.
- Set `AddedWho` to `"ReC.API"` as a placeholder.
Added a `TODO` comment to replace the hardcoded `AddedWho` value with dynamic injection from the current host/user context.
2025-12-03 13:08:00 +01:00
3e6c2ea12b Add repository interaction to CreateRecActionCommandHandler
Updated `CreateRecActionCommandHandler` to include a repository
dependency (`IRepository<RecAction>`) for persisting data. Added
a call to `repo.CreateAsync` in the `Handle` method to save the
command request. Updated `using` directives to include necessary
dependencies (`AutoMapper`, `DigitalData.Core.Abstraction.Application.Repository`,
and `ReC.Domain.Entities`). Validation logic for `EndpointId` or
`EndpointUri` remains unchanged.
2025-12-03 13:03:50 +01:00
606a6727f4 Refactor RecActionController and add CRUD methods
Refactored the `RecActionController` to improve structure and
readability by introducing a `#region CRUD` section. Updated
the `HttpPost` route for invoking actions to `"invoke/{profileId}"`.

Added a new `CreateAction` method to handle action creation
and renamed the `HttpDelete` method from `GetActions` to
`Delete` for clarity. Introduced the `Invoke` method for batch
action invocation. Improved overall code organization and
maintainability.
2025-12-03 12:54:39 +01:00
1e21d133ae Add mappings for AddedWhen and AddedWho in MappingProfile
Added a TODO comment to update `AddedWho` to be injected
from the current host/user context. Configured `AddedWhen`
to use the current UTC time (`DateTime.UtcNow`) and set
`AddedWho` to the string `"ReC.API"`.
2025-12-03 12:50:38 +01:00
6e68083a8d Set Active property to true in ObtainEndpointCommand map
Updated the `MappingProfile` class to configure the mapping
between `ObtainEndpointCommand` and `Endpoint` to explicitly
set the `Active` property of `Endpoint` to `true` using the
`ForMember` method. This ensures that the `Active` property
is initialized to `true` during the mapping process, aligning
with the intended default behavior for new `Endpoint` objects.
2025-12-03 12:43:51 +01:00
b67da5434e Fix incorrect conditional logic in ReadRecActionQueryHandler
The conditional check in the `Handle` method of the
`ReadRecActionQueryHandler` class was updated. Previously, the code
threw a `NotFoundException` if the `actions` list was not empty
(`actions.Count != 0`). This logic was inverted to throw the exception
when the `actions` list is empty (`actions.Count == 0`).

This change ensures the exception is thrown only when no actions are
found for the given profile, aligning with the intended behavior
described in the exception message.
2025-12-03 12:06:47 +01:00
a7f4677ad1 Refactor and enhance DbContext configuration
Updated `AddRecInfrastructure` to improve DbContext setup:
- Renamed parameters for clarity (`dbContextOpt` to `opt`).
- Renamed `connectionString` to `cnnStr` for consistency.
- Added `LogTo` for SQL query logging at `Trace` level.
- Enabled `EnableSensitiveDataLogging` for debugging.
- Enabled `EnableDetailedErrors` for detailed error messages.
2025-12-03 11:48:23 +01:00
edf2468a33 Enhance DbContext configuration with logging features
Added advanced logging and debugging capabilities to the
DbContext configuration in `AddRecInfrastructure`:
- Integrated `ILogger<RecDbContext>` for logging.
- Enabled SQL query logging with `LogTo` at `Trace` level.
- Enabled sensitive data logging for debugging purposes.
- Enabled detailed error messages for better diagnostics.
2025-12-03 11:47:54 +01:00
60e5adbf1a Refactor DbContext configuration for flexibility
Updated `ConfigureDbContext` to accept `IServiceProvider`, enabling dependency injection during database context setup. Modified `DependencyInjection.cs` to align with this change by updating `DbContextOptionsAction` and its related method signature.

Removed unused `System.IO` and `System.Text.Json` namespaces from `RecActionController.cs` to improve code cleanliness.
2025-12-03 11:47:04 +01:00
dc408e7794 Add CancellationToken support to controller methods
Updated `CreateAction`, `CreateFakeAction`, and `GetActions`
methods in `RecActionController` to include a `CancellationToken`
parameter. This enables handling of cancellation requests during
asynchronous operations. Updated `mediator.Send` calls to pass
the `CancellationToken`, improving responsiveness and resource
management.
2025-12-03 11:34:00 +01:00
c34a87771d Add CancellationToken support to RecAction methods
Updated the `Invoke` method in `RecActionController` to accept a `CancellationToken` parameter, enabling cancellation handling during execution. Modified the `InvokeBatchRecAction` extension method in `InvokeBatchRecActionsCommandExtensions` to propagate the `CancellationToken` to the `sender.Send` method, ensuring cancellation support for batch action commands.
2025-12-03 11:31:38 +01:00
6041d57948 Add CancellationToken support to Get method
The `Get` method in `RecActionController` was updated to include a `CancellationToken` parameter, enabling support for operation cancellation. The `mediator.Send` call was modified to pass the token. No changes were made to the `Invoke` method or other unrelated parts of the class.
2025-12-03 11:30:18 +01:00
a99f2d55b2 Add Get endpoint and refactor ReadRecActionQuery
Added a new Get endpoint to RecActionController to fetch data
based on profileId using ReadRecActionQuery. Updated
ReadRecActionQuery to support long ProfileId, added a
parameterless constructor, and refactored its structure.
Adjusted ReadRecActionQueryHandler to align with these changes.
2025-12-03 11:29:31 +01:00
edfbfd8e6c Update Profile.Id type and fix FK mapping in RecAction
Changed the `Id` property in the `Profile` class from `short?` to `long` to support larger values and resolve a type mismatch with the `ProfileId` foreign key in the `RecAction` class.

Removed the `[NotMapped]` attribute from the `Profile` navigation property in `RecAction` as the type mismatch issue has been resolved. Also removed the related TODO comment. These changes improve database schema consistency and integrity.
2025-12-03 11:18:36 +01:00
23ccd44bd6 Add table mappings and navigation property updates
Added `[Table]` attributes to `Connection`, `Endpoint`, `EndpointAuth`, and `Profile` classes to define database table mappings. Updated `Profile` with schema information.

Introduced a `Profile` navigation property in `RecAction` with a `[ForeignKey]` attribute to establish a relationship with the `Profile` entity. Temporarily marked it as `[NotMapped]` due to a foreign key type mismatch, with a `TODO` to resolve this in the future.

Included `System.ComponentModel.DataAnnotations.Schema` in `using` directives to support these changes.
2025-12-03 11:15:07 +01:00
2c005c35fb Add database connection string to appsettings.json
Added a new "ConnectionStrings" section to the `appsettings.json`
file, including a "Default" connection string for SQL Server.
The connection string specifies the server, database, user
credentials, and options to disable encryption and trust the
server certificate. This change configures database connectivity
for the application.
2025-12-03 11:08:53 +01:00
771eb80b9e Make DeleteRecActionsCommand robust and async-safe
Enhanced the DeleteRecActionsCommandHandler to include a check
for the existence of records before deletion, throwing a
NotFoundException if none are found. Made the Handle method
asynchronous and added necessary namespace imports for
exception handling and database operations. Added a comment
to suggest updating the DeleteAsync method in the Core library
to return the number of deleted records.
2025-12-03 10:46:23 +01:00
1cb9ce18b4 Add DELETE endpoint to RecActionController
A new HTTP DELETE endpoint has been added to the `RecActionController` class. The endpoint, implemented as the `GetActions` method, accepts a `profileId` as a query parameter and uses the mediator pattern to send a `DeleteRecActionsCommand` with the provided `profileId`.

The method returns an HTTP 204 No Content response upon successful deletion, ensuring a clean separation of concerns and adherence to the CQRS pattern.
2025-12-03 10:42:47 +01:00
5b16d19541 Rename ActionController to RecActionController
The `ActionController` class was removed and replaced with a new `RecActionController` class. The new class retains the same functionality, methods (`Invoke`, `CreateAction`, `CreateFakeAction`), and dependencies as the removed class.

The namespace (`ReC.API.Controllers`) and route attributes remain unchanged. Dependency injection for `IMediator` is preserved. This change is primarily a renaming of the controller to better align with its purpose while maintaining existing behavior.
2025-12-03 10:39:34 +01:00
b5b1f53e21 Refactor CreateFakeAction to use FakeRequest model
Refactored the `CreateFakeAction` method in `ActionController`:
- Replaced individual parameters with a strongly-typed `FakeRequest` model for the request body.
- Added `[FromQuery]` attributes for `endpointUri`, `endpointPath`, and `type` to allow query parameter overrides.
- Updated serialization logic for `Body` and `Header` to handle null values more explicitly.
- Adjusted `BodyQuery` and `HeaderQuery` assignments to improve null handling.

Also updated `using` directives to include `ReC.API.Models` and `ReC.Application.RecActions.Commands`.
2025-12-03 10:27:34 +01:00
81aca90c39 Add FakeRequest model to handle request data
Introduced a new `FakeRequest` class in the `ReC.API.Models` namespace.
The class includes `Body` and `Header` properties, both of which
are nullable dictionaries with string keys and object values.
These properties are marked as `init`-only to ensure immutability
after initialization. This model is designed to support flexible
handling of request payloads and headers.
2025-12-03 10:22:13 +01:00
047f8fc258 Update HeaderQueryBehavior to use two generic parameters
Updated the `AddOpenBehaviors` method call in `DependencyInjection.cs` to reflect changes in the `HeaderQueryBehavior` class, which now requires two generic type parameters instead of one. This ensures compatibility with the updated class definition.
2025-12-03 10:16:57 +01:00
4b0208ca56 Refactor HeaderQueryBehavior for generic request/response
Updated HeaderQueryBehavior to support two generic type
parameters, TRequest and TResponse, for improved flexibility.
Replaced the single TRecAction type parameter and Unit return
type with a more generic implementation. Updated where
constraints to reflect the new generic types. Modified the
Handle method signature and logic to align with the updated
generic parameters.
2025-12-03 10:16:29 +01:00
0e62011f92 Update BodyQueryBehavior to use two-type parameters
Modified the `AddOpenBehaviors` method in the `DependencyInjection` class to update `BodyQueryBehavior<>` to its two-type parameter version, `BodyQueryBehavior<,>`. The `HeaderQueryBehavior<>` remains unchanged.
2025-12-03 10:12:56 +01:00
3998c9ce0b Refactor BodyQueryBehavior for generic request-response
Updated BodyQueryBehavior to support a generic request-response
pipeline. Replaced fixed `TRecAction` and `Unit` types with
`TRequest` and `TResponse` generics. Added `where` constraints
for `TRequest` (`RecActionDto`) and `TResponse` (`notnull`).
Updated the `Handle` method signature and return type to align
with the new generics.
2025-12-03 10:12:35 +01:00
269578194a Replace MediatRLicense with LuckyPennySoftwareLicenseKey
The `MediatRLicense` key was removed from `appsettings.json`
and replaced with the `LuckyPennySoftwareLicenseKey`. This
change likely reflects a transition to a new licensing
mechanism. No other modifications were made to the file.
2025-12-03 10:08:15 +01:00
6a3e0b7d50 Refactor AutoMapper profiles and add mappings
Updated `DtoMappingProfile` and `MappingProfiles` to explicitly inherit from `AutoMapper.Profile` for clarity. Added mapping configurations for `RecActionView` to `RecActionDto` and `CreateOutResCommand` to `OutRes` using `CreateMap` in their respective constructors.
2025-12-03 10:01:38 +01:00
50e092d9e2 Add JSON body/header support to CreateFakeAction method
Updated ActionController to support JSON serialization for
request body and headers in the CreateFakeAction method.
Replaced `bodyQuery` with `body` and `header` parameters,
serialized to JSON. Updated `BodyQuery` and added
`HeaderQuery` in `CreateRecActionCommand`. Refactored
endpoint URI construction and improved response handling.
2025-12-03 10:00:37 +01:00
1000be0c89 Add enhancements to ActionController and CreateFakeAction
Refactored ActionController to include IMediator dependency
in the constructor. Updated CreateFakeAction method to:
- Set a default value for `endpointUri`.
- Add an optional `endpointPath` parameter and logic to
  construct a full URI.
- Include the `Active` property in CreateRecActionCommand.
- Ensure `endpointUri` is non-nullable.

Also added the `System.IO` namespace for potential future use.
2025-12-03 09:52:25 +01:00
4d593e8a8e Add ExceptionHandlingMiddleware to request pipeline
Refactor `using` directives in `Program.cs` to include `ReC.API.Middleware` for middleware functionality.

Introduce `ExceptionHandlingMiddleware` to the HTTP request pipeline to handle exceptions globally. Suppress CS0618 warnings for its usage. No changes were made to the existing controller service configuration.
2025-12-03 09:34:49 +01:00
d239d43c1c Add handling for DataIntegrityException in middleware
Enhanced the ExceptionHandlingMiddleware to handle
DataIntegrityException explicitly. Added a new `using`
directive for `ReC.Application.Common.Exceptions` to
support this change. When a DataIntegrityException is
caught, the middleware now sets the HTTP status code to
409 Conflict and returns the exception's message.

Also updated the default case to ensure unhandled
exceptions are logged and return a generic error message
with a 500 Internal Server Error status code.
2025-12-03 09:34:02 +01:00
586b99ddc7 Add global exception handling middleware
Introduced `ExceptionHandlingMiddleware` to handle exceptions globally, log them, and return appropriate HTTP responses with JSON error messages.

- Added `HandleExceptionAsync` for exception processing.
- Handled `BadRequestException` (400) and `NotFoundException` (404).
- Included default handling for unhandled exceptions (500).
- Marked middleware as `[Obsolete]` with a note to use `DigitalData.Core.Exceptions.Middleware`.
- Added necessary `using` directives and XML documentation.
2025-12-03 09:31:14 +01:00
06af6dd43c Refactor CreateOutResCommandHandler for OutRes entity
Updated CreateOutResCommandHandler to use the OutRes entity
instead of the command itself in repository operations. Added
a new using directive for ReC.Domain.Entities. Updated the
CreateOutResCommand class to implement MediatR's IRequest
interface.
2025-12-03 09:29:02 +01:00
8624742eb3 Add CreateFakeAction endpoint and update command defaults
The ActionController class was updated to include a new
CreateFakeAction endpoint. This endpoint accepts optional
parameters (endpointUri, type, and bodyQuery) and sends a
CreateRecActionCommand with hardcoded and default values.

The CreateRecActionCommand record was modified to remove
default values for ProfileId, Type, and BodyQuery. These
properties now require explicit initialization, with Type
and BodyQuery marked as non-nullable using the null! syntax.

These changes improve flexibility and add support for
creating "fake" actions via the new endpoint.
2025-12-01 16:48:05 +01:00
a27000a75b Refactor DeleteRecActionsCommandHandler.Handle method
Simplified the `Handle` method by removing the `async` modifier
and replacing the `await` call with a direct `return` statement
for `repo.DeleteAsync`. This optimization eliminates the
overhead of creating an async state machine, as no additional
asynchronous operations or logic are performed in the method.
2025-12-01 16:29:41 +01:00
e74ee56f42 Add DeleteRecActionsCommand and handler for deletion
Introduced `DeleteRecActionsCommand` and its handler to enable
deletion of `RecAction` entities based on `ProfileId`. Added
necessary `using` directives and organized the code under the
`ReC.Application.RecActions.Commands` namespace. The handler
uses dependency injection for the repository and performs
asynchronous deletion with cancellation support.
2025-12-01 16:19:51 +01:00
ac214dc8e1 Add CreateAction POST endpoint to ActionController
A new HTTP POST endpoint `CreateAction` was added to the
`ActionController` class. This endpoint accepts a
`CreateRecActionCommand` object from the request body, sends
it to the `mediator` for processing, and returns a `201 Created`
response using the `CreatedAtAction` method. This change
enables the creation of actions via HTTP POST requests,
enhancing the controller's functionality.
2025-12-01 16:16:35 +01:00
d6b914b9c8 Add new DbSet properties to RecDbContext
Expanded RecDbContext to include new DbSet properties for
managing `Connections`, `Endpoints`, `EndpointAuths`,
`Profiles`, and `RecActions`. These additions enable
interaction with corresponding database tables/entities.

Updated the `OnModelCreating` method to ensure proper
configuration of the context. Removed an extraneous
closing brace to maintain proper syntax.
2025-12-01 16:14:15 +01:00
d764668cd7 Add CreateAction endpoint to ActionController
Introduced a new asynchronous `CreateAction` method in the
`ActionController` class to handle HTTP POST requests for
creating "rec actions". The method accepts a `CreateRecActionCommand`
object from the request body, processes it using `mediator.Send`,
and returns a `201 Created` response using `CreatedAtAction`.
2025-12-01 16:10:57 +01:00
6208a1cf93 Set default ProfileId and clean up unused directives
Removed unused `using` directives for `DigitalData.Core.Abstraction.Application.Repository` and `ReC.Domain.Entities`. Reordered `using` directives for better organization. Updated the `ProfileId` property in `CreateRecActionCommand` to have a default value of `2`, improving code clarity and reducing the need for explicit initialization.
2025-12-01 16:07:52 +01:00
a7ad55e973 Add MappingProfile for CreateRecActionCommand mapping
Introduced a new `MappingProfile` class in the `ReC.Application.RecActions` namespace to define object-to-object mapping configurations using AutoMapper.

The profile maps `CreateRecActionCommand` to `RecAction`, enabling seamless data transformation between these types. Added necessary `using` directives for `ReC.Application.RecActions.Commands` and `ReC.Domain.Entities`.
2025-12-01 16:07:11 +01:00
918372371e Refactor GetOrCreateEndpointCommand to ObtainEndpointCommand
Replaced `GetOrCreateEndpointCommand` with `ObtainEndpointCommand`
to improve clarity and align with naming conventions. Removed
`GetOrCreateEndpointCommand` and its handler, and introduced
`ObtainEndpointCommand` with equivalent functionality.

Updated `MappingProfile.cs` to map `ObtainEndpointCommand` to
`Endpoint`. Refactored `CreateRecActionCommand.cs` to use the
new `ObtainEndpointCommand` for retrieving or creating `Endpoint`
entities.

These changes ensure consistent naming and maintain the same
behavior while improving code readability.
2025-12-01 16:00:41 +01:00
a962299c95 Refactor GetOrCreateCommand to GetOrCreateEndpointCommand
Renamed `GetOrCreateCommand` to `GetOrCreateEndpointCommand`
to improve clarity and consistency. Removed the old
`GetOrCreateCommand` class and handler, and introduced the
new `GetOrCreateEndpointCommand` class with equivalent
functionality.

Updated `MappingProfile` to reflect the new command name
and adjusted `CreateRecActionCommand` to use the renamed
command. Added the appropriate namespace for the new class
to ensure proper organization.
2025-12-01 15:56:25 +01:00
cacd5eddbe Make Id property in Endpoint class non-nullable
The `Id` property in the `Endpoint` class was changed from a
nullable `long?` to a non-nullable `long`. This ensures that
the `Id` property is always assigned a value and cannot be
`null`, improving data integrity and aligning with potential
database or application requirements.
2025-12-01 15:55:23 +01:00
d30feb6034 Add handler for CreateRecActionCommand with validation
Updated `CreateRecActionCommand` to implement `IRequest` for MediatR compatibility. Introduced `CreateRecActionCommandHandler` to process requests, including validation for `EndpointId` and `EndpointUri`. Added logic to fetch or create an endpoint when `EndpointUri` is provided. Updated `EndpointId` property to be mutable. Added necessary `using` directives and adjusted the namespace declaration.
2025-12-01 15:55:01 +01:00
c6f2437300 Refactor endpoint commands and mappings
Removed unused `using` directives across files for cleanup. Deleted `CreateEndpointCommand` and `Endpoint` classes as they are no longer needed. Added `GetOrCreateCommand` to handle endpoint retrieval or creation. Updated `MappingProfile` to remove mappings for `CreateEndpointCommand` and ensure proper inheritance from `AutoMapper.Profile`.
2025-12-01 15:48:58 +01:00
46664d62ba Refactor GetOrCreateCommand and add AutoMapper profile
Refactored the `GetOrCreateCommand` to simplify the creation
of `Endpoint` entities by delegating the creation logic to
`repo.CreateAsync`.

Added a new `MappingProfile` class using AutoMapper to define
mappings between command objects (`CreateEndpointCommand` and
`GetOrCreateCommand`) and the `Endpoint` entity, improving
code maintainability and reducing boilerplate.

Included necessary `using` directives in `MappingProfile.cs`
to support the new mapping functionality.
2025-12-01 15:47:58 +01:00
4d6df7ccc8 Add CreateEndpointCommand and Endpoint classes
Introduced the `CreateEndpointCommand` class as a placeholder for future implementation. Added the `Endpoint` class with properties `Active`, `Description`, and `Uri` to represent endpoint details. Included necessary `using` directives and organized the code under the `ReC.Application.Endpoints.Commands` namespace.
2025-12-01 15:45:04 +01:00