| 1234567891011121314151617181920212223242526272829303132333435363738 |
- 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<DeleteNotificationCommand, Unit>
- {
- private readonly ICustomerRepository _customerRepository;
-
- public DeleteNotificationHandler(ICustomerRepository customerRepository)
- {
- _customerRepository = customerRepository;
- }
-
- public async Task<Unit> 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();
- }
- }
- }
|