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,6 +1,14 @@
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Services;
|
||||
using Heimdall.Application.Groups.Commands.CreateGroup;
|
||||
using Heimdall.Application.Groups.Commands.UpdateGroup;
|
||||
using Heimdall.Application.Groups.Commands.DeleteGroup;
|
||||
using Heimdall.Application.Groups.Commands.AddUserToGroup;
|
||||
using Heimdall.Application.Groups.Commands.RemoveUserFromGroup;
|
||||
using Heimdall.Application.Groups.Queries.GetGroups;
|
||||
using Heimdall.Application.Groups.Queries.GetGroup;
|
||||
using Heimdall.Application.Groups.Queries.GetGroupMembers;
|
||||
using Heimdall.Infrastructure.Security;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
@@ -16,9 +24,9 @@ namespace Heimdall.Api.Controllers;
|
||||
[EnableRateLimiting("Api")]
|
||||
public class GroupsController : ControllerBase
|
||||
{
|
||||
private readonly IGroupService _groupService;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public GroupsController(IGroupService groupService) => _groupService = groupService;
|
||||
public GroupsController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
/// <summary>List all groups (Admin only).</summary>
|
||||
[HttpGet]
|
||||
@@ -27,7 +35,7 @@ public class GroupsController : ControllerBase
|
||||
public async Task<IActionResult> List(
|
||||
[FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default)
|
||||
{
|
||||
var result = await _groupService.ListAsync(page, pageSize, ct);
|
||||
var result = await _mediator.Send(new GetGroupsQuery(page, pageSize), ct);
|
||||
if (!result.IsSuccess)
|
||||
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
return Ok(result.Data);
|
||||
@@ -39,7 +47,7 @@ public class GroupsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.GetByIdAsync(id, ct);
|
||||
var result = await _mediator.Send(new GetGroupQuery(id), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: NotFound(new { error = result.Error });
|
||||
@@ -51,7 +59,8 @@ public class GroupsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> Create([FromBody] CreateGroupRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.CreateAsync(request, ct);
|
||||
var command = new CreateGroupCommand(request.Name, request.Description);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -65,7 +74,8 @@ public class GroupsController : ControllerBase
|
||||
public async Task<IActionResult> Update(
|
||||
Guid id, [FromBody] UpdateGroupRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.UpdateAsync(id, request, ct);
|
||||
var command = new UpdateGroupCommand(id, request.Name, request.Description);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -77,7 +87,7 @@ public class GroupsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.DeleteAsync(id, ct);
|
||||
var result = await _mediator.Send(new DeleteGroupCommand(id), ct);
|
||||
return result.IsSuccess
|
||||
? Ok()
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -90,7 +100,7 @@ public class GroupsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> AddUser(Guid groupId, Guid userId, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.AddUserAsync(groupId, userId, ct);
|
||||
var result = await _mediator.Send(new AddUserToGroupCommand(groupId, userId), ct);
|
||||
return result.IsSuccess
|
||||
? Ok()
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -103,7 +113,7 @@ public class GroupsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> RemoveUser(Guid groupId, Guid userId, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.RemoveUserAsync(groupId, userId, ct);
|
||||
var result = await _mediator.Send(new RemoveUserFromGroupCommand(groupId, userId), ct);
|
||||
return result.IsSuccess
|
||||
? Ok()
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
@@ -115,7 +125,7 @@ public class GroupsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetMembers(Guid groupId, CancellationToken ct)
|
||||
{
|
||||
var result = await _groupService.GetMembersAsync(groupId, ct);
|
||||
var result = await _mediator.Send(new GetGroupMembersQuery(groupId), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
|
||||
Reference in new issue
Block a user