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:
Cédric Michel
2020-11-30 18:21:19 +01:00
committed by GitHub
parent 2502e01efd
commit 6041a1f183
19 changed files with 95 additions and 97 deletions

View File

@@ -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);
}