2018-02-27 14:32:25 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-11-14 16:21:50 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
2018-02-27 14:32:25 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
2018-11-15 12:50:37 +01:00
|
|
|
|
using System.Net;
|
2018-02-27 14:32:25 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/v1/[controller]")]
|
|
|
|
|
[Authorize]
|
2018-11-14 16:21:50 +01:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class OrderController : ControllerBase
|
2018-02-27 14:32:25 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IBasketService _basketService;
|
2019-08-27 15:08:39 +02:00
|
|
|
|
private readonly IOrderingService _orderingService;
|
|
|
|
|
public OrderController(IBasketService basketService, IOrderingService orderingService)
|
2018-02-27 14:32:25 +01:00
|
|
|
|
{
|
|
|
|
|
_basketService = basketService;
|
2019-08-27 15:08:39 +02:00
|
|
|
|
_orderingService = orderingService;
|
2018-02-27 14:32:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("draft/{basketId}")]
|
|
|
|
|
[HttpGet]
|
2018-11-15 12:50:37 +01:00
|
|
|
|
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
|
|
|
|
[ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)]
|
|
|
|
|
public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId)
|
2018-02-27 14:32:25 +01:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(basketId))
|
|
|
|
|
{
|
|
|
|
|
return BadRequest("Need a valid basketid");
|
|
|
|
|
}
|
|
|
|
|
// Get the basket data and build a order draft based on it
|
2019-08-27 15:08:39 +02:00
|
|
|
|
var basket = await _basketService.GetById(basketId);
|
2018-11-15 12:50:37 +01:00
|
|
|
|
|
2018-02-27 14:32:25 +01:00
|
|
|
|
if (basket == null)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest($"No basket found for id {basketId}");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 15:08:39 +02:00
|
|
|
|
return await _orderingService.GetOrderDraftAsync(basket);
|
2018-02-27 14:32:25 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|