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:
1 parent
c1b3b3d3b4
commit
1d1ac8387e
33 files changed
+611
-195
No files matched your search
@@ -1,7 +1,13 @@
|
||||
using System.Security.Claims;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Services;
|
||||
using Heimdall.Application.Sites.Commands.CreateSite;
|
||||
using Heimdall.Application.Sites.Commands.UpdateSite;
|
||||
using Heimdall.Application.Sites.Commands.DeleteSite;
|
||||
using Heimdall.Application.Sites.Commands.GenerateSiteToken;
|
||||
using Heimdall.Application.Sites.Queries.GetSites;
|
||||
using Heimdall.Application.Sites.Queries.GetSite;
|
||||
using Heimdall.Infrastructure.Security;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
@@ -13,9 +19,9 @@ namespace Heimdall.Api.Controllers;
|
||||
[EnableRateLimiting("Api")]
|
||||
public class SitesController : ControllerBase
|
||||
{
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public SitesController(ISiteService siteService) => _siteService = siteService;
|
||||
public SitesController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
/// <summary>Create a new site (Admin only).</summary>
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteWrite)]
|
||||
@@ -30,7 +36,8 @@ public class SitesController : ControllerBase
|
||||
if (string.IsNullOrEmpty(userIdClaim) || !Guid.TryParse(userIdClaim, out var userId))
|
||||
return Unauthorized(new { error = "Invalid user identity" });
|
||||
|
||||
var result = await _siteService.CreateAsync(request, userId, ct);
|
||||
var command = new CreateSiteCommand(request.Name, request.Address, request.Timezone);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -44,7 +51,7 @@ public class SitesController : ControllerBase
|
||||
public async Task<IActionResult> List(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default)
|
||||
{
|
||||
var result = await _siteService.ListAsync(page, pageSize, ct);
|
||||
var result = await _mediator.Send(new GetSitesQuery(page, pageSize), ct);
|
||||
if (!result.IsSuccess)
|
||||
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
return Ok(result.Data);
|
||||
@@ -57,7 +64,7 @@ public class SitesController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _siteService.GetByIdAsync(id, ct);
|
||||
var result = await _mediator.Send(new GetSiteQuery(id), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: NotFound(new { error = result.Error });
|
||||
@@ -72,7 +79,8 @@ public class SitesController : ControllerBase
|
||||
public async Task<IActionResult> Update(
|
||||
Guid id, [FromBody] UpdateSiteRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _siteService.UpdateAsync(id, request, ct);
|
||||
var command = new UpdateSiteCommand(id, request.Name, request.Address, request.Timezone);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -86,7 +94,7 @@ public class SitesController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _siteService.DeleteAsync(id, ct);
|
||||
var result = await _mediator.Send(new DeleteSiteCommand(id), ct);
|
||||
return result.IsSuccess
|
||||
? NoContent()
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -100,7 +108,7 @@ public class SitesController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GenerateToken(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _siteService.GenerateTokenAsync(id, ct);
|
||||
var result = await _mediator.Send(new GenerateSiteTokenCommand(id), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
|
||||
Reference in new issue
Block a user