http-api/src/Application/Aircrafts/Commands/DeleteAircraft/DeleteAircraftCommandHandler.cs
cuqmbr 3ebd0c3a2c
All checks were successful
/ build (push) Successful in 6m13s
/ tests (push) Successful in 47s
/ build-docker (push) Successful in 6m48s
add vehicles hierarchy management
2025-05-03 10:09:52 +03:00

35 lines
1000 B
C#

using MediatR;
using cuqmbr.TravelGuide.Application.Common.Interfaces.Persistence;
using cuqmbr.TravelGuide.Application.Common.Exceptions;
namespace cuqmbr.TravelGuide.Application.Aircrafts.Commands.DeleteAircraft;
public class DeleteAircraftCommandHandler : IRequestHandler<DeleteAircraftCommand>
{
private readonly UnitOfWork _unitOfWork;
public DeleteAircraftCommandHandler(UnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task Handle(
DeleteAircraftCommand request,
CancellationToken cancellationToken)
{
var entity = await _unitOfWork.AircraftRepository.GetOneAsync(
e => e.Guid == request.Guid, cancellationToken);
if (entity == null)
{
throw new NotFoundException();
}
await _unitOfWork.AircraftRepository.DeleteOneAsync(
entity, cancellationToken);
await _unitOfWork.SaveAsync(cancellationToken);
_unitOfWork.Dispose();
}
}