Merge branch 'features/grpc' of https://github.com/dotnet-architecture/eShopOnContainers into features/grpc
This commit is contained in:
commit
b86771e084
@ -6,14 +6,14 @@ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
|
||||
WORKDIR /src
|
||||
COPY scripts scripts/
|
||||
|
||||
COPY src/ApiGateways/*/*.csproj /src/csproj-files/
|
||||
COPY src/ApiGateways/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/BuildingBlocks/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/Services/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/Web/*/*.csproj /src/csproj-files/
|
||||
COPY ApiGateways/*/*.csproj csproj-files/
|
||||
COPY ApiGateways/*/*/*.csproj csproj-files/
|
||||
COPY BuildingBlocks/*/*/*.csproj csproj-files/
|
||||
COPY Services/*/*/*.csproj csproj-files/
|
||||
COPY Web/*/*.csproj csproj-files/
|
||||
|
||||
COPY . .
|
||||
WORKDIR /src/src/ApiGateways/ApiGw-Base/
|
||||
WORKDIR /src/ApiGateways/ApiGw-Base/
|
||||
RUN dotnet publish -c Release -o /app
|
||||
|
||||
FROM build AS publish
|
||||
|
@ -28,6 +28,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config
|
||||
public string Catalog { get; set; }
|
||||
public string Orders { get; set; }
|
||||
public string GrpcBasket { get; set; }
|
||||
public string GrpcCatalog { get; set; }
|
||||
public string GrpcOrdering { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -27,50 +27,28 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<BasketData> GetById(string id)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using (var httpClientHandler = new HttpClientHandler())
|
||||
return await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient =>
|
||||
{
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
|
||||
using (var httpClient = new HttpClient(httpClientHandler))
|
||||
{
|
||||
//httpClient.BaseAddress = new Uri("http://10.0.75.1:5580");
|
||||
httpClient.BaseAddress = new Uri(_urls.GrpcBasket);
|
||||
|
||||
_logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress);
|
||||
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(httpClient);
|
||||
|
||||
_logger.LogDebug("grpc client created, request = {@id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id });
|
||||
|
||||
_logger.LogDebug("grpc response {@response}", response);
|
||||
|
||||
return MapToBasketData(response);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
_logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(BasketData currentBasket)
|
||||
{
|
||||
_httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket());
|
||||
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(_httpClient);
|
||||
await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient =>
|
||||
{
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(httpClient);
|
||||
_logger.LogDebug("Grpc update basket currentBasket {@currentBasket}", currentBasket);
|
||||
var request = MapToCustomerBasketRequest(currentBasket);
|
||||
_logger.LogDebug("Grpc update basket request {@request}", request);
|
||||
|
||||
await client.UpdateBasketAsync(request);
|
||||
return client.UpdateBasketAsync(request);
|
||||
});
|
||||
}
|
||||
|
||||
private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest)
|
||||
|
@ -3,9 +3,8 @@ using Grpc.Net.Client;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static CatalogApi.Catalog;
|
||||
@ -25,21 +24,26 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(int id)
|
||||
{
|
||||
_httpClient.BaseAddress = new Uri(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id));
|
||||
|
||||
return await GrpcCallerService.CallService(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id), async httpClient =>
|
||||
{
|
||||
var client = GrpcClient.Create<CatalogClient>(_httpClient);
|
||||
var request = new CatalogItemRequest { Id = id };
|
||||
var response = await client.GetItemByIdAsync(request);
|
||||
|
||||
return MapToCatalogItemResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
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 await GrpcCallerService.CallService(_urls.GrpcCatalog, async httpClient =>
|
||||
{
|
||||
var client = GrpcClient.Create<CatalogClient>(httpClient);
|
||||
var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 };
|
||||
var response = await client.GetItemsByIdsAsync(request);
|
||||
return response.Data.Select(this.MapToCatalogItemResponse);
|
||||
});
|
||||
}
|
||||
|
||||
private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse)
|
||||
|
@ -0,0 +1,73 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Grpc.Core;
|
||||
using Serilog;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public static class GrpcCallerService
|
||||
{
|
||||
public static async Task<TResponse> CallService<TResponse>(string urlGrpc, Func<HttpClient, Task<TResponse>> func)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using var httpClientHandler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
|
||||
};
|
||||
|
||||
using var httpClient = new HttpClient(httpClientHandler)
|
||||
{
|
||||
BaseAddress = new Uri(urlGrpc)
|
||||
};
|
||||
|
||||
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, httpClient.BaseAddress);
|
||||
|
||||
try
|
||||
{
|
||||
return await func(httpClient);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
Log.Error($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static async Task CallService(string urlGrpc, Func<HttpClient, Task> func)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using var httpClientHandler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
|
||||
};
|
||||
|
||||
using var httpClient = new HttpClient(httpClientHandler)
|
||||
{
|
||||
BaseAddress = new Uri(urlGrpc)
|
||||
};
|
||||
|
||||
Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress);
|
||||
|
||||
try
|
||||
{
|
||||
await func(httpClient);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
Log.Error($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,12 +3,10 @@ using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using GrpcOrdering;
|
||||
using Grpc.Core;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
@ -27,43 +25,21 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<OrderData> GetOrderDraftAsync(BasketData basketData)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using (var httpClientHandler = new HttpClientHandler())
|
||||
return await GrpcCallerService.CallService(_urls.GrpcOrdering, async httpClient =>
|
||||
{
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
|
||||
using (var httpClient = new HttpClient(httpClientHandler))
|
||||
{
|
||||
httpClient.BaseAddress = new Uri(_urls.GrpcOrdering);
|
||||
|
||||
_logger.LogDebug(" Creating grpc client for ordering {@httpClient.BaseAddress}", httpClient.BaseAddress);
|
||||
|
||||
var client = GrpcClient.Create<OrderingGrpc.OrderingGrpcClient>(httpClient);
|
||||
|
||||
_logger.LogDebug(" grpc client created, basketData={@basketData}", basketData);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var command = MapToOrderDraftCommand(basketData);
|
||||
var response = await client.CreateOrderDraftFromBasketDataAsync(command);
|
||||
|
||||
_logger.LogDebug(" grpc response: {@response}", response);
|
||||
|
||||
return MapToResponse(response);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
_logger.LogError($"Error calling via grpc to ordering: {e.Status} - {e.Message}");
|
||||
}
|
||||
}
|
||||
return MapToResponse(response, basketData);
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft)
|
||||
private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData)
|
||||
{
|
||||
if (orderDraft == null)
|
||||
{
|
||||
@ -72,6 +48,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
|
||||
var data = new OrderData
|
||||
{
|
||||
Buyer = basketData.BuyerId,
|
||||
Total = (decimal)orderDraft.Total,
|
||||
};
|
||||
|
||||
|
@ -1,9 +1,4 @@
|
||||
{
|
||||
"Kestrel": {
|
||||
"EndpointDefaults": {
|
||||
"Protocols": "Http2"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"Debug": {
|
||||
|
@ -5,6 +5,7 @@
|
||||
"orders": "http://localhost:55102",
|
||||
"identity": "http://localhost:55105",
|
||||
"grpcBasket": "http://localhost:5580",
|
||||
"grpcCatalog": "http://localhost:81",
|
||||
"grpcOrdering": "http://localhost:5581"
|
||||
},
|
||||
"IdentityUrlExternal": "http://localhost:5105",
|
||||
|
@ -39,8 +39,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
}
|
||||
|
||||
// Retrieve the current basket
|
||||
Log.Information("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ GetByIdAsync @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
|
||||
var basket = await _basket.GetById(data.BuyerId) ?? new BasketData(data.BuyerId);
|
||||
|
||||
Log.Debug("get basket by id response={@response}", basket);
|
||||
@ -128,11 +126,13 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
// Step 3: Search if exist product into basket
|
||||
var product = currentBasket.Items.SingleOrDefault(i => i.ProductId == item.Id.ToString());
|
||||
|
||||
if(product != null){
|
||||
if (product != null)
|
||||
{
|
||||
// Step 4: Update quantity for product
|
||||
product.Quantity += data.Quantity;
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
// Step 4: Merge current status with new product
|
||||
currentBasket.Items.Add(new BasketDataItem()
|
||||
{
|
||||
|
@ -2,76 +2,52 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Grpc.Net.Client;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GrpcBasket;
|
||||
using Grpc.Core;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly UrlsConfig _urls;
|
||||
public readonly HttpClient _httpClient;
|
||||
private readonly ILogger<BasketService> _logger;
|
||||
|
||||
public BasketService(HttpClient httpClient, IOptions<UrlsConfig> config, ILogger<BasketService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_urls = config.Value;
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
public async Task<BasketData> GetById(string id)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using (var httpClientHandler = new HttpClientHandler())
|
||||
return await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient =>
|
||||
{
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
|
||||
using (var httpClient = new HttpClient(httpClientHandler))
|
||||
{
|
||||
//httpClient.BaseAddress = new Uri("http://10.0.75.1:5580");
|
||||
httpClient.BaseAddress = new Uri(_urls.GrpcBasket);
|
||||
|
||||
_logger.LogDebug("Creating grpc client for basket {@httpClient.BaseAddress} ", httpClient.BaseAddress);
|
||||
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(httpClient);
|
||||
|
||||
_logger.LogDebug("grpc client created, request = {@id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var response = await client.GetBasketByIdAsync(new BasketRequest { Id = id });
|
||||
|
||||
_logger.LogDebug("grpc response {@response}", response);
|
||||
|
||||
return MapToBasketData(response);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
_logger.LogError($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(BasketData currentBasket)
|
||||
{
|
||||
_httpClient.BaseAddress = new Uri(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket());
|
||||
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(_httpClient);
|
||||
await GrpcCallerService.CallService(_urls.GrpcBasket, async httpClient =>
|
||||
{
|
||||
var client = GrpcClient.Create<Basket.BasketClient>(httpClient);
|
||||
_logger.LogDebug("Grpc update basket currentBasket {@currentBasket}", currentBasket);
|
||||
var request = MapToCustomerBasketRequest(currentBasket);
|
||||
_logger.LogDebug("Grpc update basket request {@request}", request);
|
||||
|
||||
await client.UpdateBasketAsync(request);
|
||||
return await client.UpdateBasketAsync(request);
|
||||
});
|
||||
}
|
||||
|
||||
private BasketData MapToBasketData(CustomerBasketResponse customerBasketRequest)
|
||||
@ -86,7 +62,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
BuyerId = customerBasketRequest.Buyerid
|
||||
};
|
||||
|
||||
customerBasketRequest.Items.ToList().ForEach(item => map.Items.Add(new BasketDataItem
|
||||
customerBasketRequest.Items.ToList().ForEach(item =>
|
||||
{
|
||||
if (item.Id != null)
|
||||
{
|
||||
map.Items.Add(new BasketDataItem
|
||||
{
|
||||
Id = item.Id,
|
||||
OldUnitPrice = (decimal)item.Oldunitprice,
|
||||
@ -95,7 +75,9 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
ProductName = item.Productname,
|
||||
Quantity = item.Quantity,
|
||||
UnitPrice = (decimal)item.Unitprice
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return map;
|
||||
}
|
||||
@ -112,7 +94,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
Buyerid = basketData.BuyerId
|
||||
};
|
||||
|
||||
basketData.Items.ToList().ForEach(item => map.Items.Add(new BasketItemResponse
|
||||
basketData.Items.ToList().ForEach(item =>
|
||||
{
|
||||
if (item.Id != null)
|
||||
{
|
||||
map.Items.Add(new BasketItemResponse
|
||||
{
|
||||
Id = item.Id,
|
||||
Oldunitprice = (double)item.OldUnitPrice,
|
||||
@ -121,7 +107,9 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
Productname = item.ProductName,
|
||||
Quantity = item.Quantity,
|
||||
Unitprice = (double)item.UnitPrice
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return map;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
@ -29,27 +28,28 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(int id)
|
||||
{
|
||||
_httpClient.BaseAddress = new Uri(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id));
|
||||
|
||||
var client = GrpcClient.Create<CatalogClient>(_httpClient);
|
||||
return await GrpcCallerService.CallService(_urls.GrpcCatalog, async httpClient =>
|
||||
{
|
||||
var client = GrpcClient.Create<CatalogClient>(httpClient);
|
||||
var request = new CatalogItemRequest { Id = id };
|
||||
_logger.LogInformation("grpc client created, request = {@request}", request);
|
||||
var response = await client.GetItemByIdAsync(request);
|
||||
|
||||
_logger.LogInformation("grpc response {@response}", response);
|
||||
return MapToCatalogItemResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids)
|
||||
{
|
||||
_httpClient.BaseAddress = new Uri(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids));
|
||||
|
||||
var client = GrpcClient.Create<CatalogClient>(_httpClient);
|
||||
return await GrpcCallerService.CallService(_urls.GrpcCatalog, async httpClient =>
|
||||
{
|
||||
var client = GrpcClient.Create<CatalogClient>(httpClient);
|
||||
var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 };
|
||||
_logger.LogInformation("grpc client created, request = {@request}", request);
|
||||
var response = await client.GetItemsByIdsAsync(request);
|
||||
_logger.LogInformation("grpc response {@response}", response);
|
||||
return response.Data.Select(this.MapToCatalogItemResponse);
|
||||
//var stringContent = await _httpClient.GetStringAsync(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemsById(ids));
|
||||
//var catalogItems = JsonConvert.DeserializeObject<CatalogItem[]>(stringContent);
|
||||
|
||||
//return catalogItems;
|
||||
});
|
||||
}
|
||||
|
||||
private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse)
|
||||
|
@ -0,0 +1,73 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Grpc.Core;
|
||||
using Serilog;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public static class GrpcCallerService
|
||||
{
|
||||
public static async Task<TResponse> CallService<TResponse>(string urlGrpc, Func<HttpClient, Task<TResponse>> func)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using var httpClientHandler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
|
||||
};
|
||||
|
||||
using var httpClient = new HttpClient(httpClientHandler)
|
||||
{
|
||||
BaseAddress = new Uri(urlGrpc)
|
||||
};
|
||||
|
||||
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, httpClient.BaseAddress);
|
||||
|
||||
try
|
||||
{
|
||||
return await func(httpClient);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
Log.Error($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public static async Task CallService(string urlGrpc, Func<HttpClient, Task> func)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using var httpClientHandler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
|
||||
};
|
||||
|
||||
using var httpClient = new HttpClient(httpClientHandler)
|
||||
{
|
||||
BaseAddress = new Uri(urlGrpc)
|
||||
};
|
||||
|
||||
Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", httpClient.BaseAddress);
|
||||
|
||||
try
|
||||
{
|
||||
await func(httpClient);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
Log.Error($"Error calling via grpc: {e.Status} - {e.Message}");
|
||||
}
|
||||
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,52 +14,30 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class OrderingService : IOrderingService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly UrlsConfig _urls;
|
||||
private readonly ILogger<OrderingService> _logger;
|
||||
public readonly HttpClient _httpClient;
|
||||
|
||||
public OrderingService(HttpClient httpClient, IOptions<UrlsConfig> config, ILogger<OrderingService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_urls = config.Value;
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<OrderData> GetOrderDraftAsync(BasketData basketData)
|
||||
{
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
|
||||
|
||||
using (var httpClientHandler = new HttpClientHandler())
|
||||
return await GrpcCallerService.CallService(_urls.GrpcOrdering, async httpClient =>
|
||||
{
|
||||
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
|
||||
using (var httpClient = new HttpClient(httpClientHandler))
|
||||
{
|
||||
httpClient.BaseAddress = new Uri(_urls.GrpcOrdering);
|
||||
|
||||
_logger.LogDebug(" Creating grpc client for ordering {@httpClient.BaseAddress}", httpClient.BaseAddress);
|
||||
|
||||
var client = GrpcClient.Create<OrderingGrpc.OrderingGrpcClient>(httpClient);
|
||||
|
||||
_logger.LogDebug(" grpc client created, basketData={@basketData}", basketData);
|
||||
|
||||
try
|
||||
{
|
||||
var command = MapToOrderDraftCommand(basketData);
|
||||
var response = await client.CreateOrderDraftFromBasketDataAsync(command);
|
||||
|
||||
_logger.LogDebug(" grpc response: {@response}", response);
|
||||
|
||||
return MapToResponse(response, basketData);
|
||||
}
|
||||
catch (RpcException e)
|
||||
{
|
||||
_logger.LogError($"Error calling via grpc to ordering: {e.Status} - {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData)
|
||||
|
@ -144,9 +144,9 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
|
||||
options.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "Shopping Aggregator for Mobile Clients",
|
||||
Title = "Shopping Aggregator for Web Clients",
|
||||
Version = "v1",
|
||||
Description = "Shopping Aggregator for Mobile Clients"
|
||||
Description = "Shopping Aggregator for Web Clients"
|
||||
});
|
||||
|
||||
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||
|
@ -63,8 +63,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
|
||||
guid : basketCheckout.RequestId;
|
||||
|
||||
_logger.LogInformation("----- CheckoutAsync userId: {userId} ", userId);
|
||||
|
||||
var basket = await _repository.GetBasketAsync(userId);
|
||||
|
||||
if (basket == null)
|
||||
@ -72,14 +70,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
_logger.LogInformation("----- CheckoutAsync basket: {@basket} ", basket);
|
||||
|
||||
_logger.LogInformation("----- CheckoutAsync user identity: {User} ", string.Join(':', ((ClaimsIdentity)User.Identity).Claims.Select(c => c.Type + " " + c.Value)));
|
||||
|
||||
var userName = User.FindFirst(x => x.Type == ClaimTypes.Name).Value;
|
||||
|
||||
_logger.LogInformation("----- CheckoutAsync userName: {@userName} ", userName);
|
||||
|
||||
var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street,
|
||||
basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,
|
||||
basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);
|
||||
@ -89,8 +81,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
// order creation process
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", eventMessage.Id, Program.AppName, eventMessage);
|
||||
|
||||
_eventBus.Publish(eventMessage);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -26,8 +26,6 @@ namespace Basket.API.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _repository.DeleteBasketAsync(@event.UserId.ToString());
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var userIds = _repository.GetUsers();
|
||||
|
||||
foreach (var id in userIds)
|
||||
@ -46,8 +44,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
|
||||
|
||||
if (itemsToUpdate != null)
|
||||
{
|
||||
_logger.LogInformation("----- ProductPriceChangedIntegrationEventHandler - Updating items in basket for user: {BuyerId} ({@Items})", basket.BuyerId, itemsToUpdate);
|
||||
|
||||
foreach (var item in itemsToUpdate)
|
||||
{
|
||||
if (item.UnitPrice == oldPrice)
|
||||
|
@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
|
||||
public List<BasketItem> Items { get; set; }
|
||||
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
|
||||
|
||||
public CustomerBasket()
|
||||
{
|
||||
@ -16,7 +16,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||
public CustomerBasket(string customerId)
|
||||
{
|
||||
BuyerId = customerId;
|
||||
Items = new List<BasketItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,24 @@ namespace Catalog.API.Grpc
|
||||
PageSize = pageSize,
|
||||
};
|
||||
|
||||
items.ForEach(i => result.Data.Add(new CatalogItemResponse()
|
||||
items.ForEach(i =>
|
||||
{
|
||||
var brand = i.CatalogBrand == null
|
||||
? null
|
||||
: new CatalogApi.CatalogBrand()
|
||||
{
|
||||
Id = i.CatalogBrand.Id,
|
||||
Name = i.CatalogBrand.Brand,
|
||||
};
|
||||
var catalogType = i.CatalogType == null
|
||||
? null
|
||||
: new CatalogApi.CatalogType()
|
||||
{
|
||||
Id = i.CatalogType.Id,
|
||||
Type = i.CatalogType.Type,
|
||||
};
|
||||
|
||||
result.Data.Add(new CatalogItemResponse()
|
||||
{
|
||||
AvailableStock = i.AvailableStock,
|
||||
Description = i.Description,
|
||||
@ -127,18 +144,11 @@ namespace Catalog.API.Grpc
|
||||
PictureFileName = i.PictureFileName,
|
||||
PictureUri = i.PictureUri,
|
||||
RestockThreshold = i.RestockThreshold,
|
||||
CatalogBrand = new CatalogApi.CatalogBrand()
|
||||
{
|
||||
Id = i.CatalogBrand.Id,
|
||||
Name = i.CatalogBrand.Brand,
|
||||
},
|
||||
CatalogType = new CatalogApi.CatalogType()
|
||||
{
|
||||
Id = i.CatalogType.Id,
|
||||
Type = i.CatalogType.Type,
|
||||
},
|
||||
CatalogBrand = brand,
|
||||
CatalogType = catalogType,
|
||||
Price = (double)i.Price,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -39,8 +39,6 @@ namespace Catalog.API.IntegrationEvents
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId_published} from {AppName} - ({@IntegrationEvent})", evt.Id, Program.AppName, evt);
|
||||
|
||||
await _eventLogService.MarkEventAsInProgressAsync(evt.Id);
|
||||
_eventBus.Publish(evt);
|
||||
await _eventLogService.MarkEventAsPublishedAsync(evt.Id);
|
||||
@ -54,8 +52,6 @@ namespace Catalog.API.IntegrationEvents
|
||||
|
||||
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
|
||||
{
|
||||
_logger.LogInformation("----- CatalogIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id);
|
||||
|
||||
//Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction():
|
||||
//See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
|
||||
await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () =>
|
||||
|
@ -32,8 +32,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();
|
||||
|
||||
foreach (var orderStockItem in @event.OrderStockItems)
|
||||
|
@ -25,8 +25,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
//we're not blocking stock/inventory
|
||||
foreach (var orderStockItem in @event.OrderStockItems)
|
||||
{
|
||||
|
@ -56,11 +56,5 @@ service Catalog {
|
||||
};
|
||||
<< */
|
||||
}
|
||||
rpc GetItemsByIds (CatalogItemsRequest) returns (PaginatedItemsResponse) {
|
||||
/* >>
|
||||
option (google.api.http) = {
|
||||
get: "/api/v1/catalog/items/ids/{ids}"
|
||||
};
|
||||
<< */
|
||||
}
|
||||
rpc GetItemsByIds (CatalogItemsRequest) returns (PaginatedItemsResponse) {}
|
||||
}
|
@ -72,9 +72,6 @@
|
||||
{
|
||||
var newUserLocations = MapUserLocationDetails(newLocations);
|
||||
var @event = new UserLocationUpdatedIntegrationEvent(userId, newUserLocations);
|
||||
|
||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
_eventBus.Publish(@event);
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var userMarketingData = await _marketingDataRepository.GetAsync(@event.UserId);
|
||||
userMarketingData = userMarketingData ??
|
||||
new MarketingData() { UserId = @event.UserId };
|
||||
|
@ -24,8 +24,6 @@ namespace Ordering.API.Application.Behaviors
|
||||
{
|
||||
var typeName = request.GetGenericTypeName();
|
||||
|
||||
_logger.LogInformation("----- Validating command {CommandType}", typeName);
|
||||
|
||||
var failures = _validators
|
||||
.Select(v => v.Validate(request))
|
||||
.SelectMany(result => result.Errors)
|
||||
|
@ -53,8 +53,6 @@
|
||||
order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units);
|
||||
}
|
||||
|
||||
_logger.LogInformation("----- Creating Order - Order: {@Order}", order);
|
||||
|
||||
_orderRepository.Add(order);
|
||||
|
||||
return await _orderRepository.UnitOfWork
|
||||
|
@ -27,7 +27,6 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri
|
||||
public async Task Handle(BuyerAndPaymentMethodVerifiedDomainEvent buyerPaymentMethodVerifiedEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
var log = _logger.CreateLogger<UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler>();
|
||||
log.LogInformation("----- Handling BuyerAndPaymentMethodVerifiedDomainEvent - buyerPaymentMethodVerifiedEvent: {@buyerPaymentMethodVerifiedEvent}", buyerPaymentMethodVerifiedEvent);
|
||||
var orderToUpdate = await _orderRepository.GetAsync(buyerPaymentMethodVerifiedEvent.OrderId);
|
||||
orderToUpdate.SetBuyerId(buyerPaymentMethodVerifiedEvent.Buyer.Id);
|
||||
orderToUpdate.SetPaymentId(buyerPaymentMethodVerifiedEvent.Payment.Id);
|
||||
|
@ -60,7 +60,6 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent
|
||||
|
||||
var orderStatusChangedTosubmittedIntegrationEvent = new OrderStatusChangedToSubmittedIntegrationEvent(orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name);
|
||||
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedTosubmittedIntegrationEvent);
|
||||
|
||||
_logger.CreateLogger<ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler>()
|
||||
.LogTrace("Buyer {BuyerId} and related payment method were validated or updated for orderId: {OrderId}.",
|
||||
buyerUpdated.Id, orderStartedEvent.Order.Id);
|
||||
|
@ -37,8 +37,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
|
@ -31,8 +31,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var command = new CancelOrderCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
|
@ -31,8 +31,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var command = new SetPaidOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
|
@ -31,8 +31,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
|
@ -30,8 +30,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var orderStockRejectedItems = @event.OrderStockItems
|
||||
.FindAll(c => !c.HasStock)
|
||||
.Select(c => c.ProductId)
|
||||
|
@ -38,8 +38,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var result = false;
|
||||
|
||||
if (@event.RequestId != Guid.Empty)
|
||||
@ -62,11 +60,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
|
||||
result = await _mediator.Send(requestCreateOrder);
|
||||
|
||||
if (result)
|
||||
{
|
||||
_logger.LogInformation("----- CreateOrderCommand suceeded - RequestId: {RequestId}", @event.RequestId);
|
||||
}
|
||||
else
|
||||
if (!result)
|
||||
{
|
||||
_logger.LogWarning("CreateOrderCommand failed - RequestId: {RequestId}", @event.RequestId);
|
||||
}
|
||||
|
@ -45,8 +45,6 @@ namespace Ordering.API.Application.IntegrationEvents
|
||||
|
||||
foreach (var logEvt in pendingLogEvents)
|
||||
{
|
||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", logEvt.EventId, Program.AppName, logEvt.IntegrationEvent);
|
||||
|
||||
try
|
||||
{
|
||||
await _eventLogService.MarkEventAsInProgressAsync(logEvt.EventId);
|
||||
@ -64,8 +62,6 @@ namespace Ordering.API.Application.IntegrationEvents
|
||||
|
||||
public async Task AddAndSaveEventAsync(IntegrationEvent evt)
|
||||
{
|
||||
_logger.LogInformation("----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt);
|
||||
|
||||
await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction());
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
{
|
||||
var requestCancelOrder = new IdentifiedCommand<CancelOrderCommand, bool>(command, guid);
|
||||
|
||||
_logger.LogInformation(
|
||||
_logger.LogTrace(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
requestCancelOrder.GetGenericTypeName(),
|
||||
nameof(requestCancelOrder.Command.OrderNumber),
|
||||
@ -79,7 +79,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
{
|
||||
var requestShipOrder = new IdentifiedCommand<ShipOrderCommand, bool>(command, guid);
|
||||
|
||||
_logger.LogInformation(
|
||||
_logger.LogTrace(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
requestShipOrder.GetGenericTypeName(),
|
||||
nameof(requestShipOrder.Command.OrderNumber),
|
||||
@ -141,7 +141,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<OrderDraftDTO>> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
_logger.LogTrace(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
createOrderDraftCommand.GetGenericTypeName(),
|
||||
nameof(createOrderDraftCommand.BuyerId),
|
||||
|
@ -27,7 +27,7 @@ namespace GrpcOrdering
|
||||
public override async Task<OrderDraftDTO> CreateOrderDraftFromBasketData(CreateOrderDraftCommand createOrderDraftCommand, ServerCallContext context)
|
||||
{
|
||||
_logger.LogInformation($"Begin grpc call from method {context.Method} for ordering get order draft {createOrderDraftCommand}");
|
||||
_logger.LogInformation(
|
||||
_logger.LogTrace(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
createOrderDraftCommand.GetGenericTypeName(),
|
||||
nameof(createOrderDraftCommand.BuyerId),
|
||||
|
@ -7,14 +7,15 @@ WORKDIR /src
|
||||
|
||||
COPY scripts scripts/
|
||||
|
||||
COPY src/ApiGateways/*/*.csproj /src/csproj-files/
|
||||
COPY src/ApiGateways/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/BuildingBlocks/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/Services/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/Web/*/*.csproj /src/csproj-files/
|
||||
COPY ApiGateways/*/*.csproj csproj-files/
|
||||
COPY ApiGateways/*/*/*.csproj csproj-files/
|
||||
COPY BuildingBlocks/*/*/*.csproj csproj-files/
|
||||
COPY Services/*/*/*.csproj csproj-files/
|
||||
COPY Web/*/*.csproj csproj-files/
|
||||
|
||||
|
||||
COPY . .
|
||||
WORKDIR /src/src/Services/Ordering/Ordering.BackgroundTasks
|
||||
WORKDIR /src/Services/Ordering/Ordering.BackgroundTasks
|
||||
RUN dotnet publish -c Release -o /app
|
||||
|
||||
FROM build AS publish
|
||||
|
@ -55,8 +55,6 @@ namespace Ordering.BackgroundTasks.Tasks
|
||||
{
|
||||
var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
|
||||
|
||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", confirmGracePeriodEvent.Id, _settings.SubscriptionClientName, confirmGracePeriodEvent);
|
||||
|
||||
_eventBus.Publish(confirmGracePeriodEvent);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
// Address is a Value Object pattern example persisted as EF Core 2.0 owned entity
|
||||
public Address Address { get; private set; }
|
||||
|
||||
public int? GetBuyerId => _buyerId;
|
||||
public int? GetBuyerId { get { return this._buyerId; } }
|
||||
private int? _buyerId;
|
||||
|
||||
public OrderStatus OrderStatus { get; private set; }
|
||||
@ -46,7 +46,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
return order;
|
||||
}
|
||||
|
||||
protected Order() {
|
||||
protected Order()
|
||||
{
|
||||
_orderItems = new List<OrderItem>();
|
||||
_isDraft = false;
|
||||
}
|
||||
|
@ -27,10 +27,31 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
a.WithOwner();
|
||||
});
|
||||
|
||||
orderConfiguration.Property<DateTime>("OrderDate").IsRequired();
|
||||
orderConfiguration.Property<int?>("BuyerId").IsRequired(false);
|
||||
orderConfiguration.Property<int>("OrderStatusId").IsRequired();
|
||||
orderConfiguration.Property<int?>("PaymentMethodId").IsRequired(false);
|
||||
orderConfiguration
|
||||
.Property<int?>("_buyerId")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("BuyerId")
|
||||
.IsRequired(false);
|
||||
|
||||
orderConfiguration
|
||||
.Property<DateTime>("_orderDate")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("OrderDate")
|
||||
.IsRequired();
|
||||
|
||||
orderConfiguration
|
||||
.Property<int>("_orderStatusId")
|
||||
// .HasField("_orderStatusId")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("OrderStatusId")
|
||||
.IsRequired();
|
||||
|
||||
orderConfiguration
|
||||
.Property<int?>("_paymentMethodId")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("PaymentMethodId")
|
||||
.IsRequired(false);
|
||||
|
||||
orderConfiguration.Property<string>("Description").IsRequired(false);
|
||||
|
||||
var navigation = orderConfiguration.Metadata.FindNavigation(nameof(Order.OrderItems));
|
||||
@ -41,18 +62,21 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
|
||||
orderConfiguration.HasOne<PaymentMethod>()
|
||||
.WithMany()
|
||||
.HasForeignKey("PaymentMethodId")
|
||||
// .HasForeignKey("PaymentMethodId")
|
||||
.HasForeignKey("_paymentMethodId")
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
orderConfiguration.HasOne<Buyer>()
|
||||
.WithMany()
|
||||
.IsRequired(false)
|
||||
.HasForeignKey("BuyerId");
|
||||
// .HasForeignKey("BuyerId");
|
||||
.HasForeignKey("_buyerId");
|
||||
|
||||
orderConfiguration.HasOne(o => o.OrderStatus)
|
||||
.WithMany()
|
||||
.HasForeignKey("OrderStatusId");
|
||||
// .HasForeignKey("OrderStatusId");
|
||||
.HasForeignKey("_orderStatusId");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,22 +22,37 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
orderItemConfiguration.Property<int>("OrderId")
|
||||
.IsRequired();
|
||||
|
||||
orderItemConfiguration.Property<decimal>("Discount")
|
||||
orderItemConfiguration
|
||||
.Property<decimal>("_discount")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("Discount")
|
||||
.IsRequired();
|
||||
|
||||
orderItemConfiguration.Property<int>("ProductId")
|
||||
.IsRequired();
|
||||
|
||||
orderItemConfiguration.Property<string>("ProductName")
|
||||
orderItemConfiguration
|
||||
.Property<string>("_productName")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("ProductName")
|
||||
.IsRequired();
|
||||
|
||||
orderItemConfiguration.Property<decimal>("UnitPrice")
|
||||
orderItemConfiguration
|
||||
.Property<decimal>("_unitPrice")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("UnitPrice")
|
||||
.IsRequired();
|
||||
|
||||
orderItemConfiguration.Property<int>("Units")
|
||||
orderItemConfiguration
|
||||
.Property<int>("_units")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("Units")
|
||||
.IsRequired();
|
||||
|
||||
orderItemConfiguration.Property<string>("PictureUrl")
|
||||
orderItemConfiguration
|
||||
.Property<string>("_pictureUrl")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("PictureUrl")
|
||||
.IsRequired(false);
|
||||
}
|
||||
}
|
||||
|
@ -23,27 +23,43 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
paymentConfiguration.Property<int>("BuyerId")
|
||||
.IsRequired();
|
||||
|
||||
paymentConfiguration.Property<string>("CardHolderName")
|
||||
paymentConfiguration
|
||||
.Property<string>("_cardHolderName")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("CardHolderName")
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
paymentConfiguration.Property<string>("Alias")
|
||||
paymentConfiguration
|
||||
.Property<string>("_alias")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("Alias")
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
paymentConfiguration.Property<string>("CardNumber")
|
||||
paymentConfiguration
|
||||
.Property<string>("_cardNumber")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("CardNumber")
|
||||
.HasMaxLength(25)
|
||||
.IsRequired();
|
||||
|
||||
paymentConfiguration.Property<DateTime>("Expiration")
|
||||
paymentConfiguration
|
||||
.Property<DateTime>("_expiration")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("Expiration")
|
||||
.HasMaxLength(25)
|
||||
.IsRequired();
|
||||
|
||||
paymentConfiguration.Property<int>("CardTypeId")
|
||||
paymentConfiguration
|
||||
.Property<int>("_cardTypeId")
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("CardTypeId")
|
||||
.IsRequired();
|
||||
|
||||
paymentConfiguration.HasOne(p => p.CardType)
|
||||
.WithMany()
|
||||
.HasForeignKey("CardTypeId");
|
||||
.HasForeignKey("_cardTypeId");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
||||
using Ordering.Domain.Exceptions;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories
|
||||
@ -37,6 +38,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
|
||||
.Orders
|
||||
.Include(x => x.Address)
|
||||
.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null)
|
||||
{
|
||||
order = _context
|
||||
.Orders
|
||||
.Local
|
||||
.FirstOrDefault(o => o.Id == orderId);
|
||||
}
|
||||
if (order != null)
|
||||
{
|
||||
await _context.Entry(order)
|
||||
|
@ -7,14 +7,14 @@ WORKDIR /src
|
||||
|
||||
COPY scripts scripts/
|
||||
|
||||
COPY src/ApiGateways/*/*.csproj /src/csproj-files/
|
||||
COPY src/ApiGateways/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/BuildingBlocks/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/Services/*/*/*.csproj /src/csproj-files/
|
||||
COPY src/Web/*/*.csproj /src/csproj-files/
|
||||
COPY ApiGateways/*/*.csproj csproj-files/
|
||||
COPY ApiGateways/*/*/*.csproj csproj-files/
|
||||
COPY BuildingBlocks/*/*/*.csproj csproj-files/
|
||||
COPY Services/*/*/*.csproj csproj-files/
|
||||
COPY Web/*/*.csproj csproj-files/
|
||||
|
||||
COPY . .
|
||||
WORKDIR /src/src/Services/Ordering/Ordering.SignalrHub
|
||||
WORKDIR /src/Services/Ordering/Ordering.SignalrHub
|
||||
RUN dotnet publish -c Release -o /app
|
||||
|
||||
FROM build AS publish
|
||||
|
@ -27,8 +27,6 @@ namespace Ordering.SignalrHub.IntegrationEvents
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(@event.BuyerName)
|
||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||
|
@ -28,8 +28,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(@event.BuyerName)
|
||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||
|
@ -26,8 +26,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(@event.BuyerName)
|
||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||
|
@ -28,8 +28,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(@event.BuyerName)
|
||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||
|
@ -29,8 +29,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(@event.BuyerName)
|
||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||
|
@ -29,8 +29,6 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(@event.BuyerName)
|
||||
.SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus });
|
||||
|
@ -31,8 +31,6 @@
|
||||
{
|
||||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
IntegrationEvent orderPaymentIntegrationEvent;
|
||||
|
||||
//Business feature comment:
|
||||
@ -50,8 +48,6 @@
|
||||
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
|
||||
}
|
||||
|
||||
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent);
|
||||
|
||||
_eventBus.Publish(orderPaymentIntegrationEvent);
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
@ -25,8 +25,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
||||
var user = User as ClaimsPrincipal;
|
||||
var token = await HttpContext.GetTokenAsync("access_token");
|
||||
|
||||
_logger.LogInformation("----- User {@User} authenticated into {AppName}", user, Program.AppName);
|
||||
|
||||
if (token != null)
|
||||
{
|
||||
ViewData["access_token"] = token;
|
||||
|
@ -288,6 +288,7 @@ services:
|
||||
- urls__orders=http://ordering-api
|
||||
- urls__identity=http://identity-api
|
||||
- urls__grpcBasket=http://10.0.75.1:5580
|
||||
- urls__grpcCatalog=http://10.0.75.1:9101
|
||||
- urls__grpcOrdering=http://10.0.75.1:5581
|
||||
- CatalogUrlHC=http://catalog-api/hc
|
||||
- OrderingUrlHC=http://ordering-api/hc
|
||||
|
Loading…
x
Reference in New Issue
Block a user