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