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:
parent
c34a87771d
commit
dc408e7794
@ -26,15 +26,16 @@ public class RecActionController(IMediator mediator) : ControllerBase
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[HttpPost("fake")]
|
||||
public async Task<IActionResult> 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<IActionResult> GetActions([FromQuery] int profileId)
|
||||
public async Task<IActionResult> GetActions([FromQuery] int profileId, CancellationToken cancel)
|
||||
{
|
||||
await mediator.Send(new DeleteRecActionsCommand()
|
||||
{
|
||||
ProfileId = profileId
|
||||
});
|
||||
}, cancel);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user