@ -1,18 +1,14 @@ | |||
using Microsoft.AspNetCore.Mvc; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers | |||
{ | |||
[Route("")] | |||
public class HomeController : Controller | |||
{ | |||
[HttpGet()] | |||
public IActionResult Index() | |||
{ | |||
return new RedirectResult("~/swagger"); | |||
} | |||
} | |||
[Route("")] | |||
public class HomeController : Controller | |||
{ | |||
[HttpGet()] | |||
public IActionResult Index() | |||
{ | |||
return new RedirectResult("~/swagger"); | |||
} | |||
} | |||
} |
@ -1,42 +1,39 @@ | |||
using Microsoft.AspNetCore.Authorization; | |||
using Microsoft.AspNetCore.Mvc; | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers | |||
{ | |||
[Route("api/v1/[controller]")] | |||
[Authorize] | |||
public class OrderController : Controller | |||
{ | |||
private readonly IBasketService _basketService; | |||
private readonly IOrderApiClient _orderClient; | |||
public OrderController(IBasketService basketService, IOrderApiClient orderClient) | |||
{ | |||
_basketService = basketService; | |||
_orderClient = orderClient; | |||
} | |||
[Route("api/v1/[controller]")] | |||
[Authorize] | |||
public class OrderController : Controller | |||
{ | |||
private readonly IBasketService _basketService; | |||
private readonly IOrderApiClient _orderClient; | |||
public OrderController(IBasketService basketService, IOrderApiClient orderClient) | |||
{ | |||
_basketService = basketService; | |||
_orderClient = orderClient; | |||
} | |||
[Route("draft/{basketId}")] | |||
[HttpGet] | |||
public async Task<IActionResult> GetOrderDraft(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); | |||
if (basket == null) | |||
{ | |||
return BadRequest($"No basket found for id {basketId}"); | |||
} | |||
[Route("draft/{basketId}")] | |||
[HttpGet] | |||
public async Task<IActionResult> GetOrderDraft(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); | |||
if (basket == null) | |||
{ | |||
return BadRequest($"No basket found for id {basketId}"); | |||
} | |||
var orderDraft = await _orderClient.GetOrderDraftFromBasket(basket); | |||
return Ok(orderDraft); | |||
} | |||
} | |||
var orderDraft = await _orderClient.GetOrderDraftFromBasket(basket); | |||
return Ok(orderDraft); | |||
} | |||
} | |||
} |
@ -1,33 +1,35 @@ | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Filters | |||
{ | |||
using Microsoft.AspNetCore.Authorization; | |||
using Swashbuckle.AspNetCore.Swagger; | |||
using Swashbuckle.AspNetCore.SwaggerGen; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using Microsoft.AspNetCore.Authorization; | |||
using Swashbuckle.AspNetCore.Swagger; | |||
using Swashbuckle.AspNetCore.SwaggerGen; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
namespace Basket.API.Infrastructure.Filters | |||
{ | |||
public class AuthorizeCheckOperationFilter : IOperationFilter | |||
{ | |||
public void Apply(Operation operation, OperationFilterContext context) | |||
{ | |||
// Check for authorize attribute | |||
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || | |||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); | |||
namespace Basket.API.Infrastructure.Filters | |||
{ | |||
public class AuthorizeCheckOperationFilter : IOperationFilter | |||
{ | |||
public void Apply(Operation operation, OperationFilterContext context) | |||
{ | |||
// Check for authorize attribute | |||
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || | |||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); | |||
if (hasAuthorize) | |||
{ | |||
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); | |||
operation.Responses.Add("403", new Response { Description = "Forbidden" }); | |||
if (hasAuthorize) | |||
{ | |||
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); | |||
operation.Responses.Add("403", new Response { Description = "Forbidden" }); | |||
operation.Security = new List<IDictionary<string, IEnumerable<string>>>(); | |||
operation.Security.Add(new Dictionary<string, IEnumerable<string>> | |||
{ | |||
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } } | |||
}); | |||
} | |||
} | |||
} | |||
} | |||
operation.Security = new List<IDictionary<string, IEnumerable<string>>> | |||
{ | |||
new Dictionary<string, IEnumerable<string>> | |||
{ | |||
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } } | |||
} | |||
}; | |||
} | |||
} | |||
} | |||
} | |||
} |
@ -1,31 +1,28 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
{ | |||
public class BasketData | |||
{ | |||
public string BuyerId { get; set; } | |||
public List<BasketDataItem> Items { get; set; } | |||
public class BasketData | |||
{ | |||
public string BuyerId { get; set; } | |||
public IList<BasketDataItem> Items { get; set; } | |||
public BasketData(string buyerId) | |||
{ | |||
BuyerId = buyerId; | |||
Items = new List<BasketDataItem>(); | |||
} | |||
} | |||
public BasketData(string buyerId) | |||
{ | |||
BuyerId = buyerId; | |||
Items = new List<BasketDataItem>(); | |||
} | |||
} | |||
public class BasketDataItem | |||
{ | |||
public string Id { get; set; } | |||
public string ProductId { get; set; } | |||
public string ProductName { get; set; } | |||
public decimal UnitPrice { get; set; } | |||
public decimal OldUnitPrice { get; set; } | |||
public int Quantity { get; set; } | |||
public string PictureUrl { get; set; } | |||
public class BasketDataItem | |||
{ | |||
public string Id { get; set; } | |||
public string ProductId { get; set; } | |||
public string ProductName { get; set; } | |||
public decimal UnitPrice { get; set; } | |||
public decimal OldUnitPrice { get; set; } | |||
public int Quantity { get; set; } | |||
public string PictureUrl { get; set; } | |||
} | |||
} | |||
} |
@ -1,20 +1,15 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
{ | |||
public class CatalogItem | |||
{ | |||
public int Id { get; set; } | |||
public class CatalogItem | |||
{ | |||
public int Id { get; set; } | |||
public string Name { get; set; } | |||
public string Name { get; set; } | |||
public decimal Price { get; set; } | |||
public decimal Price { get; set; } | |||
public string PictureUri { get; set; } | |||
public string PictureUri { get; set; } | |||
} | |||
} | |||
} |
@ -1,33 +1,31 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
using DateTime = System.DateTime; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
{ | |||
public class OrderData | |||
{ | |||
public string OrderNumber { get; set; } | |||
public DateTime Date { get; set; } | |||
public string Status { get; set; } | |||
public decimal Total { get; set; } | |||
public string Description { get; set; } | |||
public string City { get; set; } | |||
public string Street { get; set; } | |||
public string State { get; set; } | |||
public string Country { get; set; } | |||
public string ZipCode { get; set; } | |||
public string CardNumber { get; set; } | |||
public string CardHolderName { get; set; } | |||
public bool IsDraft { get; set; } | |||
public DateTime CardExpiration { get; set; } | |||
public string CardExpirationShort { get; set; } | |||
public string CardSecurityNumber { get; set; } | |||
public class OrderData | |||
{ | |||
public string OrderNumber { get; set; } | |||
public DateTime Date { get; set; } | |||
public string Status { get; set; } | |||
public decimal Total { get; set; } | |||
public string Description { get; set; } | |||
public string City { get; set; } | |||
public string Street { get; set; } | |||
public string State { get; set; } | |||
public string Country { get; set; } | |||
public string ZipCode { get; set; } | |||
public string CardNumber { get; set; } | |||
public string CardHolderName { get; set; } | |||
public bool IsDraft { get; set; } | |||
public DateTime CardExpiration { get; set; } | |||
public string CardExpirationShort { get; set; } | |||
public string CardSecurityNumber { get; set; } | |||
public int CardTypeId { get; set; } | |||
public int CardTypeId { get; set; } | |||
public string Buyer { get; set; } | |||
public string Buyer { get; set; } | |||
public List<OrderItemData> OrderItems { get; } = new List<OrderItemData>(); | |||
} | |||
public IList<OrderItemData> OrderItems { get; } = new List<OrderItemData>(); | |||
} | |||
} |
@ -1,17 +1,12 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
{ | |||
public class OrderItemData | |||
{ | |||
public int ProductId { get; set; } | |||
public string ProductName { get; set; } | |||
public decimal UnitPrice { get; set; } | |||
public decimal Discount { get; set; } | |||
public int Units { get; set; } | |||
public string PictureUrl { get; set; } | |||
} | |||
public class OrderItemData | |||
{ | |||
public int ProductId { get; set; } | |||
public string ProductName { get; set; } | |||
public decimal UnitPrice { get; set; } | |||
public decimal Discount { get; set; } | |||
public int Units { get; set; } | |||
public string PictureUrl { get; set; } | |||
} | |||
} |
@ -1,31 +1,28 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
{ | |||
public class UpdateBasketItemsRequest | |||
{ | |||
public string BasketId { get; set; } | |||
public class UpdateBasketItemsRequest | |||
{ | |||
public ICollection<UpdateBasketItemData> Updates { get; set; } | |||
public string BasketId { get; set; } | |||
public UpdateBasketItemsRequest() | |||
{ | |||
Updates = new List<UpdateBasketItemData>(); | |||
} | |||
} | |||
public ICollection<UpdateBasketItemData> Updates { get; set; } | |||
public class UpdateBasketItemData | |||
{ | |||
public string BasketItemId { get; set; } | |||
public int NewQty { get; set; } | |||
public UpdateBasketItemsRequest() | |||
{ | |||
Updates = new List<UpdateBasketItemData>(); | |||
} | |||
} | |||
public UpdateBasketItemData() | |||
{ | |||
NewQty = 0; | |||
} | |||
} | |||
public class UpdateBasketItemData | |||
{ | |||
public string BasketItemId { get; set; } | |||
public int NewQty { get; set; } | |||
public UpdateBasketItemData() | |||
{ | |||
NewQty = 0; | |||
} | |||
} | |||
} |
@ -1,21 +1,18 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models | |||
{ | |||
public class UpdateBasketRequest | |||
{ | |||
public string BuyerId { get; set; } | |||
public class UpdateBasketRequest | |||
{ | |||
public string BuyerId { get; set; } | |||
public IEnumerable<UpdateBasketRequestItemData> Items { get; set; } | |||
} | |||
public IEnumerable<UpdateBasketRequestItemData> Items { get; set; } | |||
} | |||
public class UpdateBasketRequestItemData | |||
{ | |||
public string Id { get; set; } // Basket id | |||
public int ProductId { get; set; } // Catalog item id | |||
public int Quantity { get; set; } // Quantity | |||
} | |||
public class UpdateBasketRequestItemData | |||
{ | |||
public string Id { get; set; } // Basket id | |||
public int ProductId { get; set; } // Catalog item id | |||
public int Quantity { get; set; } // Quantity | |||
} | |||
} |
@ -1,36 +1,31 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.Logging; | |||
using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions; | |||
using static Microsoft.AspNetCore.Hosting.WebHostExtensions; | |||
using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost; | |||
using WebHost = Microsoft.AspNetCore.WebHost; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator | |||
{ | |||
public class Program | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
BuildWebHost(args).Run(); | |||
} | |||
public class Program | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
BuildWebHost(args).Run(); | |||
} | |||
public static IWebHost BuildWebHost(string[] args) => | |||
WebHost | |||
.CreateDefaultBuilder(args) | |||
.ConfigureAppConfiguration(cb => | |||
{ | |||
var sources = cb.Sources; | |||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() | |||
{ | |||
Optional = true, | |||
Path = "appsettings.localhost.json", | |||
ReloadOnChange = false | |||
}); | |||
}) | |||
.UseStartup<Startup>() | |||
.Build(); | |||
} | |||
public static IWebHost BuildWebHost(string[] args) => | |||
WebHost | |||
.CreateDefaultBuilder(args) | |||
.ConfigureAppConfiguration(cb => | |||
{ | |||
var sources = cb.Sources; | |||
sources.Insert(3, new Extensions.Configuration.Json.JsonConfigurationSource() | |||
{ | |||
Optional = true, | |||
Path = "appsettings.localhost.json", | |||
ReloadOnChange = false | |||
}); | |||
}) | |||
.UseStartup<Startup>() | |||
.Build(); | |||
} | |||
} |
@ -1,41 +1,45 @@ | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Options; | |||
using Newtonsoft.Json; | |||
using System.Net.Http; | |||
using System.Threading.Tasks; | |||
using Encoding = System.Text.Encoding; | |||
using HttpClient = System.Net.Http.HttpClient; | |||
using JsonConvert = Newtonsoft.Json.JsonConvert; | |||
using StringContent = System.Net.Http.StringContent; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services | |||
{ | |||
public class BasketService : IBasketService | |||
{ | |||
using BasketData = Models.BasketData; | |||
using BasketOperations = Config.UrlsConfig.BasketOperations; | |||
using UrlsConfig = Config.UrlsConfig; | |||
private readonly HttpClient _httpClient; | |||
private readonly ILogger<BasketService> _logger; | |||
private readonly UrlsConfig _urls; | |||
public class BasketService : IBasketService | |||
{ | |||
public BasketService(HttpClient httpClient, ILogger<BasketService> logger, IOptions<UrlsConfig> config) | |||
{ | |||
_httpClient = httpClient; | |||
_logger = logger; | |||
_urls = config.Value; | |||
} | |||
private readonly HttpClient _httpClient; | |||
private readonly ILogger<BasketService> _logger; | |||
private readonly UrlsConfig _urls; | |||
public async Task<BasketData> GetById(string id) | |||
{ | |||
var data = await _httpClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id)); | |||
public BasketService(HttpClient httpClient, ILogger<BasketService> logger, IOptions<UrlsConfig> config) | |||
{ | |||
_httpClient = httpClient; | |||
_logger = logger; | |||
_urls = config.Value; | |||
} | |||
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null; | |||
public async Task<BasketData> GetById(string id) | |||
{ | |||
var data = await _httpClient.GetStringAsync(_urls.Basket + BasketOperations.GetItemById(id)); | |||
return basket; | |||
} | |||
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null; | |||
public async Task Update(BasketData currentBasket) | |||
{ | |||
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), System.Text.Encoding.UTF8, "application/json"); | |||
return basket; | |||
} | |||
var data = await _httpClient.PostAsync(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket(), basketContent); | |||
} | |||
} | |||
public async Task Update(BasketData currentBasket) | |||
{ | |||
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), Encoding.UTF8, "application/json"); | |||
var data = await _httpClient.PostAsync(_urls.Basket + BasketOperations.UpdateBasket(), basketContent); | |||
} | |||
} | |||
} |
@ -1,41 +1,43 @@ | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Options; | |||
using Newtonsoft.Json; | |||
using System.Collections.Generic; | |||
using System.Net.Http; | |||
using System.Threading.Tasks; | |||
using HttpClient = System.Net.Http.HttpClient; | |||
using JsonConvert = Newtonsoft.Json.JsonConvert; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services | |||
{ | |||
public class CatalogService : ICatalogService | |||
{ | |||
private readonly HttpClient _httpClient; | |||
private readonly ILogger<CatalogService> _logger; | |||
private readonly UrlsConfig _urls; | |||
using CatalogItem = Models.CatalogItem; | |||
using CatalogOperations = Config.UrlsConfig.CatalogOperations; | |||
using UrlsConfig = Config.UrlsConfig; | |||
public CatalogService(HttpClient httpClient, ILogger<CatalogService> logger, IOptions<UrlsConfig> config) | |||
{ | |||
_httpClient = httpClient; | |||
_logger = logger; | |||
_urls = config.Value; | |||
} | |||
public class CatalogService : ICatalogService | |||
{ | |||
private readonly HttpClient _httpClient; | |||
private readonly ILogger<CatalogService> _logger; | |||
private readonly UrlsConfig _urls; | |||
public async Task<CatalogItem> GetCatalogItem(int id) | |||
{ | |||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id)); | |||
var catalogItem = JsonConvert.DeserializeObject<CatalogItem>(stringContent); | |||
public CatalogService(HttpClient httpClient, ILogger<CatalogService> logger, IOptions<UrlsConfig> config) | |||
{ | |||
_httpClient = httpClient; | |||
_logger = logger; | |||
_urls = config.Value; | |||
} | |||
return catalogItem; | |||
} | |||
public async Task<CatalogItem> GetCatalogItem(int id) | |||
{ | |||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + CatalogOperations.GetItemById(id)); | |||
var catalogItem = JsonConvert.DeserializeObject<CatalogItem>(stringContent); | |||
public async Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids) | |||
{ | |||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids)); | |||
var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent); | |||
return catalogItem; | |||
} | |||
return catalogItems; | |||
} | |||
} | |||
public async Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids) | |||
{ | |||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + CatalogOperations.GetItemsById(ids)); | |||
var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent); | |||
return catalogItems; | |||
} | |||
} | |||
} |
@ -1,15 +1,13 @@ | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services | |||
{ | |||
public interface IBasketService | |||
{ | |||
Task<BasketData> GetById(string id); | |||
Task Update(BasketData currentBasket); | |||
using BasketData = Models.BasketData; | |||
} | |||
public interface IBasketService | |||
{ | |||
Task<BasketData> GetById(string id); | |||
Task Update(BasketData currentBasket); | |||
} | |||
} |
@ -1,14 +1,13 @@ | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Collections.Generic; | |||
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); | |||
} | |||
using CatalogItem = Models.CatalogItem; | |||
public interface ICatalogService | |||
{ | |||
Task<CatalogItem> GetCatalogItem(int id); | |||
Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids); | |||
} | |||
} |
@ -1,13 +1,12 @@ | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services | |||
{ | |||
public interface IOrderApiClient | |||
{ | |||
Task<OrderData> GetOrderDraftFromBasket(BasketData basket); | |||
} | |||
using BasketData = Models.BasketData; | |||
using OrderData = Models.OrderData; | |||
public interface IOrderApiClient | |||
{ | |||
Task<OrderData> GetOrderDraftFromBasket(BasketData basket); | |||
} | |||
} |
@ -1,37 +1,42 @@ | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config; | |||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.Extensions.Options; | |||
using Newtonsoft.Json; | |||
using System.Net.Http; | |||
using System.Threading.Tasks; | |||
using Encoding = System.Text.Encoding; | |||
using HttpClient = System.Net.Http.HttpClient; | |||
using JsonConvert = Newtonsoft.Json.JsonConvert; | |||
using StringContent = System.Net.Http.StringContent; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services | |||
{ | |||
public class OrderApiClient : IOrderApiClient | |||
{ | |||
private readonly HttpClient _apiClient; | |||
private readonly ILogger<OrderApiClient> _logger; | |||
private readonly UrlsConfig _urls; | |||
using BasketData = Models.BasketData; | |||
using OrdersOperations = Config.UrlsConfig.OrdersOperations; | |||
using OrderData = Models.OrderData; | |||
using UrlsConfig = Config.UrlsConfig; | |||
public OrderApiClient(HttpClient httpClient, ILogger<OrderApiClient> logger, IOptions<UrlsConfig> config) | |||
{ | |||
_apiClient = httpClient; | |||
_logger = logger; | |||
_urls = config.Value; | |||
} | |||
public class OrderApiClient : IOrderApiClient | |||
{ | |||
private readonly HttpClient _apiClient; | |||
private readonly ILogger<OrderApiClient> _logger; | |||
private readonly UrlsConfig _urls; | |||
public async Task<OrderData> GetOrderDraftFromBasket(BasketData basket) | |||
{ | |||
var uri = _urls.Orders + UrlsConfig.OrdersOperations.GetOrderDraft(); | |||
var content = new StringContent(JsonConvert.SerializeObject(basket), System.Text.Encoding.UTF8, "application/json"); | |||
var response = await _apiClient.PostAsync(uri, content); | |||
public OrderApiClient(HttpClient httpClient, ILogger<OrderApiClient> logger, IOptions<UrlsConfig> config) | |||
{ | |||
_apiClient = httpClient; | |||
_logger = logger; | |||
_urls = config.Value; | |||
} | |||
response.EnsureSuccessStatusCode(); | |||
public async Task<OrderData> GetOrderDraftFromBasket(BasketData basket) | |||
{ | |||
var uri = _urls.Orders + OrdersOperations.GetOrderDraft(); | |||
var content = new StringContent(JsonConvert.SerializeObject(basket), Encoding.UTF8, "application/json"); | |||
var response = await _apiClient.PostAsync(uri, content); | |||
var ordersDraftResponse = await response.Content.ReadAsStringAsync(); | |||
response.EnsureSuccessStatusCode(); | |||
return JsonConvert.DeserializeObject<OrderData>(ordersDraftResponse); | |||
} | |||
} | |||
var ordersDraftResponse = await response.Content.ReadAsStringAsync(); | |||
return JsonConvert.DeserializeObject<OrderData>(ordersDraftResponse); | |||
} | |||
} | |||
} |
@ -1,15 +1,15 @@ | |||
{ | |||
"Logging": { | |||
"IncludeScopes": false, | |||
"Debug": { | |||
"LogLevel": { | |||
"Default": "Warning" | |||
} | |||
}, | |||
"Console": { | |||
"LogLevel": { | |||
"Default": "Warning" | |||
} | |||
} | |||
} | |||
"Logging": { | |||
"IncludeScopes": false, | |||
"Debug": { | |||
"LogLevel": { | |||
"Default": "Warning" | |||
} | |||
}, | |||
"Console": { | |||
"LogLevel": { | |||
"Default": "Warning" | |||
} | |||
} | |||
} | |||
} |
@ -1,8 +1,8 @@ | |||
{ | |||
"urls": { | |||
"basket": "http://localhost:55105", | |||
"catalog": "http://localhost:55101", | |||
"orders": "http://localhost:55102", | |||
"identity": "http://localhost:55105" | |||
} | |||
"urls": { | |||
"basket": "http://localhost:55105", | |||
"catalog": "http://localhost:55101", | |||
"orders": "http://localhost:55102", | |||
"identity": "http://localhost:55105" | |||
} | |||
} |