Fix mvc calls to grpc
This commit is contained in:
parent
9bb640aee4
commit
4398b25fc1
@ -125,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()
|
||||||
{
|
{
|
||||||
@ -142,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);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
|||||||
var request = MapToCustomerBasketRequest(currentBasket);
|
var request = MapToCustomerBasketRequest(currentBasket);
|
||||||
_logger.LogDebug("Grpc update basket request {@request}", request);
|
_logger.LogDebug("Grpc update basket request {@request}", request);
|
||||||
|
|
||||||
return client.UpdateBasketAsync(request);
|
return await client.UpdateBasketAsync(request);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user