- Sites: CreateSite, UpdateSite, DeleteSite, GenerateToken commands + handlers - Auth: Login, Register, RefreshToken, 2FA, ChangePassword, Logout commands - Users: CRUD, roles, sites, lock/unlock, reset-password commands + queries - Cameras: CRUD, SetCredentials commands + queries - Add IApplicationDbContext abstraction for Clean Architecture - Add ICredentialProtector, IJwtService interfaces to Application layer - 0 build errors, 0 warnings
29 lines
804 B
C#
29 lines
804 B
C#
using Heimdall.Application.Common;
|
|
using MediatR;
|
|
|
|
namespace Heimdall.Application.Cameras.Commands.DeleteCamera;
|
|
|
|
public record DeleteCameraCommand(Guid Id) : IRequest<ServiceResult>;
|
|
|
|
public class DeleteCameraCommandHandler : IRequestHandler<DeleteCameraCommand, ServiceResult>
|
|
{
|
|
private readonly IApplicationDbContext _db;
|
|
|
|
public DeleteCameraCommandHandler(IApplicationDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
public async Task<ServiceResult> Handle(DeleteCameraCommand request, CancellationToken ct)
|
|
{
|
|
var camera = await _db.Cameras.FindAsync([request.Id], ct);
|
|
if (camera is null)
|
|
return ServiceResult.NotFound("Camera not found");
|
|
|
|
camera.SoftDelete();
|
|
await _db.SaveChangesAsync(ct);
|
|
|
|
return ServiceResult.Success();
|
|
}
|
|
}
|