Code re-factorings and formatting for Basket.API project
This commit is contained in:
parent
386c118616
commit
d44c12e718
File diff suppressed because one or more lines are too long
@ -17,7 +17,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
|
|||||||
if (isAuthorized && !allowAnonymous)
|
if (isAuthorized && !allowAnonymous)
|
||||||
{
|
{
|
||||||
if (operation.Parameters == null)
|
if (operation.Parameters == null)
|
||||||
|
{
|
||||||
operation.Parameters = new List<IParameter>();
|
operation.Parameters = new List<IParameter>();
|
||||||
|
}
|
||||||
|
|
||||||
operation.Parameters.Add(new NonBodyParameter
|
operation.Parameters.Add(new NonBodyParameter
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
|
||||||
{
|
{
|
||||||
public class IdentitySecurityScheme:SecurityScheme
|
public class IdentitySecurityScheme : SecurityScheme
|
||||||
{
|
{
|
||||||
public IdentitySecurityScheme()
|
public IdentitySecurityScheme()
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
|||||||
{
|
{
|
||||||
// GET: /<controller>/
|
// GET: /<controller>/
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
=> new RedirectResult("~/swagger");
|
||||||
return new RedirectResult("~/swagger");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ namespace Basket.API.Infrastructure.ActionResults
|
|||||||
{
|
{
|
||||||
public InternalServerErrorObjectResult(object error)
|
public InternalServerErrorObjectResult(object error)
|
||||||
: base(error)
|
: base(error)
|
||||||
{
|
=> StatusCode = StatusCodes.Status500InternalServerError;
|
||||||
StatusCode = StatusCodes.Status500InternalServerError;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
public static class FailingMiddlewareAppBuilderExtensions
|
public static class FailingMiddlewareAppBuilderExtensions
|
||||||
{
|
{
|
||||||
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder)
|
||||||
{
|
=> UseFailingMiddleware(builder, null);
|
||||||
return UseFailingMiddleware(builder, null);
|
|
||||||
}
|
|
||||||
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder, Action<FailingOptions> action)
|
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder, Action<FailingOptions> action)
|
||||||
{
|
{
|
||||||
var options = new FailingOptions();
|
var options = new FailingOptions();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -37,7 +37,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
|
|||||||
{
|
{
|
||||||
foreach (var item in itemsToUpdate)
|
foreach (var item in itemsToUpdate)
|
||||||
{
|
{
|
||||||
if(item.UnitPrice == oldPrice)
|
if (item.UnitPrice == oldPrice)
|
||||||
{
|
{
|
||||||
var originalPrice = item.UnitPrice;
|
var originalPrice = item.UnitPrice;
|
||||||
item.UnitPrice = newPrice;
|
item.UnitPrice = newPrice;
|
||||||
|
@ -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;
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
using Basket.API.Infrastructure.Middlewares;
|
using Basket.API.Infrastructure.Middlewares;
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using static Microsoft.AspNetCore.Hosting.ApplicationInsightsWebHostBuilderExtensions;
|
||||||
using System.IO;
|
using static Microsoft.AspNetCore.Hosting.HealthCheckWebHostBuilderExtension;
|
||||||
|
using static Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions;
|
||||||
|
using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions;
|
||||||
|
using static Microsoft.AspNetCore.Hosting.WebHostExtensions;
|
||||||
|
using static Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions;
|
||||||
|
using static Microsoft.Extensions.Configuration.ChainedBuilderExtensions;
|
||||||
|
using static Microsoft.Extensions.Configuration.EnvironmentVariablesExtensions;
|
||||||
|
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
||||||
|
using Convert = System.Convert;
|
||||||
|
using Directory = System.IO.Directory;
|
||||||
|
using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost;
|
||||||
|
using WebHost = Microsoft.AspNetCore.WebHost;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
=> BuildWebHost(args).Run();
|
||||||
BuildWebHost(args).Run();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IWebHost BuildWebHost(string[] args) =>
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
@ -50,12 +50,14 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
RegisterAppInsights(services);
|
RegisterAppInsights(services);
|
||||||
|
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddMvc(options =>
|
services
|
||||||
|
.AddMvc(options =>
|
||||||
{
|
{
|
||||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||||
options.Filters.Add(typeof(ValidateModelStateFilter));
|
options.Filters.Add(typeof(ValidateModelStateFilter));
|
||||||
|
|
||||||
}).AddControllersAsServices();
|
})
|
||||||
|
.AddControllersAsServices();
|
||||||
|
|
||||||
ConfigureAuthService(services);
|
ConfigureAuthService(services);
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
//and then creating the connection it seems reasonable to move
|
//and then creating the connection it seems reasonable to move
|
||||||
//that cost to startup instead of having the first request pay the
|
//that cost to startup instead of having the first request pay the
|
||||||
//penalty.
|
//penalty.
|
||||||
services.AddSingleton<ConnectionMultiplexer>(sp =>
|
services.AddSingleton(sp =>
|
||||||
{
|
{
|
||||||
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
||||||
var configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
|
var configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
|
||||||
@ -205,7 +207,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
.UseSwaggerUI(c =>
|
.UseSwaggerUI(c =>
|
||||||
{
|
{
|
||||||
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Basket.API V1");
|
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Basket.API V1");
|
||||||
c.OAuthClientId ("basketswaggerui");
|
c.OAuthClientId("basketswaggerui");
|
||||||
c.OAuthAppName("Basket Swagger UI");
|
c.OAuthAppName("Basket Swagger UI");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -238,12 +240,14 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
|
|
||||||
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user