feat(cqrs): update controllers, add AutoMapper profiles, SignalR notifications, Hangfire config

- 13 controllers migrated from service DI to IMediator dispatch
- 11 AutoMapper mapping profiles (Sites, Cameras, Auth, Users, Agents, Events, Assignments, Settings, Groups, Persons, Discovery)
- SignalR notifications bridged via MediatR INotificationHandler
- Hangfire config moved from Program.cs to Infrastructure/BackgroundJobs
- 0 build errors, 0 warnings
This commit is contained in:
Arnaud Dartois committed 2026-07-22 19:54:55 +00:00
1 parent c1b3b3d3b4
commit 1d1ac8387e
33 files changed
+611 -195

No files matched your search

@@ -1,8 +1,18 @@
using Heimdall.Application.Common;
using Heimdall.Application.DTOs;
using Heimdall.Application.Services;
using Heimdall.Application.Settings.Commands.CreateAppSetting;
using Heimdall.Application.Settings.Commands.UpdateAppSetting;
using Heimdall.Application.Settings.Commands.DeleteAppSetting;
using Heimdall.Application.Settings.Commands.SetAgentSetting;
using Heimdall.Application.Settings.Commands.RemoveAgentSetting;
using Heimdall.Application.Settings.Queries.GetSettings;
using Heimdall.Application.Settings.Queries.GetSettingByKey;
using Heimdall.Application.Settings.Queries.GetEffectiveAgentConfig;
using Heimdall.Application.Settings.Queries.GetAgentSettings;
using Heimdall.Api.Hubs;
using Heimdall.Infrastructure.Security;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
@@ -15,16 +25,16 @@ namespace Heimdall.Api.Controllers;
[EnableRateLimiting("Api")]
public class SettingsController : ControllerBase
{
private readonly ISettingService _settingService;
private readonly IMediator _mediator;
private readonly IConfigBroadcastService _broadcast;
private readonly ILogger<SettingsController> _logger;
public SettingsController(
ISettingService settingService,
IMediator mediator,
IConfigBroadcastService broadcast,
ILogger<SettingsController> logger)
{
_settingService = settingService;
_mediator = mediator;
_broadcast = broadcast;
_logger = logger;
}
@@ -36,7 +46,7 @@ public class SettingsController : ControllerBase
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> ListAll(CancellationToken ct)
{
var result = await _settingService.GetAllSettingsAsync(ct);
var result = await _mediator.Send(new GetSettingsQuery(), ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
@@ -56,7 +66,7 @@ public class SettingsController : ControllerBase
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetByKey(string key, CancellationToken ct)
{
var result = await _settingService.GetSettingByKeyAsync(key, ct);
var result = await _mediator.Send(new GetSettingByKeyQuery(key), ct);
if (!result.IsSuccess)
return NotFound(new { error = result.Error });
@@ -78,7 +88,8 @@ public class SettingsController : ControllerBase
public async Task<IActionResult> Create(
[FromBody] CreateAppSettingRequest request, CancellationToken ct)
{
var result = await _settingService.CreateSettingAsync(request, ct);
var command = new CreateAppSettingCommand(request.Key, request.Value, request.Category, request.Description, request.ValueType, request.AllowedValues);
var result = await _mediator.Send(command, ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
@@ -96,7 +107,8 @@ public class SettingsController : ControllerBase
public async Task<IActionResult> Update(
string key, [FromBody] UpdateAppSettingRequest request, CancellationToken ct)
{
var result = await _settingService.UpdateSettingAsync(key, request, ct);
var command = new UpdateAppSettingCommand(key, request.Value, request.Description, request.Category, request.ValueType, request.AllowedValues);
var result = await _mediator.Send(command, ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
@@ -113,7 +125,7 @@ public class SettingsController : ControllerBase
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<IActionResult> Delete(string key, CancellationToken ct)
{
var result = await _settingService.DeleteSettingAsync(key, ct);
var result = await _mediator.Send(new DeleteAppSettingCommand(key), ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
@@ -132,7 +144,7 @@ public class SettingsController : ControllerBase
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetEffectiveConfig(Guid agentId, CancellationToken ct)
{
var result = await _settingService.GetEffectiveAgentConfigAsync(agentId, ct);
var result = await _mediator.Send(new GetEffectiveAgentConfigQuery(agentId), ct);
return result.IsSuccess
? Ok(result.Data)
: NotFound(new { error = result.Error });
@@ -145,7 +157,7 @@ public class SettingsController : ControllerBase
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<IActionResult> ListAgentOverrides(Guid agentId, CancellationToken ct)
{
var result = await _settingService.GetAgentSettingsAsync(agentId, ct);
var result = await _mediator.Send(new GetAgentSettingsQuery(agentId), ct);
return result.IsSuccess
? Ok(result.Data)
: NotFound(new { error = result.Error });
@@ -163,7 +175,8 @@ public class SettingsController : ControllerBase
public async Task<IActionResult> SetAgentOverride(
Guid agentId, [FromBody] SetAgentSettingRequest request, CancellationToken ct)
{
var result = await _settingService.SetAgentSettingAsync(agentId, request, ct);
var command = new SetAgentSettingCommand(agentId, request.Key, request.Value);
var result = await _mediator.Send(command, ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
@@ -184,7 +197,7 @@ public class SettingsController : ControllerBase
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<IActionResult> RemoveAgentOverride(Guid agentId, string key, CancellationToken ct)
{
var result = await _settingService.RemoveAgentSettingAsync(agentId, key, ct);
var result = await _mediator.Send(new RemoveAgentSettingCommand(agentId, key), ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });