using Diligent.WebAPI.Business.Interfaces; using Diligent.WebAPI.Host.Exceptions; using Diligent.WebAPI.Host.Mediator.Notifications.Commands; using MediatR; namespace Diligent.WebAPI.Host.Mediator.Notifications.Handlers { public class DeleteNotificationHandler : IRequestHandler { private readonly ICustomerRepository _customerRepository; public DeleteNotificationHandler(ICustomerRepository customerRepository) { _customerRepository = customerRepository; } public async Task Handle(DeleteNotificationCommand request, CancellationToken cancellationToken) { var user = await _customerRepository.GetCustomerById(request.NotificationData.UserId); if (user == null) { throw new NotFoundException(); } var notification = user.Notifications.Where(x => x.RoomId == request.NotificationData.RoomId).FirstOrDefault(); if (notification == null) { throw new NotFoundException(); } await _customerRepository.DeleteNotification(user, notification); return new Unit(); } } }