45 lines
1.5 KiB
C#
Raw Normal View History

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;
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;
private readonly IOrderingService _orderingService;
public OrderController(IBasketService basketService, IOrderingService orderingService)
2018-02-27 14:32:25 +01:00
{
_basketService = basketService;
_orderingService = orderingService;
2018-02-27 14:32:25 +01:00
}
[Route("draft/{basketId}")]
[HttpGet]
[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
var basket = await _basketService.GetById(basketId);
2018-02-27 14:32:25 +01:00
if (basket == null)
{
return BadRequest($"No basket found for id {basketId}");
}
return await _orderingService.GetOrderDraftAsync(basket);
2018-02-27 14:32:25 +01:00
}
}
}