SingalR for realtime entitychanges
All checks were successful
Build Docker Images / test (map[name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 1m36s
Build Docker Images / test (map[name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m31s
Build Docker Images / build-and-push (map[image_suffix:morska name:Morska plugin_project:DiunaBI.Plugins.Morska]) (push) Successful in 1m55s
Build Docker Images / build-and-push (map[image_suffix:pedrollopl name:PedrolloPL plugin_project:DiunaBI.Plugins.PedrolloPL]) (push) Successful in 1m53s

This commit is contained in:
2025-12-04 22:20:00 +01:00
parent bf2beda390
commit 193127b86a
11 changed files with 509 additions and 6 deletions

View File

@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.SignalR;
namespace DiunaBI.API.Hubs;
public class EntityChangeHub : Hub
{
public async Task SendEntityChange(string module, string id, string operation)
{
await Clients.All.SendAsync("EntityChanged", new
{
module,
id,
operation
});
}
}

View File

@@ -4,8 +4,10 @@ using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection;
using System.Text;
using DiunaBI.API.Hubs;
using DiunaBI.API.Services;
using DiunaBI.Infrastructure.Data;
using DiunaBI.Infrastructure.Interceptors;
using DiunaBI.Infrastructure.Services;
using Google.Apis.Sheets.v4;
using Serilog;
@@ -29,10 +31,17 @@ if (builder.Environment.IsProduction())
var connectionString = builder.Configuration.GetConnectionString("SQLDatabase");
builder.Services.AddDbContext<AppDbContext>(x =>
// Register EntityChangeInterceptor
builder.Services.AddSingleton<EntityChangeInterceptor>();
builder.Services.AddDbContext<AppDbContext>((serviceProvider, options) =>
{
x.UseSqlServer(connectionString, sqlOptions => sqlOptions.MigrationsAssembly("DiunaBI.Infrastructure"));
x.EnableSensitiveDataLogging();
options.UseSqlServer(connectionString, sqlOptions => sqlOptions.MigrationsAssembly("DiunaBI.Infrastructure"));
options.EnableSensitiveDataLogging();
// Add EntityChangeInterceptor
var interceptor = serviceProvider.GetRequiredService<EntityChangeInterceptor>();
options.AddInterceptors(interceptor);
});
builder.Services.AddCors(options =>
@@ -58,6 +67,9 @@ builder.Services.AddCors(options =>
builder.Services.AddControllers();
// SignalR
builder.Services.AddSignalR();
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@@ -244,6 +256,9 @@ app.Use(async (context, next) =>
app.MapControllers();
// SignalR Hub
app.MapHub<EntityChangeHub>("/hubs/entitychanges");
app.MapGet("/health", () => Results.Ok(new { status = "OK", timestamp = DateTime.UtcNow }))
.AllowAnonymous();