diff --git a/src/Services/Basket/Basket.API/Controllers/BasketController.cs b/src/Services/Basket/Basket.API/Controllers/BasketController.cs index 5bf23509c..0e64f02ed 100644 --- a/src/Services/Basket/Basket.API/Controllers/BasketController.cs +++ b/src/Services/Basket/Basket.API/Controllers/BasketController.cs @@ -18,10 +18,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers { private IBasketRepository _repository; - public BasketController(IBasketRepository repository) - { + public BasketController(IBasketRepository repository) => _repository = repository; - } + // GET api/values/5 [HttpGet("{id}")] public async Task Get(string id) @@ -42,9 +41,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers // DELETE api/values/5 [HttpDelete("{id}")] - public void Delete(string id) + public Task Delete(string id) { - _repository.DeleteBasketAsync(id); + return _repository.DeleteBasket(id); } } } diff --git a/src/Services/Basket/Basket.API/Controllers/HomeController.cs b/src/Services/Basket/Basket.API/Controllers/HomeController.cs index 5cf7ab855..f1c054adf 100644 --- a/src/Services/Basket/Basket.API/Controllers/HomeController.cs +++ b/src/Services/Basket/Basket.API/Controllers/HomeController.cs @@ -11,9 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers public class HomeController : Controller { // GET: // - public IActionResult Index() - { - return new RedirectResult("~/swagger/ui"); - } + public IActionResult Index() => + new RedirectResult("~/swagger/ui"); } } diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs index 88244404a..a8e87ad4e 100644 --- a/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs +++ b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using System.Threading.Tasks; + namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling { public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler @@ -16,7 +17,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even _repository = repository ?? throw new ArgumentNullException(nameof(repository)); } - public async Task Handle(ProductPriceChangedIntegrationEvent @event) + public async Task Handle(ProductPriceChangedIntegrationEvent @event) { var userIds = await _repository.GetUsersAsync(); @@ -32,7 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even { var itemsToUpdate = basket?.Items?.Where(x => int.Parse(x.ProductId) == productId).ToList(); - if (itemsToUpdate != null) + if ((itemsToUpdate != null) && (itemsToUpdate.Any()) { foreach (var item in itemsToUpdate) { diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs b/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs index 6f51010be..6ac83f155 100644 --- a/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs +++ b/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs @@ -7,11 +7,11 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even // An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems. public class ProductPriceChangedIntegrationEvent : IntegrationEvent { - public int ProductId { get; private set; } + public int ProductId { get; } - public decimal NewPrice { get; private set; } + public decimal NewPrice { get; } - public decimal OldPrice { get; private set; } + public decimal OldPrice { get; } public ProductPriceChangedIntegrationEvent(int productId, decimal newPrice, decimal oldPrice) { diff --git a/src/Services/Basket/Basket.API/Model/Basket.cs b/src/Services/Basket/Basket.API/Model/Basket.cs index d07c710e7..e5b0910f7 100644 --- a/src/Services/Basket/Basket.API/Model/Basket.cs +++ b/src/Services/Basket/Basket.API/Model/Basket.cs @@ -8,12 +8,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model public class CustomerBasket { public string BuyerId { get; set; } - public List Items { get; set; } + public List Items { get; set; } = new List(); - public CustomerBasket(string customerId) - { + public CustomerBasket(string customerId) => BuyerId = customerId; - Items = new List(); - } } } diff --git a/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs b/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs index 01a8b4728..f245ac7ce 100644 --- a/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs +++ b/src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs @@ -27,7 +27,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model public async Task DeleteBasketAsync(string id) { var database = await GetDatabase(); - return await database.KeyDeleteAsync(id.ToString()); + return await database.KeyDeleteAsync(id); } public async Task> GetUsersAsync() @@ -35,11 +35,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model var server = await GetServer(); IEnumerable data = server.Keys(); - if (data == null) - { - return null; - } - return data.Select(k => k.ToString()); + return data?.Select(k => k.ToString()); } public async Task GetBasketAsync(string customerId) @@ -108,7 +104,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model _redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString()); } } - } } diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 855312a65..2fdd31fd7 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -148,7 +148,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API var identityUrl = Configuration.GetValue("IdentityUrl"); app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions { - Authority = identityUrl.ToString(), + Authority = identityUrl, ScopeName = "basket", RequireHttpsMetadata = false });