Use file-scoped namespaces
This commit is contained in:
parent
5157b01e81
commit
76ddee7756
@ -1,13 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server;
|
||||||
using Microsoft.OpenApi.Models;
|
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
|
public class AuthorizationHeaderParameterOperationFilter : IOperationFilter
|
||||||
{
|
{
|
||||||
public class AuthorizationHeaderParameterOperationFilter : IOperationFilter
|
|
||||||
{
|
|
||||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||||
{
|
{
|
||||||
var filterPipeline = context.ApiDescription.ActionDescriptor.FilterDescriptors;
|
var filterPipeline = context.ApiDescription.ActionDescriptor.FilterDescriptors;
|
||||||
@ -29,5 +23,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
namespace Microsoft.eShopOnContainers.Services.Basket.API;
|
||||||
|
|
||||||
|
public class BasketSettings
|
||||||
{
|
{
|
||||||
public class BasketSettings
|
|
||||||
{
|
|
||||||
public string ConnectionString { get; set; }
|
public string ConnectionString { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,10 @@
|
|||||||
using Basket.API.IntegrationEvents.Events;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
|
||||||
using Basket.API.Model;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
[Route("api/v1/[controller]")]
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
public class BasketController : ControllerBase
|
||||||
{
|
{
|
||||||
[Route("api/v1/[controller]")]
|
|
||||||
[Authorize]
|
|
||||||
[ApiController]
|
|
||||||
public class BasketController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly IBasketRepository _repository;
|
private readonly IBasketRepository _repository;
|
||||||
private readonly IIdentityService _identityService;
|
private readonly IIdentityService _identityService;
|
||||||
private readonly IEventBus _eventBus;
|
private readonly IEventBus _eventBus;
|
||||||
@ -99,5 +86,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
|||||||
{
|
{
|
||||||
await _repository.DeleteBasketAsync(id);
|
await _repository.DeleteBasketAsync(id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
|
||||||
{
|
|
||||||
// GET: /<controller>/
|
// GET: /<controller>/
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return new RedirectResult("~/swagger");
|
return new RedirectResult("~/swagger");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
using Grpc.Core;
|
namespace GrpcBasket;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
public class BasketService : Basket.BasketBase
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace GrpcBasket
|
|
||||||
{
|
{
|
||||||
public class BasketService : Basket.BasketBase
|
|
||||||
{
|
|
||||||
private readonly IBasketRepository _repository;
|
private readonly IBasketRepository _repository;
|
||||||
private readonly ILogger<BasketService> _logger;
|
private readonly ILogger<BasketService> _logger;
|
||||||
|
|
||||||
@ -98,5 +90,4 @@ namespace GrpcBasket
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
namespace Basket.API.Infrastructure.ActionResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.ActionResults
|
public class InternalServerErrorObjectResult : ObjectResult
|
||||||
{
|
{
|
||||||
public class InternalServerErrorObjectResult : ObjectResult
|
|
||||||
{
|
|
||||||
public InternalServerErrorObjectResult(object error)
|
public InternalServerErrorObjectResult(object error)
|
||||||
: base(error)
|
: base(error)
|
||||||
{
|
{
|
||||||
StatusCode = StatusCodes.Status500InternalServerError;
|
StatusCode = StatusCodes.Status500InternalServerError;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
using System;
|
namespace Basket.API.Infrastructure.Exceptions;
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Exceptions
|
public class BasketDomainException : Exception
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Exception type for app exceptions
|
|
||||||
/// </summary>
|
|
||||||
public class BasketDomainException : Exception
|
|
||||||
{
|
|
||||||
public BasketDomainException()
|
public BasketDomainException()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -17,5 +12,5 @@ namespace Basket.API.Infrastructure.Exceptions
|
|||||||
public BasketDomainException(string message, Exception innerException)
|
public BasketDomainException(string message, Exception innerException)
|
||||||
: base(message, innerException)
|
: base(message, innerException)
|
||||||
{ }
|
{ }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
namespace Basket.API.Infrastructure.Middlewares;
|
||||||
using System;
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
return UseFailingMiddleware(builder, null);
|
return UseFailingMiddleware(builder, null);
|
||||||
@ -16,5 +13,5 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
builder.UseMiddleware<FailingMiddleware>(options);
|
builder.UseMiddleware<FailingMiddleware>(options);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,7 @@
|
|||||||
using Basket.API.Infrastructure.ActionResults;
|
namespace Basket.API.Infrastructure.Filters;
|
||||||
using Basket.API.Infrastructure.Exceptions;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
|
public partial class HttpGlobalExceptionFilter : IExceptionFilter
|
||||||
namespace Basket.API.Infrastructure.Filters
|
|
||||||
{
|
{
|
||||||
public partial class HttpGlobalExceptionFilter : IExceptionFilter
|
|
||||||
{
|
|
||||||
private readonly IWebHostEnvironment env;
|
private readonly IWebHostEnvironment env;
|
||||||
private readonly ILogger<HttpGlobalExceptionFilter> logger;
|
private readonly ILogger<HttpGlobalExceptionFilter> logger;
|
||||||
|
|
||||||
@ -54,5 +44,4 @@ namespace Basket.API.Infrastructure.Filters
|
|||||||
}
|
}
|
||||||
context.ExceptionHandled = true;
|
context.ExceptionHandled = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
namespace Basket.API.Infrastructure.Filters
|
namespace Basket.API.Infrastructure.Filters;
|
||||||
|
|
||||||
|
public class JsonErrorResponse
|
||||||
{
|
{
|
||||||
public class JsonErrorResponse
|
|
||||||
{
|
|
||||||
public string[] Messages { get; set; }
|
public string[] Messages { get; set; }
|
||||||
|
|
||||||
public object DeveloperMessage { get; set; }
|
public object DeveloperMessage { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
namespace Basket.API.Infrastructure.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Filters
|
public class ValidateModelStateFilter : ActionFilterAttribute
|
||||||
{
|
{
|
||||||
public class ValidateModelStateFilter : ActionFilterAttribute
|
|
||||||
{
|
|
||||||
public override void OnActionExecuting(ActionExecutingContext context)
|
public override void OnActionExecuting(ActionExecutingContext context)
|
||||||
{
|
{
|
||||||
if (context.ModelState.IsValid)
|
if (context.ModelState.IsValid)
|
||||||
@ -26,5 +22,5 @@ namespace Basket.API.Infrastructure.Filters
|
|||||||
|
|
||||||
context.Result = new BadRequestObjectResult(json);
|
context.Result = new BadRequestObjectResult(json);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
namespace Basket.API.Infrastructure.Filters;
|
||||||
using Microsoft.OpenApi.Models;
|
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Filters
|
public class AuthorizeCheckOperationFilter : IOperationFilter
|
||||||
{
|
{
|
||||||
public class AuthorizeCheckOperationFilter : IOperationFilter
|
|
||||||
{
|
|
||||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||||
{
|
{
|
||||||
// Check for authorize attribute
|
// Check for authorize attribute
|
||||||
@ -32,5 +26,4 @@ namespace Basket.API.Infrastructure.Filters
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,19 +1,13 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
namespace Basket.API.Infrastructure.Middlewares;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Middlewares
|
public class FailingMiddleware
|
||||||
{
|
{
|
||||||
public class FailingMiddleware
|
|
||||||
{
|
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private bool _mustFail;
|
private bool _mustFail;
|
||||||
private readonly FailingOptions _options;
|
private readonly FailingOptions _options;
|
||||||
private readonly ILogger _logger;
|
private readonly Microsoft.Extensions.Logging.ILogger _logger;
|
||||||
|
|
||||||
public FailingMiddleware(RequestDelegate next, ILogger<FailingMiddleware> logger, FailingOptions options)
|
public FailingMiddleware(RequestDelegate next, Microsoft.Extensions.Logging.ILogger<FailingMiddleware> logger, FailingOptions options)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_options = options;
|
_options = options;
|
||||||
@ -91,5 +85,4 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
(_options.EndpointPaths.Any(x => x == rpath)
|
(_options.EndpointPaths.Any(x => x == rpath)
|
||||||
|| _options.EndpointPaths.Count == 0);
|
|| _options.EndpointPaths.Count == 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
namespace Basket.API.Infrastructure.Middlewares;
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Middlewares
|
public class FailingOptions
|
||||||
{
|
{
|
||||||
public class FailingOptions
|
|
||||||
{
|
|
||||||
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>();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
namespace Basket.API.Infrastructure.Middlewares;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Middlewares
|
public class FailingStartupFilter : IStartupFilter
|
||||||
{
|
{
|
||||||
public class FailingStartupFilter : IStartupFilter
|
|
||||||
{
|
|
||||||
private readonly Action<FailingOptions> _options;
|
private readonly Action<FailingOptions> _options;
|
||||||
public FailingStartupFilter(Action<FailingOptions> optionsAction)
|
public FailingStartupFilter(Action<FailingOptions> optionsAction)
|
||||||
{
|
{
|
||||||
@ -20,5 +16,5 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
next(app);
|
next(app);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
namespace Basket.API.Infrastructure.Middlewares;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Basket.API.Infrastructure.Middlewares
|
public static class WebHostBuildertExtensions
|
||||||
{
|
{
|
||||||
public static class WebHostBuildertExtensions
|
|
||||||
{
|
|
||||||
public static IWebHostBuilder UseFailing(this IWebHostBuilder builder, Action<FailingOptions> options)
|
public static IWebHostBuilder UseFailing(this IWebHostBuilder builder, Action<FailingOptions> options)
|
||||||
{
|
{
|
||||||
builder.ConfigureServices(services =>
|
builder.ConfigureServices(services =>
|
||||||
@ -14,5 +10,5 @@ namespace Basket.API.Infrastructure.Middlewares
|
|||||||
});
|
});
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
|
||||||
using Microsoft.Extensions.Logging;
|
public class RedisBasketRepository : IBasketRepository
|
||||||
using StackExchange.Redis;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories
|
|
||||||
{
|
{
|
||||||
public class RedisBasketRepository : IBasketRepository
|
|
||||||
{
|
|
||||||
private readonly ILogger<RedisBasketRepository> _logger;
|
private readonly ILogger<RedisBasketRepository> _logger;
|
||||||
private readonly ConnectionMultiplexer _redis;
|
private readonly ConnectionMultiplexer _redis;
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
@ -69,5 +60,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Reposit
|
|||||||
var endpoint = _redis.GetEndPoints();
|
var endpoint = _redis.GetEndPoints();
|
||||||
return _redis.GetServer(endpoint.First());
|
return _redis.GetServer(endpoint.First());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
using Basket.API.IntegrationEvents.Events;
|
namespace Basket.API.IntegrationEvents.EventHandling;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Serilog.Context;
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Basket.API.IntegrationEvents.EventHandling
|
public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<OrderStartedIntegrationEvent>
|
||||||
{
|
{
|
||||||
public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<OrderStartedIntegrationEvent>
|
|
||||||
{
|
|
||||||
private readonly IBasketRepository _repository;
|
private readonly IBasketRepository _repository;
|
||||||
private readonly ILogger<OrderStartedIntegrationEventHandler> _logger;
|
private readonly ILogger<OrderStartedIntegrationEventHandler> _logger;
|
||||||
|
|
||||||
@ -30,8 +22,8 @@ namespace Basket.API.IntegrationEvents.EventHandling
|
|||||||
await _repository.DeleteBasketAsync(@event.UserId.ToString());
|
await _repository.DeleteBasketAsync(@event.UserId.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +1,7 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Serilog.Context;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling
|
public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>
|
||||||
{
|
{
|
||||||
public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>
|
|
||||||
{
|
|
||||||
private readonly ILogger<ProductPriceChangedIntegrationEventHandler> _logger;
|
private readonly ILogger<ProductPriceChangedIntegrationEventHandler> _logger;
|
||||||
private readonly IBasketRepository _repository;
|
private readonly IBasketRepository _repository;
|
||||||
|
|
||||||
@ -59,6 +50,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
|
|||||||
await _repository.UpdateBasketAsync(basket);
|
await _repository.UpdateBasketAsync(basket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
namespace Basket.API.IntegrationEvents.Events;
|
||||||
|
|
||||||
namespace Basket.API.IntegrationEvents.Events
|
// Integration Events notes:
|
||||||
|
// 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 record OrderStartedIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
// Integration Events notes:
|
|
||||||
// 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 record OrderStartedIntegrationEvent : IntegrationEvent
|
|
||||||
{
|
|
||||||
public string UserId { get; init; }
|
public string UserId { get; init; }
|
||||||
|
|
||||||
public OrderStartedIntegrationEvent(string userId)
|
public OrderStartedIntegrationEvent(string userId)
|
||||||
=> UserId = userId;
|
=> UserId = userId;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events
|
// Integration Events notes:
|
||||||
|
// 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 record ProductPriceChangedIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
// Integration Events notes:
|
|
||||||
// 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 record ProductPriceChangedIntegrationEvent : IntegrationEvent
|
|
||||||
{
|
|
||||||
public int ProductId { get; private init; }
|
public int ProductId { get; private init; }
|
||||||
|
|
||||||
public decimal NewPrice { get; private init; }
|
public decimal NewPrice { get; private init; }
|
||||||
@ -19,5 +17,5 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
|
|||||||
NewPrice = newPrice;
|
NewPrice = newPrice;
|
||||||
OldPrice = oldPrice;
|
OldPrice = oldPrice;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
namespace Basket.API.IntegrationEvents.Events;
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Basket.API.IntegrationEvents.Events
|
public record UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
public record UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
|
|
||||||
{
|
|
||||||
public string UserId { get; }
|
public string UserId { get; }
|
||||||
|
|
||||||
public string UserName { get; }
|
public string UserName { get; }
|
||||||
@ -60,5 +56,4 @@ namespace Basket.API.IntegrationEvents.Events
|
|||||||
RequestId = requestId;
|
RequestId = requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
using System;
|
namespace Basket.API.Model;
|
||||||
|
public class BasketCheckout
|
||||||
namespace Basket.API.Model
|
|
||||||
{
|
{
|
||||||
public class BasketCheckout
|
|
||||||
{
|
|
||||||
public string City { get; set; }
|
public string City { get; set; }
|
||||||
|
|
||||||
public string Street { get; set; }
|
public string Street { get; set; }
|
||||||
@ -27,6 +24,4 @@ namespace Basket.API.Model
|
|||||||
public string Buyer { get; set; }
|
public string Buyer { get; set; }
|
||||||
|
|
||||||
public Guid RequestId { get; set; }
|
public Guid RequestId { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
public class BasketItem : IValidatableObject
|
||||||
{
|
{
|
||||||
public class BasketItem : IValidatableObject
|
|
||||||
{
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
public string ProductName { get; set; }
|
public string ProductName { get; set; }
|
||||||
@ -23,5 +20,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||||
|
public class CustomerBasket
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|
||||||
{
|
{
|
||||||
public class CustomerBasket
|
|
||||||
{
|
|
||||||
public string BuyerId { get; set; }
|
public string BuyerId { get; set; }
|
||||||
|
|
||||||
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
|
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
|
||||||
@ -17,5 +14,5 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|||||||
{
|
{
|
||||||
BuyerId = customerId;
|
BuyerId = customerId;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
public interface IBasketRepository
|
||||||
{
|
{
|
||||||
public interface IBasketRepository
|
|
||||||
{
|
|
||||||
Task<CustomerBasket> GetBasketAsync(string customerId);
|
Task<CustomerBasket> GetBasketAsync(string customerId);
|
||||||
IEnumerable<string> GetUsers();
|
IEnumerable<string> GetUsers();
|
||||||
Task<CustomerBasket> UpdateBasketAsync(CustomerBasket basket);
|
Task<CustomerBasket> UpdateBasketAsync(CustomerBasket basket);
|
||||||
Task<bool> DeleteBasketAsync(string id);
|
Task<bool> DeleteBasketAsync(string id);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,4 @@
|
|||||||
using Basket.API.Infrastructure.Middlewares;
|
var configuration = GetConfiguration();
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Azure.Identity;
|
|
||||||
using Serilog;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using Azure.Core;
|
|
||||||
|
|
||||||
var configuration = GetConfiguration();
|
|
||||||
|
|
||||||
Log.Logger = CreateSerilogLogger(configuration);
|
Log.Logger = CreateSerilogLogger(configuration);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services;
|
||||||
|
|
||||||
|
public interface IIdentityService
|
||||||
{
|
{
|
||||||
public interface IIdentityService
|
|
||||||
{
|
|
||||||
string GetUserIdentity();
|
string GetUserIdentity();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Services;
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
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)
|
||||||
@ -17,5 +13,5 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Services
|
|||||||
{
|
{
|
||||||
return _context.HttpContext.User.FindFirst("sub").Value;
|
return _context.HttpContext.User.FindFirst("sub").Value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,43 +1,7 @@
|
|||||||
using Autofac;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API;
|
||||||
using Autofac.Extensions.DependencyInjection;
|
|
||||||
using Basket.API.Infrastructure.Filters;
|
|
||||||
using Basket.API.IntegrationEvents.EventHandling;
|
|
||||||
using Basket.API.IntegrationEvents.Events;
|
|
||||||
using GrpcBasket;
|
|
||||||
using HealthChecks.UI.Client;
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Azure.ServiceBus;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.OpenApi.Models;
|
|
||||||
using RabbitMQ.Client;
|
|
||||||
using StackExchange.Redis;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
public class Startup
|
||||||
{
|
{
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
@ -66,7 +30,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
|
|
||||||
services.AddSwaggerGen(options =>
|
services.AddSwaggerGen(options =>
|
||||||
{
|
{
|
||||||
options.DescribeAllEnumsAsStrings();
|
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo
|
options.SwaggerDoc("v1", new OpenApiInfo
|
||||||
{
|
{
|
||||||
Title = "eShopOnContainers - Basket HTTP API",
|
Title = "eShopOnContainers - Basket HTTP API",
|
||||||
@ -323,10 +286,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
|
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
|
||||||
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();
|
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CustomExtensionMethods
|
public static class CustomExtensionMethods
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var hcBuilder = services.AddHealthChecks();
|
var hcBuilder = services.AddHealthChecks();
|
||||||
@ -359,5 +322,4 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
namespace Microsoft.eShopOnContainers.Services.Basket.API;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
internal class TestHttpResponseTrailersFeature : IHttpResponseTrailersFeature
|
||||||
{
|
{
|
||||||
internal class TestHttpResponseTrailersFeature : IHttpResponseTrailersFeature
|
|
||||||
{
|
|
||||||
public IHeaderDictionary Trailers { get; set; }
|
public IHeaderDictionary Trailers { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user