Swamy/15jan2021 small refactoring (#1580)
* Small Refactoring inside Basket Service folder * Small Refactoring
This commit is contained in:
parent
afb4534acc
commit
130e46ccdf
@ -46,7 +46,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
|
||||
public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody]CustomerBasket value)
|
||||
public async Task<ActionResult<CustomerBasket>> UpdateBasketAsync([FromBody] CustomerBasket value)
|
||||
{
|
||||
return Ok(await _repository.UpdateBasketAsync(value));
|
||||
}
|
||||
@ -55,7 +55,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
[HttpPost]
|
||||
[ProducesResponseType((int)HttpStatusCode.Accepted)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
||||
public async Task<ActionResult> CheckoutAsync([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
public async Task<ActionResult> CheckoutAsync([FromBody] BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
|
||||
{
|
||||
var userId = _identityService.GetUserIdentity();
|
||||
|
||||
|
@ -62,7 +62,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
new Claim("name", "Test user"),
|
||||
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "Test user"),
|
||||
new Claim("nonce", Guid.NewGuid().ToString()),
|
||||
new Claim("http://schemas.microsoft.com/identity/claims/identityprovider", "ByPassAuthMiddleware"),
|
||||
new Claim("http://schemas.microsoft.com/identity/claims/identityprovider", "ByPassAuthMiddleware"),
|
||||
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","User"),
|
||||
new Claim("sub", currentUserId),
|
||||
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","Microsoft")}
|
||||
|
@ -12,6 +12,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
private bool _mustFail;
|
||||
private readonly FailingOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
|
||||
{
|
||||
_next = next;
|
||||
@ -19,6 +20,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
_mustFail = false;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var path = context.Request.Path;
|
||||
@ -44,7 +46,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
private async Task ProcessConfigRequest(HttpContext context)
|
||||
{
|
||||
var enable = context.Request.Query.Keys.Any(k => k == "enable");
|
||||
var disable = context.Request.Query.Keys.Any(k => k == "disable");
|
||||
var disable = context.Request.Query.Keys.Any(k => k == "disable");
|
||||
|
||||
if (enable && disable)
|
||||
{
|
||||
@ -86,7 +88,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
}
|
||||
|
||||
return _mustFail &&
|
||||
(_options.EndpointPaths.Any(x => x == rpath)
|
||||
(_options.EndpointPaths.Any(x => x == rpath)
|
||||
|| _options.EndpointPaths.Count == 0);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
public string ConfigPath = "/Failing";
|
||||
public List<string> EndpointPaths { get; set; } = new List<string>();
|
||||
|
||||
public List<string> NotFilteredPaths {get; set;} = new List<string>();
|
||||
public List<string> NotFilteredPaths { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ namespace Basket.API.IntegrationEvents.Events
|
||||
public string UserId { get; set; }
|
||||
|
||||
public OrderStartedIntegrationEvent(string userId)
|
||||
=> UserId = userId;
|
||||
=> UserId = userId;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
|
||||
// An Event is “something that has happened in the past”, therefore its name has to be
|
||||
// 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 decimal NewPrice { get; private set; }
|
||||
|
@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||
|
||||
if (Quantity < 1)
|
||||
{
|
||||
results.Add(new ValidationResult("Invalid number of units", new []{ "Quantity" }));
|
||||
results.Add(new ValidationResult("Invalid number of units", new[] { "Quantity" }));
|
||||
}
|
||||
|
||||
return results;
|
||||
|
@ -61,9 +61,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
|
||||
})
|
||||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
||||
.UseFailing(options => {
|
||||
.UseFailing(options =>
|
||||
{
|
||||
options.ConfigPath = "/Failing";
|
||||
options.NotFilteredPaths.AddRange(new[] {"/hc","/liveness"});
|
||||
options.NotFilteredPaths.AddRange(new[] { "/hc", "/liveness" });
|
||||
})
|
||||
.UseStartup<Startup>()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
|
@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
|
||||
{
|
||||
public class IdentityService : IIdentityService
|
||||
{
|
||||
private IHttpContextAccessor _context;
|
||||
private IHttpContextAccessor _context;
|
||||
|
||||
public IdentityService(IHttpContextAccessor context)
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
ConfigureAuth(app);
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapGrpcService<BasketService>();
|
||||
@ -253,22 +253,22 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
|
||||
private void ConfigureAuthService(IServiceCollection services)
|
||||
{
|
||||
// prevent from mapping "sub" claim to nameidentifier.
|
||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
||||
// prevent from mapping "sub" claim to nameidentifier.
|
||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
||||
|
||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
|
||||
}).AddJwtBearer(options =>
|
||||
{
|
||||
options.Authority = identityUrl;
|
||||
options.RequireHttpsMetadata = false;
|
||||
options.Audience = "basket";
|
||||
});
|
||||
}).AddJwtBearer(options =>
|
||||
{
|
||||
options.Authority = identityUrl;
|
||||
options.RequireHttpsMetadata = false;
|
||||
options.Audience = "basket";
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
namespace Basket.FunctionalTests.Base
|
||||
{
|
||||
@ -20,7 +20,7 @@ namespace Basket.FunctionalTests.Base
|
||||
services.Configure<RouteOptions>(Configuration);
|
||||
return base.ConfigureServices(services);
|
||||
}
|
||||
|
||||
|
||||
protected override void ConfigureAuth(IApplicationBuilder app)
|
||||
{
|
||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||
|
@ -73,7 +73,7 @@ namespace Basket.FunctionalTests
|
||||
|
||||
string BuildCheckout()
|
||||
{
|
||||
var checkoutBasket = new
|
||||
var checkoutBasket = new
|
||||
{
|
||||
City = "city",
|
||||
Street = "street",
|
||||
|
@ -33,7 +33,7 @@ namespace Basket.FunctionalTests
|
||||
Assert.Single(basket.Items);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -58,7 +58,7 @@ namespace Basket.FunctionalTests
|
||||
|
||||
Assert.True(deleteResult);
|
||||
Assert.Null(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RedisBasketRepository BuildBasketRepository(ConnectionMultiplexer connMux)
|
||||
|
@ -19,7 +19,7 @@ namespace Catalog.API.Grpc
|
||||
private readonly CatalogContext _catalogContext;
|
||||
private readonly CatalogSettings _settings;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
||||
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
|
||||
{
|
||||
_settings = settings.Value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user