standar names and fixed response for swagger apis
This commit is contained in:
parent
deb3d38ebe
commit
b8969e6746
@ -16,7 +16,6 @@ namespace OcelotApiGw
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
|
||||
private readonly IConfiguration _cfg;
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
@ -71,6 +70,7 @@ namespace OcelotApiGw
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
var pathBase = _cfg["PATH_BASE"];
|
||||
|
||||
if (!string.IsNullOrEmpty(pathBase))
|
||||
{
|
||||
app.UsePathBase(pathBase);
|
||||
|
@ -5,6 +5,7 @@ using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
@ -16,6 +17,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
{
|
||||
private readonly ICatalogService _catalog;
|
||||
private readonly IBasketService _basket;
|
||||
|
||||
public BasketController(ICatalogService catalogService, IBasketService basketService)
|
||||
{
|
||||
_catalog = catalogService;
|
||||
@ -24,22 +26,24 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
|
||||
[HttpPost]
|
||||
[HttpPut]
|
||||
public async Task<ActionResult<BasketData>> UpdateAllBasket([FromBody] UpdateBasketRequest data)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data)
|
||||
{
|
||||
|
||||
if (data.Items == null || !data.Items.Any())
|
||||
{
|
||||
return BadRequest("Need to pass at least one basket line");
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
var currentBasket = await _basket.GetById(data.BuyerId);
|
||||
var currentBasket = await _basket.GetByIdAsync(data.BuyerId);
|
||||
|
||||
if (currentBasket == null)
|
||||
{
|
||||
currentBasket = new BasketData(data.BuyerId);
|
||||
}
|
||||
|
||||
var catalogItems = await _catalog.GetCatalogItems(data.Items.Select(x => x.ProductId));
|
||||
var catalogItems = await _catalog.GetCatalogItemsAsync(data.Items.Select(x => x.ProductId));
|
||||
var newBasket = new BasketData(data.BuyerId);
|
||||
|
||||
foreach (var bitem in data.Items)
|
||||
@ -61,14 +65,16 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
await _basket.Update(newBasket);
|
||||
await _basket.UpdateAsync(newBasket);
|
||||
|
||||
return newBasket;
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Route("items")]
|
||||
public async Task<ActionResult<BasketData>> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<BasketData>> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data)
|
||||
{
|
||||
if (!data.Updates.Any())
|
||||
{
|
||||
@ -76,7 +82,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
var currentBasket = await _basket.GetById(data.BasketId);
|
||||
var currentBasket = await _basket.GetByIdAsync(data.BasketId);
|
||||
if (currentBasket == null)
|
||||
{
|
||||
return BadRequest($"Basket with id {data.BasketId} not found.");
|
||||
@ -86,22 +92,26 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
foreach (var update in data.Updates)
|
||||
{
|
||||
var basketItem = currentBasket.Items.SingleOrDefault(bitem => bitem.Id == update.BasketItemId);
|
||||
|
||||
if (basketItem == null)
|
||||
{
|
||||
return BadRequest($"Basket item with id {update.BasketItemId} not found");
|
||||
}
|
||||
|
||||
basketItem.Quantity = update.NewQty;
|
||||
}
|
||||
|
||||
// Save the updated basket
|
||||
await _basket.Update(currentBasket);
|
||||
await _basket.UpdateAsync(currentBasket);
|
||||
|
||||
return currentBasket;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("items")]
|
||||
public async Task<ActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult> AddBasketItemAsync([FromBody] AddBasketItemRequest data)
|
||||
{
|
||||
if (data == null || data.Quantity == 0)
|
||||
{
|
||||
@ -109,12 +119,12 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Step 1: Get the item from catalog
|
||||
var item = await _catalog.GetCatalogItem(data.CatalogItemId);
|
||||
var item = await _catalog.GetCatalogItemAsync(data.CatalogItemId);
|
||||
|
||||
//item.PictureUri =
|
||||
|
||||
// Step 2: Get current basket status
|
||||
var currentBasket = (await _basket.GetById(data.BasketId)) ?? new BasketData(data.BasketId);
|
||||
var currentBasket = (await _basket.GetByIdAsync(data.BasketId)) ?? new BasketData(data.BasketId);
|
||||
// Step 3: Merge current status with new product
|
||||
currentBasket.Items.Add(new BasketDataItem()
|
||||
{
|
||||
@ -127,7 +137,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
});
|
||||
|
||||
// Step 4: Update basket
|
||||
await _basket.Update(currentBasket);
|
||||
await _basket.UpdateAsync(currentBasket);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
@ -12,6 +14,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
{
|
||||
private readonly IBasketService _basketService;
|
||||
private readonly IOrderApiClient _orderClient;
|
||||
|
||||
public OrderController(IBasketService basketService, IOrderApiClient orderClient)
|
||||
{
|
||||
_basketService = basketService;
|
||||
@ -20,21 +23,23 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||
|
||||
[Route("draft/{basketId}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetOrderDraft(string basketId)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId)
|
||||
{
|
||||
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);
|
||||
var basket = await _basketService.GetByIdAsync(basketId);
|
||||
|
||||
if (basket == null)
|
||||
{
|
||||
return BadRequest($"No basket found for id {basketId}");
|
||||
}
|
||||
|
||||
var orderDraft = await _orderClient.GetOrderDraftFromBasket(basket);
|
||||
return Ok(orderDraft);
|
||||
return await _orderClient.GetOrderDraftFromBasketAsync(basket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<BasketData> GetById(string id)
|
||||
public async Task<BasketData> GetByIdAsync(string id)
|
||||
{
|
||||
var data = await _httpClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
||||
|
||||
@ -31,7 +31,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
return basket;
|
||||
}
|
||||
|
||||
public async Task Update(BasketData currentBasket)
|
||||
public async Task UpdateAsync(BasketData currentBasket)
|
||||
{
|
||||
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<CatalogItem> GetCatalogItem(int id)
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(int id)
|
||||
{
|
||||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id));
|
||||
var catalogItem = JsonConvert.DeserializeObject<CatalogItem>(stringContent);
|
||||
@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
return catalogItem;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids)
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids)
|
||||
{
|
||||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids));
|
||||
var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent);
|
||||
|
@ -1,15 +1,13 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<BasketData> GetById(string id);
|
||||
Task Update(BasketData currentBasket);
|
||||
Task<BasketData> GetByIdAsync(string id);
|
||||
|
||||
Task UpdateAsync(BasketData currentBasket);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public interface ICatalogService
|
||||
{
|
||||
Task<CatalogItem> GetCatalogItem(int id);
|
||||
Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids);
|
||||
Task<CatalogItem> GetCatalogItemAsync(int id);
|
||||
|
||||
Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
Task<OrderData> GetOrderDraftFromBasket(BasketData basket);
|
||||
Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<OrderData> GetOrderDraftFromBasket(BasketData basket)
|
||||
public async Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket)
|
||||
{
|
||||
var uri = _urls.Orders + UrlsConfig.OrdersOperations.GetOrderDraft();
|
||||
var content = new StringContent(JsonConvert.SerializeObject(basket), System.Text.Encoding.UTF8, "application/json");
|
||||
|
@ -127,12 +127,14 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
{
|
||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
|
||||
var identityUrl = configuration.GetValue<string>("urls:identity");
|
||||
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
|
||||
}).AddJwtBearer(options =>
|
||||
})
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.Authority = identityUrl;
|
||||
options.RequireHttpsMetadata = false;
|
||||
@ -150,6 +152,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddHttpServices(this IServiceCollection services)
|
||||
{
|
||||
//register delegating handlers
|
||||
@ -170,8 +173,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
.AddPolicyHandler(GetRetryPolicy())
|
||||
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
||||
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@ -181,7 +182,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
.HandleTransientHttpError()
|
||||
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
|
||||
}
|
||||
|
||||
private static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
|
||||
|
@ -5,6 +5,7 @@ using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
@ -16,6 +17,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
{
|
||||
private readonly ICatalogService _catalog;
|
||||
private readonly IBasketService _basket;
|
||||
|
||||
public BasketController(ICatalogService catalogService, IBasketService basketService)
|
||||
{
|
||||
_catalog = catalogService;
|
||||
@ -24,22 +26,23 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
|
||||
[HttpPost]
|
||||
[HttpPut]
|
||||
public async Task<ActionResult<BasketData>> UpdateAllBasket([FromBody] UpdateBasketRequest data)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<BasketData>> UpdateAllBasketAsync([FromBody] UpdateBasketRequest data)
|
||||
{
|
||||
|
||||
if (data.Items == null || !data.Items.Any())
|
||||
{
|
||||
return BadRequest("Need to pass at least one basket line");
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
var currentBasket = await _basket.GetById(data.BuyerId);
|
||||
var currentBasket = await _basket.GetByIdAsync(data.BuyerId);
|
||||
if (currentBasket == null)
|
||||
{
|
||||
currentBasket = new BasketData(data.BuyerId);
|
||||
}
|
||||
|
||||
var catalogItems = await _catalog.GetCatalogItems(data.Items.Select(x => x.ProductId));
|
||||
var catalogItems = await _catalog.GetCatalogItemsAsync(data.Items.Select(x => x.ProductId));
|
||||
var newBasket = new BasketData(data.BuyerId);
|
||||
|
||||
foreach (var bitem in data.Items)
|
||||
@ -61,14 +64,16 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
await _basket.Update(newBasket);
|
||||
await _basket.UpdateAsync(newBasket);
|
||||
|
||||
return newBasket;
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Route("items")]
|
||||
public async Task<ActionResult<BasketData>> UpdateQuantities([FromBody] UpdateBasketItemsRequest data)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(BasketData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<BasketData>> UpdateQuantitiesAsync([FromBody] UpdateBasketItemsRequest data)
|
||||
{
|
||||
if (!data.Updates.Any())
|
||||
{
|
||||
@ -76,7 +81,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
var currentBasket = await _basket.GetById(data.BasketId);
|
||||
var currentBasket = await _basket.GetByIdAsync(data.BasketId);
|
||||
if (currentBasket == null)
|
||||
{
|
||||
return BadRequest($"Basket with id {data.BasketId} not found.");
|
||||
@ -94,14 +99,16 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Save the updated basket
|
||||
await _basket.Update(currentBasket);
|
||||
await _basket.UpdateAsync(currentBasket);
|
||||
|
||||
return currentBasket;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("items")]
|
||||
public async Task<ActionResult> AddBasketItem([FromBody] AddBasketItemRequest data)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult> AddBasketItemAsync([FromBody] AddBasketItemRequest data)
|
||||
{
|
||||
if (data == null || data.Quantity == 0)
|
||||
{
|
||||
@ -109,12 +116,12 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Step 1: Get the item from catalog
|
||||
var item = await _catalog.GetCatalogItem(data.CatalogItemId);
|
||||
var item = await _catalog.GetCatalogItemAsync(data.CatalogItemId);
|
||||
|
||||
//item.PictureUri =
|
||||
|
||||
// Step 2: Get current basket status
|
||||
var currentBasket = (await _basket.GetById(data.BasketId)) ?? new BasketData(data.BasketId);
|
||||
var currentBasket = (await _basket.GetByIdAsync(data.BasketId)) ?? new BasketData(data.BasketId);
|
||||
// Step 3: Merge current status with new product
|
||||
currentBasket.Items.Add(new BasketDataItem()
|
||||
{
|
||||
@ -127,8 +134,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
});
|
||||
|
||||
// Step 4: Update basket
|
||||
await _basket.Update(currentBasket);
|
||||
|
||||
await _basket.UpdateAsync(currentBasket);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
@ -24,20 +25,23 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
|
||||
[Route("draft/{basketId}")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<OrderData>> GetOrderDraft(string basketId)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<OrderData>> GetOrderDraftAsync(string basketId)
|
||||
{
|
||||
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);
|
||||
var basket = await _basketService.GetByIdAsync(basketId);
|
||||
|
||||
if (basket == null)
|
||||
{
|
||||
return BadRequest($"No basket found for id {basketId}");
|
||||
}
|
||||
|
||||
return await _orderClient.GetOrderDraftFromBasket(basket);
|
||||
return await _orderClient.GetOrderDraftFromBasketAsync(basket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
|
||||
private readonly HttpClient _apiClient;
|
||||
private readonly ILogger<BasketService> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
@ -22,18 +21,19 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<BasketData> GetById(string id)
|
||||
public async Task<BasketData> GetByIdAsync(string id)
|
||||
{
|
||||
var data = await _apiClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
||||
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
||||
|
||||
return basket;
|
||||
}
|
||||
|
||||
public async Task Update(BasketData currentBasket)
|
||||
public async Task UpdateAsync(BasketData currentBasket)
|
||||
{
|
||||
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var data = await _apiClient.PostAsync(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket(), basketContent);
|
||||
await _apiClient.PostAsync(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket(), basketContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ILogger<CatalogService> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
@ -23,20 +22,18 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<CatalogItem> GetCatalogItem(int id)
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(int id)
|
||||
{
|
||||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id));
|
||||
var catalogItem = JsonConvert.DeserializeObject<CatalogItem>(stringContent);
|
||||
|
||||
return catalogItem;
|
||||
return JsonConvert.DeserializeObject<CatalogItem>(stringContent);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids)
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids)
|
||||
{
|
||||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids));
|
||||
var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent);
|
||||
|
||||
return catalogItems;
|
||||
return JsonConvert.DeserializeObject<CatalogItem[]>(stringContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<BasketData> GetById(string id);
|
||||
Task Update(BasketData currentBasket);
|
||||
Task<BasketData> GetByIdAsync(string id);
|
||||
|
||||
Task UpdateAsync(BasketData currentBasket);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public interface ICatalogService
|
||||
{
|
||||
Task<CatalogItem> GetCatalogItem(int id);
|
||||
Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids);
|
||||
Task<CatalogItem> GetCatalogItemAsync(int id);
|
||||
|
||||
Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
Task<OrderData> GetOrderDraftFromBasket(BasketData basket);
|
||||
Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class OrderApiClient : IOrderApiClient
|
||||
{
|
||||
|
||||
private readonly HttpClient _apiClient;
|
||||
private readonly ILogger<OrderApiClient> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
@ -22,7 +21,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<OrderData> GetOrderDraftFromBasket(BasketData basket)
|
||||
public async Task<OrderData> GetOrderDraftFromBasketAsync(BasketData basket)
|
||||
{
|
||||
var url = _urls.Orders + UrlsConfig.OrdersOperations.GetOrderDraft();
|
||||
var content = new StringContent(JsonConvert.SerializeObject(basket), System.Text.Encoding.UTF8, "application/json");
|
||||
|
@ -64,13 +64,12 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
app.UseHttpsRedirection();
|
||||
app.UseMvc();
|
||||
|
||||
app.UseSwagger().UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Purchase BFF V1");
|
||||
//c.ConfigureOAuth2("Microsoft.eShopOnContainers.Web.Shopping.HttpAggregatorwaggerui", "", "", "Purchase BFF Swagger UI");
|
||||
});
|
||||
|
||||
|
||||
app.UseSwagger()
|
||||
.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Purchase BFF V1");
|
||||
//c.ConfigureOAuth2("Microsoft.eShopOnContainers.Web.Shopping.HttpAggregatorwaggerui", "", "", "Purchase BFF Swagger UI");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,6 +104,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCustomMvc(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddOptions();
|
||||
@ -184,6 +184,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
|
||||
}
|
||||
|
||||
static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
|
||||
{
|
||||
return HttpPolicyExtensions
|
||||
|
@ -17,37 +17,28 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
public class BasketController : ControllerBase
|
||||
{
|
||||
private readonly IBasketRepository _repository;
|
||||
private readonly IIdentityService _identitySvc;
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public BasketController(IBasketRepository repository,
|
||||
IIdentityService identityService,
|
||||
IEventBus eventBus)
|
||||
public BasketController(IBasketRepository repository, IIdentityService identityService, IEventBus eventBus)
|
||||
{
|
||||
_repository = repository;
|
||||
_identitySvc = identityService;
|
||||
_identityService = identityService;
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
// GET /id
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<CustomerBasket>> Get(string id)
|
||||
public async Task<ActionResult<CustomerBasket>> GetBasketByIdAsync(string id)
|
||||
{
|
||||
var basket = await _repository.GetBasketAsync(id);
|
||||
|
||||
if (basket == null)
|
||||
{
|
||||
return new CustomerBasket(id);
|
||||
}
|
||||
|
||||
return basket;
|
||||
return basket ?? new CustomerBasket(id);
|
||||
}
|
||||
|
||||
// POST /value
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<CustomerBasket>> Post([FromBody]CustomerBasket value)
|
||||
public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody]CustomerBasket value)
|
||||
{
|
||||
return await _repository.UpdateBasketAsync(value);
|
||||
}
|
||||
@ -56,11 +47,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.Accepted)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<ActionResult> Checkout([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
public async Task<ActionResult> CheckoutAsync([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
{
|
||||
var userId = _identitySvc.GetUserIdentity();
|
||||
var userId = _identityService.GetUserIdentity();
|
||||
|
||||
|
||||
basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
|
||||
guid : basketCheckout.RequestId;
|
||||
|
||||
@ -80,16 +70,17 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
// Once basket is checkout, sends an integration event to
|
||||
// ordering.api to convert basket to order and proceeds with
|
||||
// order creation process
|
||||
_eventBus.Publish(eventMessage);
|
||||
_eventBus.Publish(eventMessage);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(string id)
|
||||
[ProducesResponseType(typeof(void), (int)HttpStatusCode.OK)]
|
||||
public async Task DeleteBasketByIdAsync(string id)
|
||||
{
|
||||
_repository.DeleteBasketAsync(id);
|
||||
await _repository.DeleteBasketAsync(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||
public class RedisBasketRepository : IBasketRepository
|
||||
{
|
||||
private readonly ILogger<RedisBasketRepository> _logger;
|
||||
|
||||
private readonly ConnectionMultiplexer _redis;
|
||||
private readonly IDatabase _database;
|
||||
|
||||
@ -30,12 +29,14 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||
{
|
||||
var server = GetServer();
|
||||
var data = server.Keys();
|
||||
|
||||
return data?.Select(k => k.ToString());
|
||||
}
|
||||
|
||||
public async Task<CustomerBasket> GetBasketAsync(string customerId)
|
||||
{
|
||||
var data = await _database.StringGetAsync(customerId);
|
||||
|
||||
if (data.IsNullOrEmpty)
|
||||
{
|
||||
return null;
|
||||
@ -47,6 +48,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||
public async Task<CustomerBasket> UpdateBasketAsync(CustomerBasket basket)
|
||||
{
|
||||
var created = await _database.StringSetAsync(basket.BuyerId, JsonConvert.SerializeObject(basket));
|
||||
|
||||
if (!created)
|
||||
{
|
||||
_logger.LogInformation("Problem occur persisting the item.");
|
||||
|
@ -44,7 +44,7 @@ namespace UnitTest.Basket.Application
|
||||
//Act
|
||||
var basketController = new BasketController(
|
||||
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
|
||||
var actionResult = await basketController.Get(fakeCustomerId);
|
||||
var actionResult = await basketController.GetBasketByIdAsync(fakeCustomerId);
|
||||
|
||||
//Assert
|
||||
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
@ -67,7 +67,7 @@ namespace UnitTest.Basket.Application
|
||||
var basketController = new BasketController(
|
||||
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
|
||||
|
||||
var actionResult = await basketController.Post(fakeCustomerBasket);
|
||||
var actionResult = await basketController.UpdateBasketAsync(fakeCustomerBasket);
|
||||
|
||||
//Assert
|
||||
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
@ -86,7 +86,7 @@ namespace UnitTest.Basket.Application
|
||||
var basketController = new BasketController(
|
||||
_basketRepositoryMock.Object, _identityServiceMock.Object, _serviceBusMock.Object);
|
||||
|
||||
var result = await basketController.Checkout(new BasketCheckout(), Guid.NewGuid().ToString()) as BadRequestResult;
|
||||
var result = await basketController.CheckoutAsync(new BasketCheckout(), Guid.NewGuid().ToString()) as BadRequestResult;
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ namespace UnitTest.Basket.Application
|
||||
};
|
||||
|
||||
//Act
|
||||
var result = await basketController.Checkout(new BasketCheckout(), Guid.NewGuid().ToString()) as AcceptedResult;
|
||||
var result = await basketController.CheckoutAsync(new BasketCheckout(), Guid.NewGuid().ToString()) as AcceptedResult;
|
||||
|
||||
_serviceBusMock.Verify(mock => mock.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>()), Times.Once);
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
_catalogIntegrationEventService = catalogIntegrationEventService ?? throw new ArgumentNullException(nameof(catalogIntegrationEventService));
|
||||
_settings = settings.Value;
|
||||
|
||||
((DbContext)context).ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/items[?pageSize=3&pageIndex=10]
|
||||
@ -36,11 +36,19 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
[Route("items")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(IEnumerable<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> Items([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0, [FromQuery] string ids = null)
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> ItemsAsync([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0, string ids = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ids))
|
||||
{
|
||||
return GetItemsByIds(ids);
|
||||
var items = await GetItemsByIdsAsync(ids);
|
||||
|
||||
if (!items.Any())
|
||||
{
|
||||
return BadRequest("ids value invalid. Must be comma-separated list of numbers");
|
||||
}
|
||||
|
||||
return Ok(items);
|
||||
}
|
||||
|
||||
var totalItems = await _catalogContext.CatalogItems
|
||||
@ -54,37 +62,36 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
itemsOnPage = ChangeUriPlaceholder(itemsOnPage);
|
||||
|
||||
var model = new PaginatedItemsViewModel<CatalogItem>(
|
||||
pageIndex, pageSize, totalItems, itemsOnPage);
|
||||
var model = new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
|
||||
|
||||
return Ok(model);
|
||||
}
|
||||
|
||||
private IActionResult GetItemsByIds(string ids)
|
||||
private async Task<List<CatalogItem>> GetItemsByIdsAsync(string ids)
|
||||
{
|
||||
var numIds = ids.Split(',')
|
||||
.Select(id => (Ok: int.TryParse(id, out int x), Value: x));
|
||||
var numIds = ids.Split(',').Select(id => (Ok: int.TryParse(id, out int x), Value: x));
|
||||
|
||||
if (!numIds.All(nid => nid.Ok))
|
||||
{
|
||||
return BadRequest("ids value invalid. Must be comma-separated list of numbers");
|
||||
return new List<CatalogItem>();
|
||||
}
|
||||
|
||||
var idsToSelect = numIds
|
||||
.Select(id => id.Value);
|
||||
|
||||
var items = _catalogContext.CatalogItems.Where(ci => idsToSelect.Contains(ci.Id)).ToList();
|
||||
var items = await _catalogContext.CatalogItems.Where(ci => idsToSelect.Contains(ci.Id)).ToListAsync();
|
||||
|
||||
items = ChangeUriPlaceholder(items);
|
||||
|
||||
return Ok(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("items/{id:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<CatalogItem>> GetItemById(int id)
|
||||
public async Task<ActionResult<CatalogItem>> ItemByIdAsync(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
{
|
||||
@ -95,6 +102,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
var baseUri = _settings.PicBaseUrl;
|
||||
var azureStorageEnabled = _settings.AzureStorageEnabled;
|
||||
|
||||
item.FillProductUrl(baseUri, azureStorageEnabled: azureStorageEnabled);
|
||||
|
||||
if (item != null)
|
||||
@ -107,9 +115,9 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
// GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]/withname/{name:minlength(1)}")]
|
||||
[Route("items/withname/{name:minlength(1)}")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> Items(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsWithNameAsync(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
var totalItems = await _catalogContext.CatalogItems
|
||||
.Where(c => c.Name.StartsWith(name))
|
||||
@ -123,14 +131,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
itemsOnPage = ChangeUriPlaceholder(itemsOnPage);
|
||||
|
||||
return new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
|
||||
return new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
|
||||
[Route("items/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> Items(int catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByTypeIdAndBrandIdAsync(int catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
||||
|
||||
@ -153,11 +161,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
return new PaginatedItemsViewModel<CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage);
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]/type/all/brand/{catalogBrandId:int?}")]
|
||||
[Route("items/type/all/brand/{catalogBrandId:int?}")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> Items(int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CatalogItem>>> ItemsByBrandIdAsync(int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems;
|
||||
|
||||
@ -181,18 +190,18 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
|
||||
// GET api/v1/[controller]/CatalogTypes
|
||||
[HttpGet]
|
||||
[Route("[action]")]
|
||||
[Route("catalogtypes")]
|
||||
[ProducesResponseType(typeof(List<CatalogType>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<List<CatalogType>>> CatalogTypes()
|
||||
public async Task<ActionResult<List<CatalogType>>> CatalogTypesAsync()
|
||||
{
|
||||
return await _catalogContext.CatalogTypes.ToListAsync();
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/CatalogBrands
|
||||
[HttpGet]
|
||||
[Route("[action]")]
|
||||
[Route("catalogbrands")]
|
||||
[ProducesResponseType(typeof(List<CatalogBrand>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<List<CatalogBrand>>> CatalogBrands()
|
||||
public async Task<ActionResult<List<CatalogBrand>>> CatalogBrandsAsync()
|
||||
{
|
||||
return await _catalogContext.CatalogBrands.ToListAsync();
|
||||
}
|
||||
@ -202,10 +211,9 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
[HttpPut]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<ActionResult> UpdateProduct([FromBody]CatalogItem productToUpdate)
|
||||
public async Task<ActionResult> UpdateProductAsync([FromBody]CatalogItem productToUpdate)
|
||||
{
|
||||
var catalogItem = await _catalogContext.CatalogItems
|
||||
.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
|
||||
var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id);
|
||||
|
||||
if (catalogItem == null)
|
||||
{
|
||||
@ -215,7 +223,6 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
var oldPrice = catalogItem.Price;
|
||||
var raiseProductPriceChangedEvent = oldPrice != productToUpdate.Price;
|
||||
|
||||
|
||||
// Update current product
|
||||
catalogItem = productToUpdate;
|
||||
_catalogContext.CatalogItems.Update(catalogItem);
|
||||
@ -236,14 +243,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
await _catalogContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return CreatedAtAction(nameof(GetItemById), new { id = productToUpdate.Id }, null);
|
||||
return CreatedAtAction(nameof(ItemByIdAsync), new { id = productToUpdate.Id }, null);
|
||||
}
|
||||
|
||||
//POST api/v1/[controller]/items
|
||||
[Route("items")]
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<ActionResult> CreateProduct([FromBody]CatalogItem product)
|
||||
public async Task<ActionResult> CreateProductAsync([FromBody]CatalogItem product)
|
||||
{
|
||||
var item = new CatalogItem
|
||||
{
|
||||
@ -254,18 +261,20 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
PictureFileName = product.PictureFileName,
|
||||
Price = product.Price
|
||||
};
|
||||
|
||||
_catalogContext.CatalogItems.Add(item);
|
||||
|
||||
await _catalogContext.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetItemById), new { id = item.Id }, null);
|
||||
return CreatedAtAction(nameof(ItemByIdAsync), new { id = item.Id }, null);
|
||||
}
|
||||
|
||||
//DELETE api/v1/[controller]/id
|
||||
[Route("{id}")]
|
||||
[HttpDelete]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
public async Task<ActionResult> DeleteProduct(int id)
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<ActionResult> DeleteProductAsync(int id)
|
||||
{
|
||||
var product = _catalogContext.CatalogItems.SingleOrDefault(x => x.Id == id);
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
// GET: /<controller>/
|
||||
public async Task<ActionResult> GetImage(int catalogItemId)
|
||||
public async Task<ActionResult> GetImageAsync(int catalogItemId)
|
||||
{
|
||||
if (catalogItemId <= 0)
|
||||
{
|
||||
|
@ -28,27 +28,27 @@ namespace Locations.API.Controllers
|
||||
[Route("user/{userId:guid}")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(UserLocation), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<UserLocation>> GetUserLocation(Guid userId)
|
||||
public async Task<ActionResult<UserLocation>> GetUserLocationAsync(Guid userId)
|
||||
{
|
||||
return await _locationsService.GetUserLocation(userId.ToString());
|
||||
return await _locationsService.GetUserLocationAsync(userId.ToString());
|
||||
}
|
||||
|
||||
//GET api/v1/[controller]/
|
||||
[Route("")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>> GetAllLocations()
|
||||
public async Task<ActionResult<List<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>>> GetAllLocationsAsync()
|
||||
{
|
||||
return await _locationsService.GetAllLocation();
|
||||
return await _locationsService.GetAllLocationAsync();
|
||||
}
|
||||
|
||||
//GET api/v1/[controller]/1
|
||||
[Route("{locationId}")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>> GetLocation(int locationId)
|
||||
public async Task<ActionResult<Microsoft.eShopOnContainers.Services.Locations.API.Model.Locations>> GetLocationAsync(int locationId)
|
||||
{
|
||||
return await _locationsService.GetLocation(locationId);
|
||||
return await _locationsService.GetLocationAsync(locationId);
|
||||
}
|
||||
|
||||
//POST api/v1/[controller]/
|
||||
@ -56,14 +56,17 @@ namespace Locations.API.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> CreateOrUpdateUserLocation([FromBody]LocationRequest newLocReq)
|
||||
public async Task<ActionResult> CreateOrUpdateUserLocationAsync([FromBody]LocationRequest newLocReq)
|
||||
{
|
||||
var userId = _identityService.GetUserIdentity();
|
||||
var result = await _locationsService.AddOrUpdateUserLocation(userId, newLocReq);
|
||||
|
||||
return result ?
|
||||
(IActionResult)Ok() :
|
||||
(IActionResult)BadRequest();
|
||||
var result = await _locationsService.AddOrUpdateUserLocationAsync(userId, newLocReq);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@
|
||||
|
||||
public interface ILocationsService
|
||||
{
|
||||
Task<Locations> GetLocation(int locationId);
|
||||
Task<Locations> GetLocationAsync(int locationId);
|
||||
|
||||
Task<UserLocation> GetUserLocation(string id);
|
||||
Task<UserLocation> GetUserLocationAsync(string id);
|
||||
|
||||
Task<List<Locations>> GetAllLocation();
|
||||
Task<List<Locations>> GetAllLocationAsync();
|
||||
|
||||
Task<bool> AddOrUpdateUserLocation(string userId, LocationRequest locRequest);
|
||||
Task<bool> AddOrUpdateUserLocationAsync(string userId, LocationRequest locRequest);
|
||||
}
|
||||
}
|
||||
|
@ -21,22 +21,22 @@
|
||||
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
|
||||
}
|
||||
|
||||
public async Task<Locations> GetLocation(int locationId)
|
||||
public async Task<Locations> GetLocationAsync(int locationId)
|
||||
{
|
||||
return await _locationsRepository.GetAsync(locationId);
|
||||
}
|
||||
|
||||
public async Task<UserLocation> GetUserLocation(string userId)
|
||||
public async Task<UserLocation> GetUserLocationAsync(string userId)
|
||||
{
|
||||
return await _locationsRepository.GetUserLocationAsync(userId);
|
||||
}
|
||||
|
||||
public async Task<List<Locations>> GetAllLocation()
|
||||
public async Task<List<Locations>> GetAllLocationAsync()
|
||||
{
|
||||
return await _locationsRepository.GetLocationListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddOrUpdateUserLocation(string userId, LocationRequest currentPosition)
|
||||
public async Task<bool> AddOrUpdateUserLocationAsync(string userId, LocationRequest currentPosition)
|
||||
{
|
||||
// Get the list of ordered regions the user currently is within
|
||||
var currentUserAreaLocationList = await _locationsRepository.GetCurrentUserRegionsListAsync(currentPosition);
|
||||
|
@ -41,7 +41,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(List<CampaignDTO>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<List<CampaignDTO>>> GetAllCampaigns()
|
||||
public async Task<ActionResult<List<CampaignDTO>>> GetAllCampaignsAsync()
|
||||
{
|
||||
var campaignList = await _context.Campaigns.ToListAsync();
|
||||
|
||||
@ -56,10 +56,9 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
[HttpGet("{id:int}")]
|
||||
[ProducesResponseType(typeof(CampaignDTO), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<ActionResult<CampaignDTO>> GetCampaignById(int id)
|
||||
public async Task<ActionResult<CampaignDTO>> GetCampaignByIdAsync(int id)
|
||||
{
|
||||
var campaign = await _context.Campaigns
|
||||
.SingleOrDefaultAsync(c => c.Id == id);
|
||||
var campaign = await _context.Campaigns.SingleOrDefaultAsync(c => c.Id == id);
|
||||
|
||||
if (campaign is null)
|
||||
{
|
||||
@ -72,7 +71,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<ActionResult> CreateCampaign([FromBody] CampaignDTO campaignDto)
|
||||
public async Task<ActionResult> CreateCampaignAsync([FromBody] CampaignDTO campaignDto)
|
||||
{
|
||||
if (campaignDto is null)
|
||||
{
|
||||
@ -84,14 +83,14 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
await _context.Campaigns.AddAsync(campaign);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetCampaignById), new { id = campaign.Id }, null);
|
||||
return CreatedAtAction(nameof(GetCampaignByIdAsync), new { id = campaign.Id }, null);
|
||||
}
|
||||
|
||||
[HttpPut("{id:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<ActionResult> UpdateCampaign(int id, [FromBody] CampaignDTO campaignDto)
|
||||
public async Task<ActionResult> UpdateCampaignAsync(int id, [FromBody] CampaignDTO campaignDto)
|
||||
{
|
||||
if (id < 1 || campaignDto is null)
|
||||
{
|
||||
@ -112,14 +111,14 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return CreatedAtAction(nameof(GetCampaignById), new { id = campaignToUpdate.Id }, null);
|
||||
return CreatedAtAction(nameof(GetCampaignByIdAsync), new { id = campaignToUpdate.Id }, null);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NoContent)]
|
||||
public async Task<ActionResult> Delete(int id)
|
||||
public async Task<ActionResult> DeleteCampaignByIdAsync(int id)
|
||||
{
|
||||
if (id < 1)
|
||||
{
|
||||
@ -127,6 +126,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
}
|
||||
|
||||
var campaignToDelete = await _context.Campaigns.FindAsync(id);
|
||||
|
||||
if (campaignToDelete is null)
|
||||
{
|
||||
return NotFound();
|
||||
@ -140,7 +140,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
|
||||
[HttpGet("user")]
|
||||
[ProducesResponseType(typeof(PaginatedItemsViewModel<CampaignDTO>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CampaignDTO>>> GetCampaignsByUserId( int pageSize = 10, int pageIndex = 0)
|
||||
public async Task<ActionResult<PaginatedItemsViewModel<CampaignDTO>>> GetCampaignsByUserIdAsync( int pageSize = 10, int pageIndex = 0)
|
||||
{
|
||||
var userId = _identityService.GetUserIdentity();
|
||||
|
||||
@ -165,10 +165,10 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
var userCampaignDtoList = MapCampaignModelListToDtoList(userCampaignList);
|
||||
campaignDtoList.AddRange(userCampaignDtoList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var totalItems = campaignDtoList.Count();
|
||||
|
||||
campaignDtoList = campaignDtoList
|
||||
.Skip(pageSize * pageIndex)
|
||||
.Take(pageSize).ToList();
|
||||
@ -176,7 +176,6 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
return new PaginatedItemsViewModel<CampaignDTO>(pageIndex, pageSize, totalItems, campaignDtoList);
|
||||
}
|
||||
|
||||
|
||||
private List<CampaignDTO> MapCampaignModelListToDtoList(List<Campaign> campaignList)
|
||||
{
|
||||
var campaignDtoList = new List<CampaignDTO>();
|
||||
|
@ -75,7 +75,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
[Route("api/v1/campaigns/{campaignId:int}/locations")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.Created)]
|
||||
public async Task<ActionResult> CreateLocation(int campaignId, [FromBody] UserLocationRuleDTO locationRuleDto)
|
||||
public async Task<ActionResult> CreateLocationAsync(int campaignId, [FromBody] UserLocationRuleDTO locationRuleDto)
|
||||
{
|
||||
if (campaignId < 1 || locationRuleDto is null)
|
||||
{
|
||||
@ -96,7 +96,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
[Route("api/v1/campaigns/{campaignId:int}/locations/{userLocationRuleId:int}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<ActionResult> DeleteLocationById(int campaignId, int userLocationRuleId)
|
||||
public async Task<ActionResult> DeleteLocationByIdAsync(int campaignId, int userLocationRuleId)
|
||||
{
|
||||
if (campaignId < 1 || userLocationRuleId < 1)
|
||||
{
|
||||
@ -118,8 +118,6 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<UserLocationRuleDTO> MapUserLocationRuleModelListToDtoList(List<UserLocationRule> userLocationRuleList)
|
||||
{
|
||||
var userLocationRuleDtoList = new List<UserLocationRuleDTO>();
|
||||
|
@ -23,7 +23,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
|
||||
public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentityService identityService)
|
||||
{
|
||||
|
||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||
_orderQueries = orderQueries ?? throw new ArgumentNullException(nameof(orderQueries));
|
||||
_identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
|
||||
@ -33,41 +32,51 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
[HttpPut]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> CancelOrder([FromBody]CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
public async Task<IActionResult> CancelOrderAsync([FromBody]CancelOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
{
|
||||
bool commandResult = false;
|
||||
|
||||
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
|
||||
{
|
||||
var requestCancelOrder = new IdentifiedCommand<CancelOrderCommand, bool>(command, guid);
|
||||
commandResult = await _mediator.Send(requestCancelOrder);
|
||||
}
|
||||
|
||||
return commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest();
|
||||
|
||||
if (!commandResult)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[Route("ship")]
|
||||
[HttpPut]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> ShipOrder([FromBody]ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
public async Task<IActionResult> ShipOrderAsync([FromBody]ShipOrderCommand command, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
{
|
||||
bool commandResult = false;
|
||||
|
||||
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
|
||||
{
|
||||
var requestShipOrder = new IdentifiedCommand<ShipOrderCommand, bool>(command, guid);
|
||||
commandResult = await _mediator.Send(requestShipOrder);
|
||||
}
|
||||
|
||||
return commandResult ? (IActionResult)Ok() : (IActionResult)BadRequest();
|
||||
if (!commandResult)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[Route("{orderId:int}")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(Order),(int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<ActionResult> GetOrder(int orderId)
|
||||
public async Task<ActionResult> GetOrderAsync(int orderId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -75,40 +84,37 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
|
||||
return Ok(order);
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
catch
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[Route("")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<OrderSummary>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<IEnumerable<OrderSummary>>> GetOrders()
|
||||
public async Task<ActionResult<IEnumerable<OrderSummary>>> GetOrdersAsync()
|
||||
{
|
||||
var userid = _identityService.GetUserIdentity();
|
||||
var orders = await _orderQueries.GetOrdersFromUserAsync(Guid.Parse(userid));
|
||||
|
||||
return Ok(orders);
|
||||
}
|
||||
|
||||
[Route("cardtypes")]
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<CardType>), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<IEnumerable<CardType>>> GetCardTypes()
|
||||
public async Task<ActionResult<IEnumerable<CardType>>> GetCardTypesAsync()
|
||||
{
|
||||
var cardTypes = await _orderQueries
|
||||
.GetCardTypesAsync();
|
||||
var cardTypes = await _orderQueries.GetCardTypesAsync();
|
||||
|
||||
return Ok(cardTypes);
|
||||
}
|
||||
}
|
||||
|
||||
[Route("draft")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<OrderDraftDTO>> GetOrderDraftFromBasketData([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
|
||||
public async Task<ActionResult<OrderDraftDTO>> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
|
||||
{
|
||||
return await _mediator.Send(createOrderDraftCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -36,7 +36,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.CancelOrder(new CancelOrderCommand(1), Guid.NewGuid().ToString()) as OkResult;
|
||||
var actionResult = await orderController.CancelOrderAsync(new CancelOrderCommand(1), Guid.NewGuid().ToString()) as OkResult;
|
||||
|
||||
//Assert
|
||||
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
@ -52,7 +52,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.CancelOrder(new CancelOrderCommand(1), String.Empty) as BadRequestResult;
|
||||
var actionResult = await orderController.CancelOrderAsync(new CancelOrderCommand(1), String.Empty) as BadRequestResult;
|
||||
|
||||
//Assert
|
||||
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
|
||||
@ -67,7 +67,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.ShipOrder(new ShipOrderCommand(1), Guid.NewGuid().ToString()) as OkResult;
|
||||
var actionResult = await orderController.ShipOrderAsync(new ShipOrderCommand(1), Guid.NewGuid().ToString()) as OkResult;
|
||||
|
||||
//Assert
|
||||
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
@ -83,7 +83,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.ShipOrder(new ShipOrderCommand(1), String.Empty) as BadRequestResult;
|
||||
var actionResult = await orderController.ShipOrderAsync(new ShipOrderCommand(1), String.Empty) as BadRequestResult;
|
||||
|
||||
//Assert
|
||||
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.BadRequest);
|
||||
@ -103,7 +103,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.GetOrders();
|
||||
var actionResult = await orderController.GetOrdersAsync();
|
||||
|
||||
//Assert
|
||||
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
@ -120,7 +120,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.GetOrder(fakeOrderId) as OkObjectResult;
|
||||
var actionResult = await orderController.GetOrderAsync(fakeOrderId) as OkObjectResult;
|
||||
|
||||
//Assert
|
||||
Assert.Equal(actionResult.StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
@ -136,7 +136,7 @@ namespace UnitTest.Ordering.Application
|
||||
|
||||
//Act
|
||||
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object);
|
||||
var actionResult = await orderController.GetCardTypes();
|
||||
var actionResult = await orderController.GetCardTypesAsync();
|
||||
|
||||
//Assert
|
||||
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
|
||||
|
Loading…
x
Reference in New Issue
Block a user