From 4c90ec261116ff3ef3c2d4475db15153fac9edf2 Mon Sep 17 00:00:00 2001 From: Sumit Ghosh Date: Wed, 20 Oct 2021 17:17:30 +0530 Subject: [PATCH] Apply suggestions from code review Co-authored-by: David Pine --- .../aggregator/Filters/AuthorizeCheckOperationFilter.cs | 2 +- .../aggregator/Infrastructure/GrpcExceptionInterceptor.cs | 4 ++-- .../HttpClientAuthorizationDelegatingHandler.cs | 8 ++++---- .../Web.Bff.Shopping/aggregator/Models/BasketData.cs | 2 +- .../Web.Bff.Shopping/aggregator/Models/OrderData.cs | 2 +- .../aggregator/Models/UpdateBasketItemData.cs | 4 ---- src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs | 2 +- .../aggregator/Services/IBasketService.cs | 2 +- 8 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs index 13d1c3711..a0aed7b5d 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs @@ -24,7 +24,7 @@ { new OpenApiSecurityRequirement { - [ oAuthScheme ] = new [] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" } + [ oAuthScheme ] = new[] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" } } }; } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs index 8fdbc6340..20adb2fc7 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/GrpcExceptionInterceptor.cs @@ -19,11 +19,11 @@ public class GrpcExceptionInterceptor : Interceptor return new AsyncUnaryCall(HandleResponse(call.ResponseAsync), call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose); } - private async Task HandleResponse(Task t) + private async Task HandleResponse(Task task) { try { - var response = await t; + var response = await task; return response; } catch (RpcException e) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/HttpClientAuthorizationDelegatingHandler.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/HttpClientAuthorizationDelegatingHandler.cs index e89b27206..a024560c6 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/HttpClientAuthorizationDelegatingHandler.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Infrastructure/HttpClientAuthorizationDelegatingHandler.cs @@ -15,12 +15,12 @@ public class HttpClientAuthorizationDelegatingHandler var authorizationHeader = _httpContextAccessor.HttpContext .Request.Headers["Authorization"]; - if (!string.IsNullOrEmpty(authorizationHeader)) + if (!string.IsNullOrWhitespace(authorizationHeader)) { request.Headers.Add("Authorization", new List() { authorizationHeader }); } - var token = await GetToken(); + var token = await GetTokenAsync(); if (token != null) { @@ -30,11 +30,11 @@ public class HttpClientAuthorizationDelegatingHandler return await base.SendAsync(request, cancellationToken); } - async Task GetToken() + Task GetTokenAsync() { const string ACCESS_TOKEN = "access_token"; - return await _httpContextAccessor.HttpContext + return _httpContextAccessor.HttpContext .GetTokenAsync(ACCESS_TOKEN); } } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/BasketData.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/BasketData.cs index e63974082..942eb6b74 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/BasketData.cs +++ b/src/ApiGateways/Web.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/Web.Bff.Shopping/aggregator/Models/OrderData.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/OrderData.cs index fa34b2dac..519139e77 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/OrderData.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/OrderData.cs @@ -38,6 +38,6 @@ public class OrderData public string Buyer { get; set; } - public List OrderItems { get; } = new List(); + public List OrderItems { get; } = new(); } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/UpdateBasketItemData.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/UpdateBasketItemData.cs index db0348c33..f7fa06798 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/UpdateBasketItemData.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Models/UpdateBasketItemData.cs @@ -6,8 +6,4 @@ public class UpdateBasketItemData public int NewQty { get; set; } - public UpdateBasketItemData() - { - NewQty = 0; - } } diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs index e0acaa182..70506fbda 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs @@ -1,4 +1,4 @@ -BuildWebHost(args).Run(); +await BuildWebHost(args).RunAsync(); IWebHost BuildWebHost(string[] args) => WebHost diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/IBasketService.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/IBasketService.cs index 540dd2254..1049642d2 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Services/IBasketService.cs +++ b/src/ApiGateways/Web.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); }