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.
This commit is contained in:
tekh 2025-12-03 11:34:00 +01:00
parent c34a87771d
commit dc408e7794

View File

@ -26,15 +26,16 @@ public class RecActionController(IMediator mediator) : ControllerBase
} }
[HttpPost] [HttpPost]
public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command) public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel)
{ {
await mediator.Send(command); await mediator.Send(command, cancel);
return CreatedAtAction(nameof(CreateAction), null); return CreatedAtAction(nameof(CreateAction), null);
} }
[HttpPost("fake")] [HttpPost("fake")]
public async Task<IActionResult> CreateFakeAction( public async Task<IActionResult> CreateFakeAction(
CancellationToken cancel,
[FromBody] FakeRequest? request = null, [FromBody] FakeRequest? request = null,
[FromQuery] string endpointUri = "https://jsonplaceholder.typicode.com/posts", [FromQuery] string endpointUri = "https://jsonplaceholder.typicode.com/posts",
[FromQuery] string? endpointPath = null, [FromQuery] string? endpointPath = null,
@ -54,18 +55,18 @@ public class RecActionController(IMediator mediator) : ControllerBase
BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;", BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;",
HeaderQuery = headerJson is not null ? $@"SELECT '{headerJson}' AS REQUEST_HEADER;" : null, HeaderQuery = headerJson is not null ? $@"SELECT '{headerJson}' AS REQUEST_HEADER;" : null,
Active = true Active = true
}); }, cancel);
return CreatedAtAction(nameof(CreateFakeAction), null); return CreatedAtAction(nameof(CreateFakeAction), null);
} }
[HttpDelete] [HttpDelete]
public async Task<IActionResult> GetActions([FromQuery] int profileId) public async Task<IActionResult> GetActions([FromQuery] int profileId, CancellationToken cancel)
{ {
await mediator.Send(new DeleteRecActionsCommand() await mediator.Send(new DeleteRecActionsCommand()
{ {
ProfileId = profileId ProfileId = profileId
}); }, cancel);
return NoContent(); return NoContent();
} }