diff --git a/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/CompanyHub.cs b/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/CompanyHub.cs new file mode 100644 index 0000000..53a7464 --- /dev/null +++ b/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/CompanyHub.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.SignalR; + +namespace MadWorld.ShipSimulator.API.Hubs; + +public class CompanyHub : Hub +{ + +} \ No newline at end of file diff --git a/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/CompanyLiveUpdater.cs b/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/CompanyLiveUpdater.cs new file mode 100644 index 0000000..7e74cc5 --- /dev/null +++ b/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/CompanyLiveUpdater.cs @@ -0,0 +1,19 @@ +using MadWorld.ShipSimulator.Domain.Companies; +using Microsoft.AspNetCore.SignalR; + +namespace MadWorld.ShipSimulator.API.Hubs; + +public class CompanyLiveUpdater : ICompanyLiveUpdater +{ + private readonly IHubContext _hubContext; + + public CompanyLiveUpdater(IHubContext hubContext) + { + _hubContext = hubContext; + } + + public async Task UpdateCompanyAsync(Company company) + { + await _hubContext.Clients.User(company.UserId.ToString()).SendAsync("CompanyUpdated", company); + } +} \ No newline at end of file diff --git a/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/HubExtensions.cs b/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/HubExtensions.cs new file mode 100644 index 0000000..779d2af --- /dev/null +++ b/MadWorldVPS/MadWorld.ShipSimulator.API/Hubs/HubExtensions.cs @@ -0,0 +1,12 @@ +using MadWorld.ShipSimulator.Domain.Companies; + +namespace MadWorld.ShipSimulator.API.Hubs; + +public static class HubExtensions +{ + public static void AddHubs(this WebApplicationBuilder builder) + { + builder.Services.AddSignalR(); + builder.Services.AddScoped(); + } +} \ No newline at end of file diff --git a/MadWorldVPS/MadWorld.ShipSimulator.API/Program.cs b/MadWorldVPS/MadWorld.ShipSimulator.API/Program.cs index a6b7dbb..3be48a9 100644 --- a/MadWorldVPS/MadWorld.ShipSimulator.API/Program.cs +++ b/MadWorldVPS/MadWorld.ShipSimulator.API/Program.cs @@ -5,6 +5,7 @@ using MadWorld.Shared.Infrastructure.Databases; using MadWorld.Shared.Infrastructure.Settings; using MadWorld.ShipSimulator.API.Endpoints; +using MadWorld.ShipSimulator.API.Hubs; using MadWorld.ShipSimulator.Application.CommonLogic.Extensions; using MadWorld.ShipSimulator.Infrastructure.Database; using MadWorld.ShipSimulator.Infrastructure.Database.Extensions; @@ -55,6 +56,7 @@ private static void Main(string[] args) builder.AddApplication(); builder.AddDatabase(); + builder.AddHubs(); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { @@ -81,7 +83,7 @@ private static void Main(string[] args) }); builder.Services.AddAuthorization(); - + builder.Services.AddHealthChecks(); builder.Services.Configure(options => @@ -144,6 +146,7 @@ private static void Main(string[] args) apiBuilder.AddCompanyEndpoints(); apiBuilder.AddDangerEndpoints(); + apiBuilder.MapHub("/CompanyHub"); app.MigrateDatabase(); diff --git a/MadWorldVPS/MadWorld.ShipSimulator.Domain/Companies/ICompanyLiveUpdater.cs b/MadWorldVPS/MadWorld.ShipSimulator.Domain/Companies/ICompanyLiveUpdater.cs new file mode 100644 index 0000000..31f48ec --- /dev/null +++ b/MadWorldVPS/MadWorld.ShipSimulator.Domain/Companies/ICompanyLiveUpdater.cs @@ -0,0 +1,6 @@ +namespace MadWorld.ShipSimulator.Domain.Companies; + +public interface ICompanyLiveUpdater +{ + Task UpdateCompanyAsync(Company company); +} \ No newline at end of file