Use cancellation token in repository and web fie system (http call can cancelled) (#471)
Co-authored-by: cmichel <cmichel@interparking.com>
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
using System.Threading;
|
||||
using Ardalis.ApiEndpoints;
|
||||
using Ardalis.ApiEndpoints;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Constants;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
@@ -28,14 +27,14 @@ namespace Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints
|
||||
OperationId = "catalog-items.Delete",
|
||||
Tags = new[] { "CatalogItemEndpoints" })
|
||||
]
|
||||
public override async Task<ActionResult<DeleteCatalogItemResponse>> HandleAsync([FromRoute]DeleteCatalogItemRequest request, CancellationToken cancellationToken)
|
||||
public override async Task<ActionResult<DeleteCatalogItemResponse>> HandleAsync([FromRoute] DeleteCatalogItemRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new DeleteCatalogItemResponse(request.CorrelationId());
|
||||
|
||||
var itemToDelete = await _itemRepository.GetByIdAsync(request.CatalogItemId);
|
||||
var itemToDelete = await _itemRepository.GetByIdAsync(request.CatalogItemId, cancellationToken);
|
||||
if (itemToDelete is null) return NotFound();
|
||||
|
||||
await _itemRepository.DeleteAsync(itemToDelete);
|
||||
await _itemRepository.DeleteAsync(itemToDelete, cancellationToken);
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user