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]
|
[HttpPost]
|
||||||
[ProducesResponseType(typeof(CustomerBasket), (int)HttpStatusCode.OK)]
|
[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));
|
return Ok(await _repository.UpdateBasketAsync(value));
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ProducesResponseType((int)HttpStatusCode.Accepted)]
|
[ProducesResponseType((int)HttpStatusCode.Accepted)]
|
||||||
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
|
[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();
|
var userId = _identityService.GetUserIdentity();
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
new Claim("name", "Test user"),
|
new Claim("name", "Test user"),
|
||||||
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/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("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("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","User"),
|
||||||
new Claim("sub", currentUserId),
|
new Claim("sub", currentUserId),
|
||||||
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","Microsoft")}
|
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 bool _mustFail;
|
||||||
private readonly FailingOptions _options;
|
private readonly FailingOptions _options;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
|
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
@ -19,6 +20,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
_mustFail = false;
|
_mustFail = false;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
{
|
{
|
||||||
var path = context.Request.Path;
|
var path = context.Request.Path;
|
||||||
@ -44,7 +46,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
private async Task ProcessConfigRequest(HttpContext context)
|
private async Task ProcessConfigRequest(HttpContext context)
|
||||||
{
|
{
|
||||||
var enable = context.Request.Query.Keys.Any(k => k == "enable");
|
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)
|
if (enable && disable)
|
||||||
{
|
{
|
||||||
@ -86,7 +88,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
}
|
}
|
||||||
|
|
||||||
return _mustFail &&
|
return _mustFail &&
|
||||||
(_options.EndpointPaths.Any(x => x == rpath)
|
(_options.EndpointPaths.Any(x => x == rpath)
|
||||||
|| _options.EndpointPaths.Count == 0);
|
|| _options.EndpointPaths.Count == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
public string ConfigPath = "/Failing";
|
public string ConfigPath = "/Failing";
|
||||||
public List<string> EndpointPaths { get; set; } = new List<string>();
|
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 string UserId { get; set; }
|
||||||
|
|
||||||
public OrderStartedIntegrationEvent(string userId)
|
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 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.
|
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
|
||||||
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
|
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int ProductId { get; private set; }
|
public int ProductId { get; private set; }
|
||||||
|
|
||||||
public decimal NewPrice { get; private set; }
|
public decimal NewPrice { get; private set; }
|
||||||
|
@ -18,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|||||||
|
|
||||||
if (Quantity < 1)
|
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;
|
return results;
|
||||||
|
@ -61,9 +61,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
|
|
||||||
})
|
})
|
||||||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
||||||
.UseFailing(options => {
|
.UseFailing(options =>
|
||||||
|
{
|
||||||
options.ConfigPath = "/Failing";
|
options.ConfigPath = "/Failing";
|
||||||
options.NotFilteredPaths.AddRange(new[] {"/hc","/liveness"});
|
options.NotFilteredPaths.AddRange(new[] { "/hc", "/liveness" });
|
||||||
})
|
})
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
@ -6,7 +6,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
|
|||||||
{
|
{
|
||||||
public class IdentityService : IIdentityService
|
public class IdentityService : IIdentityService
|
||||||
{
|
{
|
||||||
private IHttpContextAccessor _context;
|
private IHttpContextAccessor _context;
|
||||||
|
|
||||||
public IdentityService(IHttpContextAccessor context)
|
public IdentityService(IHttpContextAccessor context)
|
||||||
{
|
{
|
||||||
|
@ -211,7 +211,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
ConfigureAuth(app);
|
ConfigureAuth(app);
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapGrpcService<BasketService>();
|
endpoints.MapGrpcService<BasketService>();
|
||||||
@ -253,22 +253,22 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
|
|
||||||
private void ConfigureAuthService(IServiceCollection services)
|
private void ConfigureAuthService(IServiceCollection services)
|
||||||
{
|
{
|
||||||
// prevent from mapping "sub" claim to nameidentifier.
|
// prevent from mapping "sub" claim to nameidentifier.
|
||||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
|
||||||
|
|
||||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
|
||||||
}).AddJwtBearer(options =>
|
}).AddJwtBearer(options =>
|
||||||
{
|
{
|
||||||
options.Authority = identityUrl;
|
options.Authority = identityUrl;
|
||||||
options.RequireHttpsMetadata = false;
|
options.RequireHttpsMetadata = false;
|
||||||
options.Audience = "basket";
|
options.Audience = "basket";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
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.AspNetCore.Routing;
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API;
|
using Microsoft.eShopOnContainers.Services.Basket.API;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Basket.FunctionalTests.Base
|
namespace Basket.FunctionalTests.Base
|
||||||
{
|
{
|
||||||
@ -20,7 +20,7 @@ namespace Basket.FunctionalTests.Base
|
|||||||
services.Configure<RouteOptions>(Configuration);
|
services.Configure<RouteOptions>(Configuration);
|
||||||
return base.ConfigureServices(services);
|
return base.ConfigureServices(services);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ConfigureAuth(IApplicationBuilder app)
|
protected override void ConfigureAuth(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||||
|
@ -73,7 +73,7 @@ namespace Basket.FunctionalTests
|
|||||||
|
|
||||||
string BuildCheckout()
|
string BuildCheckout()
|
||||||
{
|
{
|
||||||
var checkoutBasket = new
|
var checkoutBasket = new
|
||||||
{
|
{
|
||||||
City = "city",
|
City = "city",
|
||||||
Street = "street",
|
Street = "street",
|
||||||
|
@ -33,7 +33,7 @@ namespace Basket.FunctionalTests
|
|||||||
Assert.Single(basket.Items);
|
Assert.Single(basket.Items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -58,7 +58,7 @@ namespace Basket.FunctionalTests
|
|||||||
|
|
||||||
Assert.True(deleteResult);
|
Assert.True(deleteResult);
|
||||||
Assert.Null(result);
|
Assert.Null(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RedisBasketRepository BuildBasketRepository(ConnectionMultiplexer connMux)
|
RedisBasketRepository BuildBasketRepository(ConnectionMultiplexer connMux)
|
||||||
|
@ -19,7 +19,7 @@ namespace Catalog.API.Grpc
|
|||||||
private readonly CatalogContext _catalogContext;
|
private readonly CatalogContext _catalogContext;
|
||||||
private readonly CatalogSettings _settings;
|
private readonly CatalogSettings _settings;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
|
public CatalogService(CatalogContext dbContext, IOptions<CatalogSettings> settings, ILogger<CatalogService> logger)
|
||||||
{
|
{
|
||||||
_settings = settings.Value;
|
_settings = settings.Value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user