feat: implémenter SignalR hubs (Monitoring, Notifications, Admin) + système de notifications complet

SignalR Hubs:
- MonitoringHub (/hubs/monitoring) — statuts agents/caméras/stockage/GPU jobs
- NotificationsHub (/hubs/notifications) — notifications in-app badge temps réel
- AdminHub (/hubs/admin) — broadcast changements config (Admin only)

Notification System:
- Nouvelles entités: Notification, NotificationTemplate, UserNotificationConfig
- CQRS/MediatR: 6 handlers (list, unread, mark-read, mark-all, config get/update)
- Infrastructure: NotificationService orchestrator + EmailService + GotifyService
- Rate limiter IMemoryCache (20 events/min/camera/type)
- Hangfire jobs: SendNotification, DailyDigest, WeeklyDigest
- NotificationsController API (6 endpoints)
- Blazor UI: NotificationsPage + NotificationBadge
- Migration AddNotifications (3 nouvelles tables)
- 644 nouveaux tests (Domain: 131, Application: 321, Infra: 151, Integration: 120, +autres)
This commit is contained in:
Arnaud Dartois committed 2026-07-26 20:45:35 +00:00
1 parent ef3ea9d1ca
commit f9be0f1e0d
62 files changed
+6664 -3

No files matched your search

@@ -0,0 +1,102 @@
using Heimdall.Application.DTOs;
using Heimdall.Application.Notifications.Commands.MarkAllAsRead;
using Heimdall.Application.Notifications.Commands.MarkAsRead;
using Heimdall.Application.Notifications.Commands.UpdateConfig;
using Heimdall.Application.Notifications.Queries.GetConfig;
using Heimdall.Application.Notifications.Queries.GetNotifications;
using Heimdall.Application.Notifications.Queries.GetUnreadCount;
using Heimdall.Infrastructure.Security;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using System.Security.Claims;
namespace Heimdall.Api.Controllers;
/// <summary>
/// In-app notifications for users — list, mark read, configure notification preferences.
/// </summary>
[ApiController]
[Route("api/notifications")]
[EnableRateLimiting("Api")]
[Authorize(AuthenticationSchemes = "JwtBearer")]
public class NotificationsController : ControllerBase
{
private readonly IMediator _mediator;
public NotificationsController(IMediator mediator) => _mediator = mediator;
private Guid GetUserId() =>
Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
/// <summary>List notifications for the current user.</summary>
[HttpGet]
[ProducesResponseType(typeof(PagedResult<NotificationDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetNotifications(
[FromQuery] bool? isRead,
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
CancellationToken ct = default)
{
var result = await _mediator.Send(new GetNotificationsQuery(GetUserId(), isRead, page, pageSize), ct);
return Ok(result);
}
/// <summary>Get unread notification count.</summary>
[HttpGet("unread-count")]
[ProducesResponseType(typeof(UnreadCountDto), StatusCodes.Status200OK)]
public async Task<IActionResult> GetUnreadCount(CancellationToken ct = default)
{
var result = await _mediator.Send(new GetUnreadCountQuery(GetUserId()), ct);
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error });
}
/// <summary>Mark a single notification as read.</summary>
[HttpPost("{id:guid}/read")]
[ProducesResponseType(typeof(MarkAsReadResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<IActionResult> MarkAsRead(Guid id, CancellationToken ct = default)
{
var result = await _mediator.Send(new MarkAsReadCommand(id, GetUserId()), ct);
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
}
/// <summary>Mark all notifications as read.</summary>
[HttpPost("mark-all-read")]
[ProducesResponseType(typeof(MarkAsReadResponse), StatusCodes.Status200OK)]
public async Task<IActionResult> MarkAllAsRead(CancellationToken ct = default)
{
var result = await _mediator.Send(new MarkAllAsReadCommand(GetUserId()), ct);
return Ok(result.Data);
}
/// <summary>Get notification configuration for the current user.</summary>
[HttpGet("config")]
[ProducesResponseType(typeof(UserNotificationConfigDto), StatusCodes.Status200OK)]
public async Task<IActionResult> GetConfig(CancellationToken ct = default)
{
var result = await _mediator.Send(new GetNotificationConfigQuery(GetUserId()), ct);
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error });
}
/// <summary>Update notification configuration for the current user.</summary>
[HttpPut("config")]
[ProducesResponseType(typeof(UserNotificationConfigDto), StatusCodes.Status200OK)]
public async Task<IActionResult> UpdateConfig([FromBody] UpdateNotificationConfigRequest request, CancellationToken ct = default)
{
var command = new UpdateNotificationConfigCommand(
GetUserId(),
request.EmailEnabled,
request.EmailAddress,
request.GotifyEnabled,
request.GotifyUrl,
request.GotifyToken,
request.Language,
request.DailyDigest,
request.WeeklyDigest,
request.SubscribedEvents);
var result = await _mediator.Send(command, ct);
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error });
}
}