From 4398b25fc1e4988b93dc5a2848fbb2ab019dbf2f Mon Sep 17 00:00:00 2001 From: ericuss Date: Thu, 29 Aug 2019 13:13:10 +0200 Subject: [PATCH] Fix mvc calls to grpc --- .../aggregator/Controllers/BasketController.cs | 10 ++++++---- .../aggregator/Services/BasketService.cs | 2 +- .../Basket/Basket.API/Controllers/BasketController.cs | 10 ---------- src/Services/Basket/Basket.API/Model/CustomerBasket.cs | 3 +-- src/Web/WebMVC/Controllers/CartController.cs | 4 ++-- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs index 5905ae214..429d6e82d 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -125,12 +125,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers var currentBasket = (await _basket.GetById(data.BasketId)) ?? new BasketData(data.BasketId); // 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() { @@ -142,7 +144,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers Id = Guid.NewGuid().ToString() }); } - + // Step 5: Update basket await _basket.UpdateAsync(currentBasket); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs index 3875f3bdb..8eb8865fe 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/BasketService.cs @@ -46,7 +46,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services var request = MapToCustomerBasketRequest(currentBasket); _logger.LogDebug("Grpc update basket request {@request}", request); - return client.UpdateBasketAsync(request); + return await client.UpdateBasketAsync(request); }); } diff --git a/src/Services/Basket/Basket.API/Controllers/BasketController.cs b/src/Services/Basket/Basket.API/Controllers/BasketController.cs index fca033301..59f117a3b 100644 --- a/src/Services/Basket/Basket.API/Controllers/BasketController.cs +++ b/src/Services/Basket/Basket.API/Controllers/BasketController.cs @@ -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) diff --git a/src/Services/Basket/Basket.API/Model/CustomerBasket.cs b/src/Services/Basket/Basket.API/Model/CustomerBasket.cs index b075f3150..9ae495d4f 100644 --- a/src/Services/Basket/Basket.API/Model/CustomerBasket.cs +++ b/src/Services/Basket/Basket.API/Model/CustomerBasket.cs @@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model { public string BuyerId { get; set; } - public List Items { get; set; } + public List Items { get; set; } = new List(); public CustomerBasket() { @@ -16,7 +16,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model public CustomerBasket(string customerId) { BuyerId = customerId; - Items = new List(); } } } diff --git a/src/Web/WebMVC/Controllers/CartController.cs b/src/Web/WebMVC/Controllers/CartController.cs index 6887c8d41..b05009cc7 100644 --- a/src/Web/WebMVC/Controllers/CartController.cs +++ b/src/Web/WebMVC/Controllers/CartController.cs @@ -41,7 +41,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers return View(); } - + [HttpPost] public async Task Index(Dictionary quantities, string action) { @@ -72,7 +72,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers var user = _appUserParser.Parse(HttpContext.User); await _basketSvc.AddItemToBasket(user, productDetails.Id); } - return RedirectToAction("Index", "Catalog"); + return RedirectToAction("Index", "Catalog"); } catch (BrokenCircuitException) {