From da46d45601d29c2f878eec83461fc3fe5cccf651 Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 14 Dec 2025 12:13:23 +0330 Subject: [PATCH 1/4] feat: implement SignalR notifications for project status changes --- .../TaskSectionStatusChangedHandler.cs | 23 ++++++++++++++ .../Interfaces/IBoardNotificationPublisher.cs | 9 ++++++ .../Interfaces/IBoardNotificationService.cs | 6 ---- .../ProjectAgg/Entities/TaskSection.cs | 2 +- .../ProjectAgg/Events/ProjectEvents.cs | 3 +- .../Hubs/ProgramManager/ProjectBoardHub.cs | 13 ++++++++ .../SignalRBoardNotificationPublisher.cs | 30 +++++++++++++++++++ ServiceHost/Program.cs | 2 ++ 8 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 ProgramManager/src/Application/GozareshgirProgramManager.Application/DomainEventHandlers/ProjectSection/TaskSectionStatusChangedHandler.cs create mode 100644 ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationPublisher.cs delete mode 100644 ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationService.cs create mode 100644 ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs create mode 100644 ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/DomainEventHandlers/ProjectSection/TaskSectionStatusChangedHandler.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/DomainEventHandlers/ProjectSection/TaskSectionStatusChangedHandler.cs new file mode 100644 index 00000000..cca24761 --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/DomainEventHandlers/ProjectSection/TaskSectionStatusChangedHandler.cs @@ -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> +{ + private readonly IBoardNotificationPublisher _boardNotificationPublisher; + + public TaskSectionStatusChangedHandler(IBoardNotificationPublisher boardNotificationPublisher) + { + _boardNotificationPublisher = boardNotificationPublisher; + } + + public Task Handle(DomainEventNotification notification, CancellationToken cancellationToken) + { + var domainEvent = notification.DomainEvent; + _boardNotificationPublisher.SendProjectStatusChanged(domainEvent.UserId,domainEvent.OldStatus,domainEvent.NewStatus,domainEvent.SectionId); + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationPublisher.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationPublisher.cs new file mode 100644 index 00000000..1f4d5f1b --- /dev/null +++ b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationPublisher.cs @@ -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); +} \ No newline at end of file diff --git a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationService.cs b/ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationService.cs deleted file mode 100644 index 959e7fbf..00000000 --- a/ProgramManager/src/Application/GozareshgirProgramManager.Application/Interfaces/IBoardNotificationService.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace GozareshgirProgramManager.Application.Interfaces; - -public interface IBoardNotificationService -{ - Task SendProjectAssignedAsync(); -} \ No newline at end of file diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs index e478478d..b2a6fd91 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Entities/TaskSection.cs @@ -159,7 +159,7 @@ public class TaskSection : EntityBase { var oldStatus = Status; Status = status; - AddDomainEvent(new TaskSectionStatusChangedEvent(Id, oldStatus, status)); + AddDomainEvent(new TaskSectionStatusChangedEvent(Id, oldStatus, status,CurrentAssignedUserId)); } public TimeSpan GetTotalTimeSpent() diff --git a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Events/ProjectEvents.cs b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Events/ProjectEvents.cs index e823967e..fb6ca424 100644 --- a/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Events/ProjectEvents.cs +++ b/ProgramManager/src/Domain/GozareshgirProgramManager.Domain/ProjectAgg/Events/ProjectEvents.cs @@ -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; } diff --git a/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs b/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs new file mode 100644 index 00000000..7acec847 --- /dev/null +++ b/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.SignalR; + +namespace ServiceHost.Hubs.ProgramManager; + +public class ProjectBoardHub:Hub +{ + public override async Task OnConnectedAsync() + { + Console.WriteLine($"{Context.ConnectionId} connected"); + await Clients.All.SendAsync("ReceiveGreeting","A new user has connected to the Project Board Hub!"); + await base.OnConnectedAsync(); + } +} \ No newline at end of file diff --git a/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs b/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs new file mode 100644 index 00000000..5b280f1d --- /dev/null +++ b/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs @@ -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 _hubContext; + + public SignalRBoardNotificationPublisher(IHubContext 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.User(userId.ToString()).SendAsync("ReceiveProjectStatusChanged",payload); + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 40ca19b2..4c4b58d8 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -31,6 +31,7 @@ using GozareshgirProgramManager.Application.Modules.Users.Commands.CreateUser; using GozareshgirProgramManager.Infrastructure; using GozareshgirProgramManager.Infrastructure.Persistence.Seed; using Microsoft.OpenApi; +using ServiceHost.Hubs.ProgramManager; var builder = WebApplication.CreateBuilder(args); @@ -451,6 +452,7 @@ app.MapHub("/trackingHolidayHub"); app.MapHub("/trackingCheckoutHub"); // app.MapHub("/trackingFaceEmbeddingHub"); app.MapHub("/trackingSendSmsHub"); +app.MapHub("/pm/board"); app.MapRazorPages(); app.MapControllers(); From 83a7bbf5f39c527d32279014ad4335bb6fa297a0 Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 14 Dec 2025 13:50:24 +0330 Subject: [PATCH 2/4] feat: register SignalR notification publisher for board updates --- ServiceHost/Program.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 4c4b58d8..70db4c48 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -27,11 +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; var builder = WebApplication.CreateBuilder(args); @@ -55,6 +57,7 @@ builder.Services.AddProgramManagerApplication(); builder.Services.AddProgramManagerInfrastructure(builder.Configuration); builder.Services.AddValidatorsFromAssemblyContaining(); builder.Services.AddScoped(); +builder.Services.AddScoped(); #region MongoDb var mongoConnectionSection = builder.Configuration.GetSection("MongoDb"); From bca1e66f0f94eee591c0de2e7df959bc654b5e1c Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 14 Dec 2025 14:21:45 +0330 Subject: [PATCH 3/4] feat: update ProjectBoardHub endpoint to include API prefix --- ServiceHost/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index 70db4c48..9c583c1c 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -455,7 +455,7 @@ app.MapHub("/trackingHolidayHub"); app.MapHub("/trackingCheckoutHub"); // app.MapHub("/trackingFaceEmbeddingHub"); app.MapHub("/trackingSendSmsHub"); -app.MapHub("/pm/board"); +app.MapHub("api/pm/board"); app.MapRazorPages(); app.MapControllers(); From a7d3b1e96f0455b5dc5ffd761c5d1758ed958459 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 15 Dec 2025 10:14:32 +0330 Subject: [PATCH 4/4] feat: update SignalR group handling for project status notifications --- 0_Framework/Application/AuthHelper.cs | 2 +- ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs | 12 ++++++++++-- .../SignalRBoardNotificationPublisher.cs | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/0_Framework/Application/AuthHelper.cs b/0_Framework/Application/AuthHelper.cs index 12f820f8..41e6efa2 100644 --- a/0_Framework/Application/AuthHelper.cs +++ b/0_Framework/Application/AuthHelper.cs @@ -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()), }; diff --git a/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs b/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs index 7acec847..5c262095 100644 --- a/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs +++ b/ServiceHost/Hubs/ProgramManager/ProjectBoardHub.cs @@ -6,8 +6,16 @@ public class ProjectBoardHub:Hub { public override async Task OnConnectedAsync() { - Console.WriteLine($"{Context.ConnectionId} connected"); - await Clients.All.SendAsync("ReceiveGreeting","A new user has connected to the Project Board Hub!"); + var user = Context.User?.FindFirst("pm.userId")?.Value; + + if (user != null && user !="0") + { + await Groups.AddToGroupAsync( + Context.ConnectionId, + $"pm.user-{user}" + ); + } + await base.OnConnectedAsync(); } } \ No newline at end of file diff --git a/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs b/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs index 5b280f1d..130d8f09 100644 --- a/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs +++ b/ServiceHost/Notifications/ProgramManager/SignalRBoardNotificationPublisher.cs @@ -24,7 +24,7 @@ public class SignalRBoardNotificationPublisher:IBoardNotificationPublisher NewStatus = newStatus, SectionId = sectionId }; - _hubContext.Clients.User(userId.ToString()).SendAsync("ReceiveProjectStatusChanged",payload); + _hubContext.Clients.Group($"pm.user-{userId}").SendAsync("ReceiveProjectStatusChanged",payload); return Task.CompletedTask; } } \ No newline at end of file