Merge branch 'refs/heads/Feature/program-manager/signalR-notification'
# Conflicts: # ServiceHost/Program.cs
This commit is contained in:
@@ -199,7 +199,7 @@ public class AuthHelper : IAuthHelper
|
||||
new("WorkshopSlug",slug),
|
||||
new("WorkshopId", account.WorkshopId.ToString()),
|
||||
new("WorkshopName",account.WorkshopName??""),
|
||||
new("pm.userId", account.PmUserId?.ToString() ?? "0"),
|
||||
new("pm.userId", account.PmUserId.ToString()),
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Interfaces;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Events;
|
||||
using MediatR;
|
||||
|
||||
namespace GozareshgirProgramManager.Application.DomainEventHandlers.ProjectSection;
|
||||
|
||||
public class TaskSectionStatusChangedHandler:INotificationHandler<DomainEventNotification<TaskSectionStatusChangedEvent>>
|
||||
{
|
||||
private readonly IBoardNotificationPublisher _boardNotificationPublisher;
|
||||
|
||||
public TaskSectionStatusChangedHandler(IBoardNotificationPublisher boardNotificationPublisher)
|
||||
{
|
||||
_boardNotificationPublisher = boardNotificationPublisher;
|
||||
}
|
||||
|
||||
public Task Handle(DomainEventNotification<TaskSectionStatusChangedEvent> notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var domainEvent = notification.DomainEvent;
|
||||
_boardNotificationPublisher.SendProjectStatusChanged(domainEvent.UserId,domainEvent.OldStatus,domainEvent.NewStatus,domainEvent.SectionId);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
|
||||
namespace GozareshgirProgramManager.Application.Interfaces;
|
||||
|
||||
public interface IBoardNotificationPublisher
|
||||
{
|
||||
Task SendProjectStatusChanged(long userId, TaskSectionStatus oldStatus,
|
||||
TaskSectionStatus newStatus, Guid sectionId);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace GozareshgirProgramManager.Application.Interfaces;
|
||||
|
||||
public interface IBoardNotificationService
|
||||
{
|
||||
Task SendProjectAssignedAsync();
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class TaskSection : EntityBase<Guid>
|
||||
{
|
||||
var oldStatus = Status;
|
||||
Status = status;
|
||||
AddDomainEvent(new TaskSectionStatusChangedEvent(Id, oldStatus, status));
|
||||
AddDomainEvent(new TaskSectionStatusChangedEvent(Id, oldStatus, status,CurrentAssignedUserId));
|
||||
}
|
||||
|
||||
public TimeSpan GetTotalTimeSpent()
|
||||
|
||||
@@ -104,7 +104,8 @@ public record TaskSectionRemovedEvent(Guid TaskId, Guid SectionId) : IDomainEven
|
||||
}
|
||||
|
||||
// TaskSection Events
|
||||
public record TaskSectionStatusChangedEvent(Guid SectionId, TaskSectionStatus OldStatus, TaskSectionStatus NewStatus) : IDomainEvent
|
||||
public record TaskSectionStatusChangedEvent(Guid SectionId, TaskSectionStatus OldStatus,
|
||||
TaskSectionStatus NewStatus,long UserId) : IDomainEvent
|
||||
{
|
||||
public DateTime OccurredOn { get; init; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
21
ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs
Normal file
21
ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace ServiceHost.Hubs.ProgramManager;
|
||||
|
||||
public class ProjectBoardHub:Hub
|
||||
{
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
var user = Context.User?.FindFirst("pm.userId")?.Value;
|
||||
|
||||
if (user != null && user !="0")
|
||||
{
|
||||
await Groups.AddToGroupAsync(
|
||||
Context.ConnectionId,
|
||||
$"pm.user-{user}"
|
||||
);
|
||||
}
|
||||
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using GozareshgirProgramManager.Application.Interfaces;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using ServiceHost.Hubs.ProgramManager;
|
||||
|
||||
namespace ServiceHost.Notifications.ProgramManager;
|
||||
|
||||
public class SignalRBoardNotificationPublisher:IBoardNotificationPublisher
|
||||
{
|
||||
private readonly IHubContext<ProjectBoardHub> _hubContext;
|
||||
|
||||
public SignalRBoardNotificationPublisher(IHubContext<ProjectBoardHub> hubContext)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
public Task SendProjectStatusChanged(long userId, TaskSectionStatus oldStatus,
|
||||
TaskSectionStatus newStatus, Guid sectionId)
|
||||
{
|
||||
var payload = new
|
||||
{
|
||||
UserId = userId,
|
||||
OldStatus = oldStatus,
|
||||
NewStatus = newStatus,
|
||||
SectionId = sectionId
|
||||
};
|
||||
_hubContext.Clients.Group($"pm.user-{userId}").SendAsync("ReceiveProjectStatusChanged",payload);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,13 @@ using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using AccountManagement.Domain.InternalApiCaller;
|
||||
using FluentValidation;
|
||||
using GozareshgirProgramManager.Application._Bootstrapper;
|
||||
using GozareshgirProgramManager.Application.Interfaces;
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Commands.CreateUser;
|
||||
using GozareshgirProgramManager.Infrastructure;
|
||||
using GozareshgirProgramManager.Infrastructure.Persistence.Seed;
|
||||
using Microsoft.OpenApi;
|
||||
using ServiceHost.Hubs.ProgramManager;
|
||||
using ServiceHost.Notifications.ProgramManager;
|
||||
using ServiceHost.Conventions;
|
||||
|
||||
|
||||
@@ -55,6 +58,7 @@ builder.Services.AddProgramManagerApplication();
|
||||
builder.Services.AddProgramManagerInfrastructure(builder.Configuration);
|
||||
builder.Services.AddValidatorsFromAssemblyContaining<CreateUserCommandValidators>();
|
||||
builder.Services.AddScoped<IDataSeeder, DataSeeder>();
|
||||
builder.Services.AddScoped<IBoardNotificationPublisher, SignalRBoardNotificationPublisher>();
|
||||
#region MongoDb
|
||||
|
||||
var mongoConnectionSection = builder.Configuration.GetSection("MongoDb");
|
||||
@@ -456,6 +460,7 @@ app.MapHub<HolidayApiHub>("/trackingHolidayHub");
|
||||
app.MapHub<CheckoutHub>("/trackingCheckoutHub");
|
||||
// app.MapHub<FaceEmbeddingHub>("/trackingFaceEmbeddingHub");
|
||||
app.MapHub<SendSmsHub>("/trackingSendSmsHub");
|
||||
app.MapHub<ProjectBoardHub>("api/pm/board");
|
||||
app.MapRazorPages();
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user