Re-factored and formatted MobileAgg project codes
This commit is contained in:
parent
4e774612ae
commit
0bc2a29b38
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -38,10 +37,10 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
|||||||
currentBasket = new BasketData(data.BuyerId);
|
currentBasket = new BasketData(data.BuyerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var catalogItems = await _catalog.GetCatalogItems(data.Items.Select(x => x.ProductId));
|
System.Collections.Generic.IEnumerable<CatalogItem> catalogItems = await _catalog.GetCatalogItems(data.Items.Select(x => x.ProductId));
|
||||||
var newBasket = new BasketData(data.BuyerId);
|
BasketData newBasket = new BasketData(data.BuyerId);
|
||||||
|
|
||||||
foreach (var bitem in data.Items)
|
foreach (UpdateBasketRequestItemData bitem in data.Items)
|
||||||
{
|
{
|
||||||
var catalogItem = catalogItems.SingleOrDefault(ci => ci.Id == bitem.ProductId);
|
var catalogItem = catalogItems.SingleOrDefault(ci => ci.Id == bitem.ProductId);
|
||||||
if (catalogItem == null)
|
if (catalogItem == null)
|
||||||
@ -74,16 +73,16 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the current basket
|
// Retrieve the current basket
|
||||||
var currentBasket = await _basket.GetById(data.BasketId);
|
BasketData currentBasket = await _basket.GetById(data.BasketId);
|
||||||
if (currentBasket == null)
|
if (currentBasket == null)
|
||||||
{
|
{
|
||||||
return BadRequest($"Basket with id {data.BasketId} not found.");
|
return BadRequest($"Basket with id {data.BasketId} not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update with new quantities
|
// Update with new quantities
|
||||||
foreach (var update in data.Updates)
|
foreach (UpdateBasketItemData update in data.Updates)
|
||||||
{
|
{
|
||||||
var basketItem = currentBasket.Items.SingleOrDefault(bitem => bitem.Id == update.BasketItemId);
|
BasketDataItem basketItem = currentBasket.Items.SingleOrDefault(bitem => bitem.Id == update.BasketItemId);
|
||||||
if (basketItem == null)
|
if (basketItem == null)
|
||||||
{
|
{
|
||||||
return BadRequest($"Basket item with id {update.BasketItemId} not found");
|
return BadRequest($"Basket item with id {update.BasketItemId} not found");
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Controllers
|
||||||
|
@ -21,11 +21,13 @@
|
|||||||
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
|
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
|
||||||
operation.Responses.Add("403", new Response { Description = "Forbidden" });
|
operation.Responses.Add("403", new Response { Description = "Forbidden" });
|
||||||
|
|
||||||
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
|
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
|
||||||
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
|
{
|
||||||
|
new Dictionary<string, IEnumerable<string>>
|
||||||
{
|
{
|
||||||
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } }
|
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } }
|
||||||
});
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
using System;
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
|
||||||
{
|
{
|
||||||
public class AddBasketItemRequest
|
public class AddBasketItemRequest
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
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 BasketData
|
public class BasketData
|
||||||
{
|
{
|
||||||
public string BuyerId { get; set; }
|
public string BuyerId { get; set; }
|
||||||
public List<BasketDataItem> Items { get; set; }
|
public IList<BasketDataItem> Items { get; set; }
|
||||||
|
|
||||||
public BasketData(string buyerId)
|
public BasketData(string buyerId)
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
using System;
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
|
||||||
{
|
{
|
||||||
public class CatalogItem
|
public class CatalogItem
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using DateTime = System.DateTime;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||||
{
|
{
|
||||||
@ -28,6 +26,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
|||||||
|
|
||||||
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,9 +1,4 @@
|
|||||||
using System;
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models
|
|
||||||
{
|
{
|
||||||
public class OrderItemData
|
public class OrderItemData
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
using System;
|
using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions;
|
||||||
using System.Collections.Generic;
|
using static Microsoft.AspNetCore.Hosting.WebHostExtensions;
|
||||||
using System.IO;
|
using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost;
|
||||||
using System.Linq;
|
using WebHost = Microsoft.AspNetCore.WebHost;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||||
{
|
{
|
||||||
@ -23,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
|||||||
.ConfigureAppConfiguration(cb =>
|
.ConfigureAppConfiguration(cb =>
|
||||||
{
|
{
|
||||||
var sources = cb.Sources;
|
var sources = cb.Sources;
|
||||||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource()
|
sources.Insert(3, new Extensions.Configuration.Json.JsonConfigurationSource()
|
||||||
{
|
{
|
||||||
Optional = true,
|
Optional = true,
|
||||||
Path = "appsettings.localhost.json",
|
Path = "appsettings.localhost.json",
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
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
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||||
{
|
{
|
||||||
|
using BasketData = Models.BasketData;
|
||||||
|
using BasketOperations = Config.UrlsConfig.BasketOperations;
|
||||||
|
using UrlsConfig = Config.UrlsConfig;
|
||||||
|
|
||||||
public class BasketService : IBasketService
|
public class BasketService : IBasketService
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -24,7 +28,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
|||||||
|
|
||||||
public async Task<BasketData> GetById(string id)
|
public async Task<BasketData> GetById(string id)
|
||||||
{
|
{
|
||||||
var data = await _httpClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
var data = await _httpClient.GetStringAsync(_urls.Basket + BasketOperations.GetItemById(id));
|
||||||
|
|
||||||
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
||||||
|
|
||||||
@ -33,9 +37,9 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
|||||||
|
|
||||||
public async Task Update(BasketData currentBasket)
|
public async Task Update(BasketData currentBasket)
|
||||||
{
|
{
|
||||||
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), System.Text.Encoding.UTF8, "application/json");
|
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
var data = await _httpClient.PostAsync(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket(), basketContent);
|
var data = await _httpClient.PostAsync(_urls.Basket + BasketOperations.UpdateBasket(), basketContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using HttpClient = System.Net.Http.HttpClient;
|
||||||
|
using JsonConvert = Newtonsoft.Json.JsonConvert;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||||
{
|
{
|
||||||
|
using CatalogItem = Models.CatalogItem;
|
||||||
|
using CatalogOperations = Config.UrlsConfig.CatalogOperations;
|
||||||
|
using UrlsConfig = Config.UrlsConfig;
|
||||||
|
|
||||||
public class CatalogService : ICatalogService
|
public class CatalogService : ICatalogService
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
@ -24,7 +26,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
|||||||
|
|
||||||
public async Task<CatalogItem> GetCatalogItem(int id)
|
public async Task<CatalogItem> GetCatalogItem(int id)
|
||||||
{
|
{
|
||||||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id));
|
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + CatalogOperations.GetItemById(id));
|
||||||
var catalogItem = JsonConvert.DeserializeObject<CatalogItem>(stringContent);
|
var catalogItem = JsonConvert.DeserializeObject<CatalogItem>(stringContent);
|
||||||
|
|
||||||
return catalogItem;
|
return catalogItem;
|
||||||
@ -32,7 +34,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
|||||||
|
|
||||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids)
|
public async Task<IEnumerable<CatalogItem>> GetCatalogItems(IEnumerable<int> ids)
|
||||||
{
|
{
|
||||||
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids));
|
var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + CatalogOperations.GetItemsById(ids));
|
||||||
var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent);
|
var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent);
|
||||||
|
|
||||||
return catalogItems;
|
return catalogItems;
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
using System.Threading.Tasks;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||||
{
|
{
|
||||||
|
using BasketData = Models.BasketData;
|
||||||
|
|
||||||
public interface IBasketService
|
public interface IBasketService
|
||||||
{
|
{
|
||||||
Task<BasketData> GetById(string id);
|
Task<BasketData> GetById(string id);
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
using System.Collections.Generic;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||||
{
|
{
|
||||||
|
using CatalogItem = Models.CatalogItem;
|
||||||
|
|
||||||
public interface ICatalogService
|
public interface ICatalogService
|
||||||
{
|
{
|
||||||
Task<CatalogItem> GetCatalogItem(int id);
|
Task<CatalogItem> GetCatalogItem(int id);
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
using System.Threading.Tasks;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||||
{
|
{
|
||||||
|
using BasketData = Models.BasketData;
|
||||||
|
using OrderData = Models.OrderData;
|
||||||
|
|
||||||
public interface IOrderApiClient
|
public interface IOrderApiClient
|
||||||
{
|
{
|
||||||
Task<OrderData> GetOrderDraftFromBasket(BasketData basket);
|
Task<OrderData> GetOrderDraftFromBasket(BasketData basket);
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
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
|
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||||
{
|
{
|
||||||
|
using BasketData = Models.BasketData;
|
||||||
|
using OrdersOperations = Config.UrlsConfig.OrdersOperations;
|
||||||
|
using OrderData = Models.OrderData;
|
||||||
|
using UrlsConfig = Config.UrlsConfig;
|
||||||
|
|
||||||
public class OrderApiClient : IOrderApiClient
|
public class OrderApiClient : IOrderApiClient
|
||||||
{
|
{
|
||||||
private readonly HttpClient _apiClient;
|
private readonly HttpClient _apiClient;
|
||||||
@ -23,8 +28,8 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
|||||||
|
|
||||||
public async Task<OrderData> GetOrderDraftFromBasket(BasketData basket)
|
public async Task<OrderData> GetOrderDraftFromBasket(BasketData basket)
|
||||||
{
|
{
|
||||||
var uri = _urls.Orders + UrlsConfig.OrdersOperations.GetOrderDraft();
|
var uri = _urls.Orders + OrdersOperations.GetOrderDraft();
|
||||||
var content = new StringContent(JsonConvert.SerializeObject(basket), System.Text.Encoding.UTF8, "application/json");
|
var content = new StringContent(JsonConvert.SerializeObject(basket), Encoding.UTF8, "application/json");
|
||||||
var response = await _apiClient.PostAsync(uri, content);
|
var response = await _apiClient.PostAsync(uri, content);
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
@ -31,7 +31,8 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddCustomMvc(Configuration)
|
services
|
||||||
|
.AddCustomMvc(Configuration)
|
||||||
.AddCustomAuthentication(Configuration)
|
.AddCustomAuthentication(Configuration)
|
||||||
.AddHttpServices();
|
.AddHttpServices();
|
||||||
}
|
}
|
||||||
@ -116,25 +117,29 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
|||||||
{
|
{
|
||||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
|
||||||
var identityUrl = configuration.GetValue<string>("urls:identity");
|
var identityUrl = configuration.GetValue<string>("urls:identity");
|
||||||
services.AddAuthentication(options =>
|
services
|
||||||
|
.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
|
||||||
}).AddJwtBearer(options =>
|
})
|
||||||
|
.AddJwtBearer(options =>
|
||||||
{
|
{
|
||||||
options.Authority = identityUrl;
|
options.Authority = identityUrl;
|
||||||
options.RequireHttpsMetadata = false;
|
options.RequireHttpsMetadata = false;
|
||||||
options.Audience = "mobileshoppingagg";
|
options.Audience = "mobileshoppingagg";
|
||||||
options.Events = new JwtBearerEvents()
|
options.Events = new JwtBearerEvents()
|
||||||
{
|
{
|
||||||
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
OnAuthenticationFailed = async ctx =>
|
OnAuthenticationFailed = async ctx =>
|
||||||
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
},
|
},
|
||||||
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
OnTokenValidated = async ctx =>
|
OnTokenValidated = async ctx =>
|
||||||
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -153,11 +158,13 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
|||||||
.AddPolicyHandler(GetRetryPolicy())
|
.AddPolicyHandler(GetRetryPolicy())
|
||||||
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
||||||
|
|
||||||
services.AddHttpClient<ICatalogService, CatalogService>()
|
services
|
||||||
|
.AddHttpClient<ICatalogService, CatalogService>()
|
||||||
.AddPolicyHandler(GetRetryPolicy())
|
.AddPolicyHandler(GetRetryPolicy())
|
||||||
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
||||||
|
|
||||||
services.AddHttpClient<IOrderApiClient, OrderApiClient>()
|
services
|
||||||
|
.AddHttpClient<IOrderApiClient, OrderApiClient>()
|
||||||
.AddPolicyHandler(GetRetryPolicy())
|
.AddPolicyHandler(GetRetryPolicy())
|
||||||
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
||||||
|
|
||||||
@ -167,18 +174,13 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
|||||||
}
|
}
|
||||||
|
|
||||||
static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
|
static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
|
||||||
{
|
=> HttpPolicyExtensions
|
||||||
return HttpPolicyExtensions
|
|
||||||
.HandleTransientHttpError()
|
.HandleTransientHttpError()
|
||||||
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
|
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||||
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||||
|
|
||||||
}
|
|
||||||
static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
|
static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
|
||||||
{
|
=> HttpPolicyExtensions
|
||||||
return HttpPolicyExtensions
|
|
||||||
.HandleTransientHttpError()
|
.HandleTransientHttpError()
|
||||||
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
|
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user