From 3a0f094d53ea7c3cf132f4b30e4f4fafdc125387 Mon Sep 17 00:00:00 2001 From: Sumit Ghosh Date: Wed, 20 Oct 2021 17:15:13 +0530 Subject: [PATCH] Apply suggestions from code review Co-authored-by: David Pine --- .../aggregator/Controllers/HomeController.cs | 2 +- .../Mobile.Bff.Shopping/aggregator/Models/BasketData.cs | 2 +- .../Mobile.Bff.Shopping/aggregator/Models/OrderData.cs | 2 +- src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs | 2 +- .../aggregator/Services/IBasketService.cs | 2 +- .../aggregator/Controllers/BasketController.cs | 4 ++-- .../aggregator/Controllers/HomeController.cs | 2 +- .../aggregator/Controllers/OrderController.cs | 5 +++-- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs index 5c931462a..5328f308d 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Controllers/HomeController.cs @@ -3,7 +3,7 @@ [Route("")] public class HomeController : Controller { - [HttpGet()] + [HttpGet] public IActionResult Index() { return new RedirectResult("~/swagger"); diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/BasketData.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/BasketData.cs index 6a57b4d70..d47e6efbd 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/BasketData.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/BasketData.cs @@ -4,7 +4,7 @@ public class BasketData { public string BuyerId { get; set; } - public List Items { get; set; } = new List(); + public List Items { get; set; } = new(); public BasketData() { diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/OrderData.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/OrderData.cs index c707eb408..8761417ab 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/OrderData.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Models/OrderData.cs @@ -38,5 +38,5 @@ public class OrderData public string Buyer { get; set; } - public List OrderItems { get; } = new List(); + public List OrderItems { get; } = new(); } diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs index 290fc9545..c5d6e10ff 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs @@ -1,4 +1,4 @@ -BuildWebHost(args).Run(); +await BuildWebHost(args).RunAsync(); IWebHost BuildWebHost(string[] args) => WebHost .CreateDefaultBuilder(args) diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/IBasketService.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/IBasketService.cs index 518daffcf..e1c9a24bf 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/IBasketService.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/IBasketService.cs @@ -2,7 +2,7 @@ public interface IBasketService { - Task GetById(string id); + Task GetByIdAsync(string id); Task UpdateAsync(BasketData currentBasket); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs index cf2f7dca7..008ded21b 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/BasketController.cs @@ -26,7 +26,7 @@ public class BasketController : ControllerBase } // Retrieve the current basket - var basket = await _basket.GetById(data.BuyerId) ?? new BasketData(data.BuyerId); + var basket = await _basket.GetByIdAsync(data.BuyerId) ?? new BasketData(data.BuyerId); var catalogItems = await _catalog.GetCatalogItemsAsync(data.Items.Select(x => x.ProductId)); // group by product id to avoid duplicates @@ -84,7 +84,7 @@ public class BasketController : ControllerBase } // Retrieve the current basket - var currentBasket = await _basket.GetById(data.BasketId); + var currentBasket = await _basket.GetByIdAsync(data.BasketId); if (currentBasket == null) { return BadRequest($"Basket with id {data.BasketId} not found."); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/HomeController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/HomeController.cs index 450ad9575..55df5880b 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/HomeController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/HomeController.cs @@ -3,7 +3,7 @@ [Route("")] public class HomeController : Controller { - [HttpGet()] + [HttpGet] public IActionResult Index() { return new RedirectResult("~/swagger"); diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs index 630b34b57..5897a5c86 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Controllers/OrderController.cs @@ -7,6 +7,7 @@ public class OrderController : ControllerBase { private readonly IBasketService _basketService; private readonly IOrderingService _orderingService; + public OrderController(IBasketService basketService, IOrderingService orderingService) { _basketService = basketService; @@ -19,12 +20,12 @@ public class OrderController : ControllerBase [ProducesResponseType(typeof(OrderData), (int)HttpStatusCode.OK)] public async Task> GetOrderDraftAsync(string basketId) { - if (string.IsNullOrEmpty(basketId)) + if (string.IsNullOrWhitespace(basketId)) { return BadRequest("Need a valid basketid"); } // Get the basket data and build a order draft based on it - var basket = await _basketService.GetById(basketId); + var basket = await _basketService.GetByIdAsync(basketId); if (basket == null) {