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.
This commit is contained in:
tekh 2025-12-04 15:37:06 +01:00
parent f9c0a8be55
commit 9a12643eb6
2 changed files with 5 additions and 9 deletions

View File

@ -18,7 +18,7 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
/// <param name="profileId">The ID of the profile.</param> /// <param name="profileId">The ID of the profile.</param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns> /// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
[HttpPost("invoke/{profileId}")] [HttpPost("invoke/{cmd}")]
[ProducesResponseType(StatusCodes.Status202Accepted)] [ProducesResponseType(StatusCodes.Status202Accepted)]
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel) public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
{ {
@ -120,18 +120,14 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
/// <summary> /// <summary>
/// Deletes all RecActions associated with a specific profile. /// Deletes all RecActions associated with a specific profile.
/// </summary> /// </summary>
/// <param name="profileId">The ID of the profile whose RecActions should be deleted.</param> /// <param name="cmd"></param>
/// <param name="cancel">A token to cancel the operation.</param> /// <param name="cancel">A token to cancel the operation.</param>
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns> /// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
[HttpDelete] [HttpDelete]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> Delete([FromQuery] int profileId, CancellationToken cancel) public async Task<IActionResult> Delete([FromQuery] DeleteRecActionsCommand cmd, CancellationToken cancel)
{ {
await mediator.Send(new DeleteRecActionsCommand() await mediator.Send(cmd, cancel);
{
ProfileId = config.GetFakeProfileId()
}, cancel);
return NoContent(); return NoContent();
} }

View File

@ -8,7 +8,7 @@ namespace ReC.Application.RecActions.Commands;
public class DeleteRecActionsCommand : IRequest public class DeleteRecActionsCommand : IRequest
{ {
public long ProfileId { get; init; } = 2; public required long ProfileId { get; init; }
} }
public class DeleteRecActionsCommandHandler(IRepository<RecAction> repo) : IRequestHandler<DeleteRecActionsCommand> public class DeleteRecActionsCommandHandler(IRepository<RecAction> repo) : IRequestHandler<DeleteRecActionsCommand>