Browse Source

updates on top of gababus changes for basket signalR

pull/1207/head
Vijay Bikka 5 years ago
parent
commit
fe5863b52b
9 changed files with 94 additions and 5 deletions
  1. +3
    -0
      src/Services/Basket/Basket.SignalrHub/AutofacModules/ApplicationModule.cs
  2. +0
    -2
      src/Services/Basket/Basket.SignalrHub/Basket.SignalrHub.csproj
  3. +40
    -0
      src/Services/Basket/Basket.SignalrHub/IntegrationEvents/EventHandling/UserAddedCartItemToBasketIntegrationEventHandler.cs
  4. +27
    -0
      src/Services/Basket/Basket.SignalrHub/IntegrationEvents/Events/BasketItem.cs
  5. +17
    -0
      src/Services/Basket/Basket.SignalrHub/IntegrationEvents/Events/UserAddedCartItemToBasketIntegrationEvent.cs
  6. +3
    -0
      src/Services/Basket/Basket.SignalrHub/Startup.cs
  7. +1
    -1
      src/Services/Ordering/Ordering.SignalrHub/Startup.cs
  8. +2
    -1
      src/Web/WebMVC/Startup.cs
  9. +1
    -1
      src/Web/WebSPA/Client/modules/shared/services/security.service.ts

+ 3
- 0
src/Services/Basket/Basket.SignalrHub/AutofacModules/ApplicationModule.cs View File

@ -1,4 +1,5 @@
using Autofac;
using Basket.SignalrHub.IntegrationEvents;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using System;
using System.Collections.Generic;
@ -24,6 +25,8 @@ namespace Basket.SignalrHub.AutofacModules
// builder.RegisterAssemblyTypes(typeof(NewIntegrationEvent).GetTypeInfo().Assembly)
// .AsClosedTypesOf(typeof(IIntegrationEventHandler<>));
builder.RegisterAssemblyTypes(typeof(UserAddedCartItemToBasketIntegrationEvent).GetTypeInfo().Assembly)
.AsClosedTypesOf(typeof(IIntegrationEventHandler<>));
}
}
}

+ 0
- 2
src/Services/Basket/Basket.SignalrHub/Basket.SignalrHub.csproj View File

@ -6,8 +6,6 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="IntegrationEvents\EventHandling\" />
<Folder Include="IntegrationEvents\Events\" />
<Folder Include="wwwroot\" />
</ItemGroup>


+ 40
- 0
src/Services/Basket/Basket.SignalrHub/IntegrationEvents/EventHandling/UserAddedCartItemToBasketIntegrationEventHandler.cs View File

@ -0,0 +1,40 @@
using Microsoft.AspNetCore.SignalR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using Basket.SignalrHub.IntegrationEvents;
using Serilog.Context;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Basket.SignalrHub.IntegrationEvents.EventHandling
{
public class UserAddedCartItemToBasketIntegrationEventHandler :
IIntegrationEventHandler<UserAddedCartItemToBasketIntegrationEvent>
{
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly ILogger<UserAddedCartItemToBasketIntegrationEventHandler> _logger;
public UserAddedCartItemToBasketIntegrationEventHandler(
IHubContext<NotificationsHub> hubContext,
ILogger<UserAddedCartItemToBasketIntegrationEventHandler> logger)
{
_hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public async Task Handle(UserAddedCartItemToBasketIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
await _hubContext.Clients
.Group(@event.BuyerName)
.SendAsync("UpdateBasketCount", "test message");
}
}
}
}

+ 27
- 0
src/Services/Basket/Basket.SignalrHub/IntegrationEvents/Events/BasketItem.cs View File

@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Basket.SignalrHub.IntegrationEvents
{
public class BasketItem : IValidatableObject
{
public string Id { get; set; }
public string ProductId { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public decimal OldUnitPrice { get; set; }
public int Quantity { get; set; }
public string PictureUrl { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var results = new List<ValidationResult>();
if (Quantity < 1)
{
results.Add(new ValidationResult("Invalid number of units", new []{ "Quantity" }));
}
return results;
}
}
}

+ 17
- 0
src/Services/Basket/Basket.SignalrHub/IntegrationEvents/Events/UserAddedCartItemToBasketIntegrationEvent.cs View File

@ -0,0 +1,17 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
namespace Basket.SignalrHub.IntegrationEvents
{
public class UserAddedCartItemToBasketIntegrationEvent : IntegrationEvent
{
public string BuyerName { get; set; }
public BasketItem Item { get; set; }
public UserAddedCartItemToBasketIntegrationEvent(string buyerName, BasketItem basketItem)
{
BuyerName = buyerName;
Item = basketItem;
}
}
}

+ 3
- 0
src/Services/Basket/Basket.SignalrHub/Startup.cs View File

@ -17,6 +17,8 @@ using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Basket.SignalrHub.AutofacModules;
using Basket.SignalrHub.IntegrationEvents;
using Basket.SignalrHub.IntegrationEvents.EventHandling;
namespace Basket.SignalrHub
{
@ -160,6 +162,7 @@ namespace Basket.SignalrHub
// Event bus subscribe events goes here
// eventBus.Subscribe<NewIntegrationEvent, NewIntegrationEventHandler>();
eventBus.Subscribe<UserAddedCartItemToBasketIntegrationEvent, UserAddedCartItemToBasketIntegrationEventHandler>();
}
private void ConfigureAuthService(IServiceCollection services)


+ 1
- 1
src/Services/Ordering/Ordering.SignalrHub/Startup.cs View File

@ -167,7 +167,7 @@ namespace Ordering.SignalrHub
eventBus.Subscribe<OrderStatusChangedToShippedIntegrationEvent, OrderStatusChangedToShippedIntegrationEventHandler>();
eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>();
eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>();
eventBus.Subscribe<UserAddedCartItemToBasketIntegrationEvent, UserAddedCartItemToBasketIntegrationEventHandler>();
//eventBus.Subscribe<UserAddedCartItemToBasketIntegrationEvent, UserAddedCartItemToBasketIntegrationEventHandler>();
}
private void ConfigureAuthService(IServiceCollection services)


+ 2
- 1
src/Web/WebMVC/Startup.cs View File

@ -266,7 +266,8 @@ namespace Microsoft.eShopOnContainers.WebMVC
options.Scope.Add("marketing");
options.Scope.Add("locations");
options.Scope.Add("webshoppingagg");
options.Scope.Add("orders.signalrhub");
options.Scope.Add("orders.signalrhub");
options.Scope.Add("basket.signalrhub");
});
return services;


+ 1
- 1
src/Web/WebSPA/Client/modules/shared/services/security.service.ts View File

@ -81,7 +81,7 @@ export class SecurityService {
let client_id = 'js';
let redirect_uri = location.origin + '/';
let response_type = 'id_token token';
let scope = 'openid profile orders basket marketing locations webshoppingagg orders.signalrhub';
let scope = 'openid profile orders basket marketing locations webshoppingagg orders.signalrhub basket.signalrhub';
let nonce = 'N' + Math.random() + '' + Date.now();
let state = Date.now() + '' + Math.random();


Loading…
Cancel
Save