From dc408e779451d6947670ec3da61b2eae19fac848 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 3 Dec 2025 11:34:00 +0100 Subject: [PATCH] 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. --- src/ReC.API/Controllers/RecActionController.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ReC.API/Controllers/RecActionController.cs b/src/ReC.API/Controllers/RecActionController.cs index 736e58e..30e4c38 100644 --- a/src/ReC.API/Controllers/RecActionController.cs +++ b/src/ReC.API/Controllers/RecActionController.cs @@ -26,15 +26,16 @@ public class RecActionController(IMediator mediator) : ControllerBase } [HttpPost] - public async Task CreateAction([FromBody] CreateRecActionCommand command) + public async Task CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel) { - await mediator.Send(command); + await mediator.Send(command, cancel); return CreatedAtAction(nameof(CreateAction), null); } [HttpPost("fake")] public async Task CreateFakeAction( + CancellationToken cancel, [FromBody] FakeRequest? request = null, [FromQuery] string endpointUri = "https://jsonplaceholder.typicode.com/posts", [FromQuery] string? endpointPath = null, @@ -54,18 +55,18 @@ public class RecActionController(IMediator mediator) : ControllerBase BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;", HeaderQuery = headerJson is not null ? $@"SELECT '{headerJson}' AS REQUEST_HEADER;" : null, Active = true - }); + }, cancel); return CreatedAtAction(nameof(CreateFakeAction), null); } [HttpDelete] - public async Task GetActions([FromQuery] int profileId) + public async Task GetActions([FromQuery] int profileId, CancellationToken cancel) { await mediator.Send(new DeleteRecActionsCommand() { ProfileId = profileId - }); + }, cancel); return NoContent(); }