diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs deleted file mode 100644 index 57321418b..000000000 --- a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Ordering.API.Application.IntegrationEvents.Events; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using TenantACustomisations.Services; - -namespace TenantACustomisations.IntegrationEvents.EventHandling -{ - public class CustomisationEventHandler : IIntegrationEventHandler - { - - private readonly ILogger _logger; - private readonly IEventBus _eventBus; - private readonly IValidationService validationService; - - public CustomisationEventHandler(ILogger logger, IEventBus eventBus) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); - validationService = new ValidationService(); - } - - public async Task Handle(CustomisationEvent @event) - { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); - IntegrationEvent integrationEvent = @event.@event; - - switch (integrationEvent.GetType().Name) - { - case "UserCheckoutAcceptedIntegrationEvent": - if (validationService.Validate((UserCheckoutAcceptedIntegrationEvent)integrationEvent)) - { - integrationEvent.CheckForCustomisation = false; - _eventBus.Publish(integrationEvent); - } - break; - default: - integrationEvent.CheckForCustomisation = false; - _eventBus.Publish(integrationEvent); - break; - } - } - } -} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs deleted file mode 100644 index fb8196ebf..000000000 --- a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs +++ /dev/null @@ -1,60 +0,0 @@ -using MediatR; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; -using Microsoft.Extensions.Logging; -using Ordering.API.Application.Behaviors; -using Serilog.Context; -using System.Threading.Tasks; -using System; -using System.Diagnostics; -using TenantACustomisations.IntegrationEvents.Events; -using TenantACustomisations.ExternalServices; -using TenantACustomisations.Database; - -namespace TenantACustomisations.IntegrationEvents.EventHandling -{ - public class TenantAUserCheckoutAcceptedIntegrationEventHandler : - IIntegrationEventHandler - { - private readonly IMediator _mediator; - private readonly IEventBus _eventBus; - private readonly ILogger _logger; - //private readonly TenantAContext _context; - //private readonly IShippingService _shippingService; - - public TenantAUserCheckoutAcceptedIntegrationEventHandler( - IMediator mediator, - ILogger logger, - IEventBus eventBus - ) - { - _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); - } - - /// - /// Integration event handler which starts the create order process - /// - /// - /// Integration event message which is sent by the - /// basket.api once it has successfully process the - /// order items. - /// - /// - public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event) - { - using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) - { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA- ({@IntegrationEvent})", @event.Id, @event); - _logger.LogInformation("Hello"); - - //TODO - Debug.WriteLine(@event); - //Save shipping info - //Hard code view comp - //Retrieve shipping info and show - } - } - } -} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs deleted file mode 100644 index 7f6fa4a36..000000000 --- a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; -using Ordering.API.Application.Models; -using System; - -namespace TenantACustomisations.IntegrationEvents.Events -{ - public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent - { - public string UserId { get; } - - public string UserName { get; } - - public string City { get; set; } - - public string Street { get; set; } - - public string State { get; set; } - - public string Country { get; set; } - - public string ZipCode { get; set; } - - public string CardNumber { get; set; } - - public string CardHolderName { get; set; } - - public DateTime CardExpiration { get; set; } - - public string CardSecurityNumber { get; set; } - - public int CardTypeId { get; set; } - - public string Buyer { get; set; } - - public Guid RequestId { get; set; } - - public CustomerBasket Basket { get; } - - public UserCheckoutAcceptedIntegrationEvent(string userId, string userName, string city, string street, - string state, string country, string zipCode, string cardNumber, string cardHolderName, - DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId, - CustomerBasket basket) - { - UserId = userId; - City = city; - Street = street; - State = state; - Country = country; - ZipCode = zipCode; - CardNumber = cardNumber; - CardHolderName = cardHolderName; - CardExpiration = cardExpiration; - CardSecurityNumber = cardSecurityNumber; - CardTypeId = cardTypeId; - Buyer = buyer; - Basket = basket; - RequestId = requestId; - UserName = userName; - } - - } -} diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs new file mode 100644 index 000000000..1c2aa2da7 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using TenantACustomisations.ExternalServices; + +namespace TenantACustomisations.Database +{ + public class DbInitializer + { + public void Initialize(TenantAContext context) + { + context.Database.EnsureCreated(); + + if (context.ShippingInformation.Any()) + { + return; + } + + ShippingInformation shippingInformation = new ShippingInformation(); + shippingInformation.ShippingTime = DateTime.Today; + shippingInformation.ArrivalTime = DateTime.Today.AddDays(2); + shippingInformation.FragilityLevel = Fragility.Medium; + shippingInformation.PriorityLevel = Priority.High; + shippingInformation.ShippingInformationId = 1; + shippingInformation.OrderNumber = "1"; + context.ShippingInformation.Add(shippingInformation); + + context.SaveChanges(); + + + } + } +} diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs new file mode 100644 index 000000000..222d63dd8 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using TenantACustomisations.ExternalServices; +using TenantACustomisations.IntegrationEvents.Events; + +namespace TenantACustomisations.Database +{ + public class TenantAContext : DbContext + { + public TenantAContext(DbContextOptions options) + : base(options) + { + } + + public DbSet ShippingInformation { get; set; } + + public DbSet SavedEvent + { + get; + set; + } + + } + public class TenantAContextDesignFactory : IDesignTimeDbContextFactory + { + public TenantAContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantADb;Integrated Security=true"); + + return new TenantAContext(optionsBuilder.Options); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs similarity index 100% rename from src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs rename to src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs diff --git a/src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs similarity index 100% rename from src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs rename to src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs deleted file mode 100644 index 37a0c3c01..000000000 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.AspNetCore.SignalR; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; -using Microsoft.Extensions.Logging; -using Serilog.Context; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; -using TenantAShippingInformation.IntegrationEvents.Events; - -namespace TenantAShippingInformation.IntegrationEvents.EventHandling -{ - public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : - IIntegrationEventHandler - { - private readonly ILogger _logger; - - public OrderStatusChangedToAwaitingValidationIntegrationEventHandler(ILogger logger) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - - public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event) - { - using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) - { - //TODO - Debug.WriteLine(@event); - - } - } - } -} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs similarity index 58% rename from src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs rename to src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs index 78cb7a46d..4accdc935 100644 --- a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs @@ -7,11 +7,12 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using TenantACustomisations.Database; -using TenantACustomisations.ExternalServices; -using TenantACustomisations.IntegrationEvents.Events; +using TenantAShippingInformation.Database; +using TenantAShippingInformation.ExternalServices; +using TenantAShippingInformation.IntegrationEvents.Events; +using TenantAShippingInformation.Models; -namespace TenantACustomisations.IntegrationEvents.EventHandling +namespace TenantAShippingInformation.IntegrationEvents.EventHandling { public class OrderStatusChangedToSubmittedIntegrationEventHandler : IIntegrationEventHandler @@ -31,14 +32,14 @@ namespace TenantACustomisations.IntegrationEvents.EventHandling { using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) { - _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA - ({@IntegrationEvent})", @event.Id, @event); - _logger.LogInformation("Hello"); - //TODO - Debug.WriteLine(@event); - ShippingInformation shippingInformation = _shippingService.CalculateShippingInformation(@event.OrderId); - _context.ShippingInformation.Add(shippingInformation); - _logger.LogInformation("----- Saving shipping information: {IntegrationEventId} at TenantA - ({@IntegrationEvent}) - {@ShippingInformation}", @event.Id, @event, shippingInformation); - _context.SaveChanges(); + using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) + { + _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA - ({@IntegrationEvent})", @event.Id, @event); + ShippingInformation shippingInformation = _shippingService.CalculateShippingInformation(@event.OrderId); + _context.ShippingInformation.Add(shippingInformation); + _logger.LogInformation("----- Saving shipping information: {IntegrationEventId} at TenantA - ({@IntegrationEvent}) - {@ShippingInformation}", @event.Id, @event, shippingInformation); + _context.SaveChanges(); + } } } } diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs deleted file mode 100644 index bbaf49a85..000000000 --- a/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - -namespace TenantAShippingInformation.IntegrationEvents.Events -{ - public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent - { - public int OrderId { get; } - public IEnumerable OrderStockItems { get; } - - public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, - IEnumerable orderStockItems) - { - OrderId = orderId; - OrderStockItems = orderStockItems; - } - } - - public class OrderStockItem - { - public int ProductId { get; } - public int Units { get; } - - public OrderStockItem(int productId, int units) - { - ProductId = productId; - Units = units; - } - } -} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs similarity index 100% rename from src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs rename to src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs new file mode 100644 index 000000000..a2afffc22 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public enum Fragility + { + Low, Medium, High + } +} diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs new file mode 100644 index 000000000..cd0efcb73 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public enum Priority + { + Low, Medium, High + } +} diff --git a/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs new file mode 100644 index 000000000..f83a7d5cb --- /dev/null +++ b/src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantACustomisations.ExternalServices +{ + public class ShippingInformation + { + public int ShippingInformationId { get; set; } + public DateTime ArrivalTime { get; set; } + public DateTime ShippingTime { get; set; } + public Priority PriorityLevel {get;set;} + public Fragility FragilityLevel { get; set; } + public String OrderNumber { get; set; } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs new file mode 100644 index 000000000..33b06d0c6 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using TenantAShippingInformation.Models; + +namespace TenantAShippingInformation.Database +{ + public class DbInitializer + { + public void Initialize(TenantAContext context) + { + context.Database.EnsureCreated(); + + if (context.ShippingInformation.Any()) + { + return; + } + + ShippingInformation shippingInformation = new ShippingInformation(); + shippingInformation.ShippingTime = DateTime.Today; + shippingInformation.ArrivalTime = DateTime.Today.AddDays(2); + shippingInformation.FragilityLevel = Fragility.Medium; + shippingInformation.PriorityLevel = Priority.High; + shippingInformation.ShippingInformationId = 1; + shippingInformation.OrderNumber = "1"; + context.ShippingInformation.Add(shippingInformation); + + context.SaveChanges(); + + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs new file mode 100644 index 000000000..022772bd1 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using TenantAShippingInformation.Models; + +namespace TenantAShippingInformation.Database +{ + public class TenantAContext : DbContext + { + public TenantAContext(DbContextOptions options) + : base(options) + { + } + + public DbSet ShippingInformation { get; set; } + + + } + public class TenantAContextDesignFactory : IDesignTimeDbContextFactory + { + public TenantAContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantAShippingInformationDb;Integrated Security=true"); + + return new TenantAContext(optionsBuilder.Options); + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile b/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile new file mode 100644 index 000000000..cb6d18737 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile @@ -0,0 +1,59 @@ +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build +WORKDIR /src + +# Keep the project list and command dotnet restore identical in all Dockfiles to maximize image cache utilization +COPY eShopOnContainers-ServicesAndWebApps.sln . +COPY docker-compose.dcproj /src/ +COPY src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj src/ApiGateways/ApiGw-Base/ +COPY src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj src/ApiGateways/Mobile.Bff.Shopping/aggregator/ +COPY src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj src/ApiGateways/Web.Bff.Shopping/aggregator/ +COPY src/BuildingBlocks/Devspaces.Support/Devspaces.Support.csproj src/BuildingBlocks/Devspaces.Support/ +COPY src/BuildingBlocks/EventBus/EventBus/EventBus.csproj src/BuildingBlocks/EventBus/EventBus/ +COPY src/BuildingBlocks/EventBus/EventBus.Tests/EventBus.Tests.csproj src/BuildingBlocks/EventBus/EventBus.Tests/ +COPY src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj src/BuildingBlocks/EventBus/EventBusRabbitMQ/ +COPY src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj src/BuildingBlocks/EventBus/EventBusServiceBus/ +COPY src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj src/BuildingBlocks/EventBus/IntegrationEventLogEF/ +COPY src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj src/BuildingBlocks/WebHostCustomization/WebHost.Customization/ +COPY src/Services/Basket/Basket.API/Basket.API.csproj src/Services/Basket/Basket.API/ +COPY src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj src/Services/Basket/Basket.FunctionalTests/ +COPY src/Services/Basket/Basket.UnitTests/Basket.UnitTests.csproj src/Services/Basket/Basket.UnitTests/ +COPY src/Services/Catalog/Catalog.API/Catalog.API.csproj src/Services/Catalog/Catalog.API/ +COPY src/Services/Catalog/Catalog.FunctionalTests/Catalog.FunctionalTests.csproj src/Services/Catalog/Catalog.FunctionalTests/ +COPY src/Services/Catalog/Catalog.UnitTests/Catalog.UnitTests.csproj src/Services/Catalog/Catalog.UnitTests/ +COPY src/Services/Identity/Identity.API/Identity.API.csproj src/Services/Identity/Identity.API/ +COPY src/Services/Location/Locations.API/Locations.API.csproj src/Services/Location/Locations.API/ +COPY src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj src/Services/Location/Locations.FunctionalTests/ +COPY src/Services/Marketing/Marketing.API/Marketing.API.csproj src/Services/Marketing/Marketing.API/ +COPY src/Services/Marketing/Marketing.FunctionalTests/Marketing.FunctionalTests.csproj src/Services/Marketing/Marketing.FunctionalTests/ +COPY src/Services/Ordering/Ordering.API/Ordering.API.csproj src/Services/Ordering/Ordering.API/ +COPY src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj src/Services/Ordering/Ordering.BackgroundTasks/ +COPY src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj src/Services/Ordering/Ordering.Domain/ +COPY src/Services/Ordering/Ordering.FunctionalTests/Ordering.FunctionalTests.csproj src/Services/Ordering/Ordering.FunctionalTests/ +COPY src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.csproj src/Services/Ordering/Ordering.Infrastructure/ +COPY src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj src/Services/Ordering/Ordering.SignalrHub/ +COPY src/Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj src/Services/Ordering/Ordering.UnitTests/ +COPY src/Services/Payment/Payment.API/Payment.API.csproj src/Services/Payment/Payment.API/ +COPY src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj src/Services/Webhooks/Webhooks.API/ +COPY src/Web/WebhookClient/WebhookClient.csproj src/Web/WebhookClient/ +COPY src/Web/WebMVC/WebMVC.csproj src/Web/WebMVC/ +COPY src/Web/WebSPA/WebSPA.csproj src/Web/WebSPA/ +COPY src/Web/WebStatus/WebStatus.csproj src/Web/WebStatus/ +COPY test/ServicesTests/Application.FunctionalTests/Application.FunctionalTests.csproj test/ServicesTests/Application.FunctionalTests/ +COPY test/ServicesTests/LoadTest/LoadTest.csproj test/ServicesTests/LoadTest/ + +RUN dotnet restore eShopOnContainers-ServicesAndWebApps.sln + +COPY . . +WORKDIR /src/src/Services/TenantCustomisations/TenantAShippingInformation +RUN dotnet publish --no-restore -c Release -o /app + +FROM build AS publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app . +ENTRYPOINT ["dotnet", "TenantAShippingInformation.dll"] diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs new file mode 100644 index 000000000..a7ad190fb --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs @@ -0,0 +1,9 @@ +using TenantAShippingInformation.Models; + +namespace TenantAShippingInformation.ExternalServices +{ + public interface IShippingService + { + ShippingInformation CalculateShippingInformation(int orderId); + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs new file mode 100644 index 000000000..6ae7e1f1d --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs @@ -0,0 +1,20 @@ +using System; +using TenantAShippingInformation.Models; + +namespace TenantAShippingInformation.ExternalServices +{ + public class MockedShippingService : IShippingService + { + public ShippingInformation CalculateShippingInformation(int orderId) + { + ShippingInformation shippingInformation = new ShippingInformation(); + shippingInformation.ShippingTime = DateTime.Today; + shippingInformation.ArrivalTime = DateTime.Today.AddDays(2); + shippingInformation.FragilityLevel = Fragility.Medium; + shippingInformation.PriorityLevel = Priority.High; + shippingInformation.OrderNumber = orderId.ToString(); + + return shippingInformation; + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs new file mode 100644 index 000000000..54fc370be --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs @@ -0,0 +1,28 @@ +using Autofac; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using System.Reflection; +using TenantAShippingInformation.IntegrationEvents.EventHandling; + +namespace TenantAShippingInformation.Infrastructure.AutofacModules +{ + + public class ApplicationModule + :Autofac.Module + { + + public string QueriesConnectionString { get; } + + public ApplicationModule(string qconstr) + { + QueriesConnectionString = qconstr; + + } + + protected override void Load(ContainerBuilder builder) + { + builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEventHandler).GetTypeInfo().Assembly) + .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); + + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs new file mode 100644 index 000000000..8f8fe2da2 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs @@ -0,0 +1,12 @@ +using Autofac; + +namespace TenantAShippingInformation.Infrastructure.AutofacModules +{ + public class MediatorModule : Autofac.Module + { + protected override void Load(ContainerBuilder builder) + { + //TODO + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs new file mode 100644 index 000000000..2c694dfbd --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Authorization; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TenantAShippingInformation.Infrastructure.Filters +{ + public class AuthorizeCheckOperationFilter : IOperationFilter + { + public void Apply(Operation operation, OperationFilterContext context) + { + // Check for authorize attribute + var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType().Any() || + context.MethodInfo.GetCustomAttributes(true).OfType().Any(); + + if (!hasAuthorize) return; + + operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" }); + operation.Responses.TryAdd("403", new Response { Description = "Forbidden" }); + + operation.Security = new List>> + { + new Dictionary> + { + { "oauth2", new [] { "orderingapi" } } + } + }; + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs new file mode 100644 index 000000000..d1b84d2fd --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs @@ -0,0 +1,69 @@ +namespace TenantAShippingInformation.Infrastructure.Filters +{ + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Filters; + using Microsoft.Extensions.Logging; + using System.Net; + + public class HttpGlobalExceptionFilter : IExceptionFilter + { + private readonly IHostingEnvironment env; + private readonly ILogger logger; + + public HttpGlobalExceptionFilter(IHostingEnvironment env, ILogger logger) + { + this.env = env; + this.logger = logger; + } + + public void OnException(ExceptionContext context) + { + logger.LogError(new EventId(context.Exception.HResult), + context.Exception, + context.Exception.Message); + + if (1==2)//TODO + { + var problemDetails = new ValidationProblemDetails() + { + Instance = context.HttpContext.Request.Path, + Status = StatusCodes.Status400BadRequest, + Detail = "Please refer to the errors property for additional details." + }; + + problemDetails.Errors.Add("DomainValidations", new string[] { context.Exception.Message.ToString() }); + + context.Result = new BadRequestObjectResult(problemDetails); + context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; + } + else + { + var json = new JsonErrorResponse + { + Messages = new[] { "An error occur.Try it again." } + }; + + if (env.IsDevelopment()) + { + json.DeveloperMessage = context.Exception; + } + + // Result asigned to a result object but in destiny the response is empty. This is a known bug of .net core 1.1 + // It will be fixed in .net core 1.1.2. See https://github.com/aspnet/Mvc/issues/5594 for more information + //TODO + //context.Result = new InternalServerErrorObjectResult(json); + context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; + } + context.ExceptionHandled = true; + } + + private class JsonErrorResponse + { + public string[] Messages { get; set; } + + public object DeveloperMessage { get; set; } + } + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs new file mode 100644 index 000000000..2409cdd84 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.SignalR; +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; +using Microsoft.Extensions.Logging; +using Serilog.Context; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using TenantBShippingInformation.IntegrationEvents.Events; + +namespace TenantBShippingInformation.IntegrationEvents.EventHandling +{ + public class OrderStatusChangedToSubmittedIntegrationEventHandler : + IIntegrationEventHandler + { + private readonly ILogger _logger; + + public OrderStatusChangedToSubmittedIntegrationEventHandler(ILogger logger) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event) + { + using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA")) + { + //TODO + Debug.WriteLine(@event); + + } + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs new file mode 100644 index 000000000..f9e521d3b --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs @@ -0,0 +1,18 @@ +using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; + +namespace TenantBShippingInformation.IntegrationEvents.Events +{ + public class OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public string OrderStatus { get; } + public string BuyerName { get; } + + public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName) + { + OrderId = orderId; + OrderStatus = orderStatus; + BuyerName = buyerName; + } + } +} \ No newline at end of file diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs new file mode 100644 index 000000000..17c04e0c0 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs @@ -0,0 +1,7 @@ +namespace TenantAShippingInformation.Models +{ + public enum Fragility + { + Low, Medium, High + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs new file mode 100644 index 000000000..b5c245641 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs @@ -0,0 +1,7 @@ +namespace TenantAShippingInformation.Models +{ + public enum Priority + { + Low, Medium, High + } +} diff --git a/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs new file mode 100644 index 000000000..8361e1786 --- /dev/null +++ b/src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs @@ -0,0 +1,14 @@ +using System; + +namespace TenantAShippingInformation.Models +{ + public class ShippingInformation + { + public int ShippingInformationId { get; set; } + public DateTime ArrivalTime { get; set; } + public DateTime ShippingTime { get; set; } + public Priority PriorityLevel {get;set;} + public Fragility FragilityLevel { get; set; } + public String OrderNumber { get; set; } + } +}