Add CancellationToken support to OutResController methods
Updated `Get` methods in `OutResController` to include a
`CancellationToken` parameter, enabling support for request
cancellation during asynchronous operations. Updated all
`mediator.Send` calls to propagate the `CancellationToken`.
Simplified the "fake/{actionId}" route by removing the explicit
assignment of `HttpContext.Response.ContentType` for non-
`ResultType.Full` cases.
This commit is contained in:
parent
b8074cfaf1
commit
9901726f5a
@ -2,7 +2,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReC.API.Extensions;
|
||||
using ReC.Application.OutResults.Queries;
|
||||
using System.Net.Mime;
|
||||
|
||||
namespace ReC.API.Controllers;
|
||||
|
||||
@ -11,25 +10,22 @@ namespace ReC.API.Controllers;
|
||||
public class OutResController(IMediator mediator, IConfiguration config) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query) => Ok(await mediator.Send(query));
|
||||
public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
|
||||
|
||||
[HttpGet("fake")]
|
||||
public async Task<IActionResult> Get() => Ok(await mediator.Send(new ReadOutResQuery()
|
||||
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadOutResQuery()
|
||||
{
|
||||
ProfileId = config.GetFakeProfileId()
|
||||
}));
|
||||
}, cancel));
|
||||
|
||||
[HttpGet("fake/{actionId}")]
|
||||
public async Task<IActionResult> Get([FromRoute] long actionId, ResultType resultType = ResultType.Full)
|
||||
public async Task<IActionResult> Get([FromRoute] long actionId, CancellationToken cancel, ResultType resultType = ResultType.Full)
|
||||
{
|
||||
var res = (await mediator.Send(new ReadOutResQuery()
|
||||
{
|
||||
ProfileId = config.GetFakeProfileId(),
|
||||
ActionId = actionId
|
||||
})).First();
|
||||
|
||||
if (resultType is not ResultType.Full)
|
||||
HttpContext.Response.ContentType = MediaTypeNames.Application.Json;
|
||||
}, cancel)).First();
|
||||
|
||||
return resultType switch
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user