2017-01-25 17:10:08 +01:00
|
|
|
|
using MediatR;
|
2017-01-27 11:38:23 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2017-01-25 17:10:08 +01:00
|
|
|
|
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 System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
|
|
|
|
{
|
2016-11-21 12:41:36 +01:00
|
|
|
|
[Route("api/v1/[controller]")]
|
2017-02-08 19:26:05 +01:00
|
|
|
|
//[Authorize]
|
2016-11-21 12:41:36 +01:00
|
|
|
|
public class OrdersController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly IMediator _mediator;
|
|
|
|
|
private readonly IOrderQueries _orderQueries;
|
2016-12-22 13:20:12 +01:00
|
|
|
|
private readonly IIdentityService _identityService;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2016-12-22 13:20:12 +01:00
|
|
|
|
public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentityService identityService)
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2016-12-22 13:20:12 +01:00
|
|
|
|
|
2017-02-27 10:35:31 +01:00
|
|
|
|
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
|
|
|
|
_orderQueries = orderQueries ?? throw new ArgumentNullException(nameof(orderQueries));
|
|
|
|
|
_identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("new")]
|
|
|
|
|
[HttpPost]
|
2017-02-13 14:03:21 -08:00
|
|
|
|
public async Task<IActionResult> CreateOrder([FromBody]CreateOrderCommand createOrderCommand)
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2017-02-13 14:03:21 -08:00
|
|
|
|
var result = await _mediator.SendAsync(createOrderCommand);
|
|
|
|
|
if (result)
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
[Route("{orderId:int}")]
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> GetOrder(int orderId)
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2016-12-17 14:41:16 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var order = await _orderQueries.GetOrder(orderId);
|
|
|
|
|
return Ok(order);
|
|
|
|
|
}
|
|
|
|
|
catch (KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
[Route("")]
|
2016-11-21 12:41:36 +01:00
|
|
|
|
[HttpGet]
|
2016-11-24 14:58:37 +01:00
|
|
|
|
public async Task<IActionResult> GetOrders()
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2016-11-24 14:58:37 +01:00
|
|
|
|
var orders = await _orderQueries.GetOrders();
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
return Ok(orders);
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
[Route("cardtypes")]
|
2016-11-21 12:41:36 +01:00
|
|
|
|
[HttpGet]
|
2016-11-24 14:58:37 +01:00
|
|
|
|
public async Task<IActionResult> GetCardTypes()
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2016-11-24 14:58:37 +01:00
|
|
|
|
var cardTypes = await _orderQueries.GetCardTypes();
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2016-11-24 14:58:37 +01:00
|
|
|
|
return Ok(cardTypes);
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|