|
|
@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Ordering.API.Application.Behaviors; |
|
|
|
using Ordering.API.Application.Commands; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
@ -20,12 +22,18 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers |
|
|
|
private readonly IMediator _mediator; |
|
|
|
private readonly IOrderQueries _orderQueries; |
|
|
|
private readonly IIdentityService _identityService; |
|
|
|
private readonly ILogger<OrdersController> _logger; |
|
|
|
|
|
|
|
public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentityService identityService) |
|
|
|
public OrdersController( |
|
|
|
IMediator mediator, |
|
|
|
IOrderQueries orderQueries, |
|
|
|
IIdentityService identityService, |
|
|
|
ILogger<OrdersController> logger) |
|
|
|
{ |
|
|
|
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); |
|
|
|
_orderQueries = orderQueries ?? throw new ArgumentNullException(nameof(orderQueries)); |
|
|
|
_identityService = identityService ?? throw new ArgumentNullException(nameof(identityService)); |
|
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); |
|
|
|
} |
|
|
|
|
|
|
|
[Route("cancel")] |
|
|
@ -39,6 +47,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers |
|
|
|
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) |
|
|
|
{ |
|
|
|
var requestCancelOrder = new IdentifiedCommand<CancelOrderCommand, bool>(command, guid); |
|
|
|
|
|
|
|
_logger.LogInformation( |
|
|
|
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", |
|
|
|
requestCancelOrder.GetGenericTypeName(), |
|
|
|
nameof(requestCancelOrder.Command.OrderNumber), |
|
|
|
requestCancelOrder.Command.OrderNumber, |
|
|
|
requestCancelOrder); |
|
|
|
|
|
|
|
commandResult = await _mediator.Send(requestCancelOrder); |
|
|
|
} |
|
|
|
|
|
|
@ -61,6 +77,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers |
|
|
|
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) |
|
|
|
{ |
|
|
|
var requestShipOrder = new IdentifiedCommand<ShipOrderCommand, bool>(command, guid); |
|
|
|
|
|
|
|
_logger.LogInformation( |
|
|
|
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", |
|
|
|
requestShipOrder.GetGenericTypeName(), |
|
|
|
nameof(requestShipOrder.Command.OrderNumber), |
|
|
|
requestShipOrder.Command.OrderNumber, |
|
|
|
requestShipOrder); |
|
|
|
|
|
|
|
commandResult = await _mediator.Send(requestShipOrder); |
|
|
|
} |
|
|
|
|
|
|
@ -114,6 +138,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers |
|
|
|
[HttpPost] |
|
|
|
public async Task<ActionResult<OrderDraftDTO>> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand) |
|
|
|
{ |
|
|
|
_logger.LogInformation( |
|
|
|
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", |
|
|
|
createOrderDraftCommand.GetGenericTypeName(), |
|
|
|
nameof(createOrderDraftCommand.BuyerId), |
|
|
|
createOrderDraftCommand.BuyerId, |
|
|
|
createOrderDraftCommand); |
|
|
|
|
|
|
|
return await _mediator.Send(createOrderDraftCommand); |
|
|
|
} |
|
|
|
} |