From 9a12643eb6ad9f93ff538299ae229b5303b64c4f Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 4 Dec 2025 15:37:06 +0100 Subject: [PATCH] Refactor RecActionController and DeleteRecActionsCommand Updated the `Invoke` method in `RecActionController` to use `cmd` as the route parameter instead of `profileId`, modifying the HTTP POST route to `invoke/{cmd}`. Refactored the `Delete` method to accept a `DeleteRecActionsCommand` object (`cmd`) instead of `profileId`. Removed the hardcoded `ProfileId` assignment and passed the `cmd` object directly to `mediator.Send`. Made the `ProfileId` property in `DeleteRecActionsCommand` required by removing its default value, enforcing explicit initialization. This improves validation and ensures flexibility for future enhancements. These changes enhance the API's clarity, flexibility, and maintainability. --- src/ReC.API/Controllers/RecActionController.cs | 12 ++++-------- .../RecActions/Commands/DeleteRecActionsCommand.cs | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ReC.API/Controllers/RecActionController.cs b/src/ReC.API/Controllers/RecActionController.cs index 543186d..ff0d2b2 100644 --- a/src/ReC.API/Controllers/RecActionController.cs +++ b/src/ReC.API/Controllers/RecActionController.cs @@ -18,7 +18,7 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co /// The ID of the profile. /// A token to cancel the operation. /// An HTTP 202 Accepted response indicating the process has been started. - [HttpPost("invoke/{profileId}")] + [HttpPost("invoke/{cmd}")] [ProducesResponseType(StatusCodes.Status202Accepted)] public async Task Invoke([FromRoute] int profileId, CancellationToken cancel) { @@ -120,18 +120,14 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co /// /// Deletes all RecActions associated with a specific profile. /// - /// The ID of the profile whose RecActions should be deleted. + /// /// A token to cancel the operation. /// An HTTP 204 No Content response upon successful deletion. [HttpDelete] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task Delete([FromQuery] int profileId, CancellationToken cancel) + public async Task Delete([FromQuery] DeleteRecActionsCommand cmd, CancellationToken cancel) { - await mediator.Send(new DeleteRecActionsCommand() - { - ProfileId = config.GetFakeProfileId() - }, cancel); - + await mediator.Send(cmd, cancel); return NoContent(); } diff --git a/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs b/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs index abc2a64..84e52d9 100644 --- a/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs +++ b/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs @@ -8,7 +8,7 @@ namespace ReC.Application.RecActions.Commands; public class DeleteRecActionsCommand : IRequest { - public long ProfileId { get; init; } = 2; + public required long ProfileId { get; init; } } public class DeleteRecActionsCommandHandler(IRepository repo) : IRequestHandler