| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using Diligent.WebAPI.Business.Interfaces;
- using Diligent.WebAPI.Business.Services;
- using Diligent.WebAPI.Host.Exceptions;
- using Diligent.WebAPI.Host.Mediator.Rooms.Commands;
- using MediatR;
-
- namespace Diligent.WebAPI.Host.Mediator.Chat.Handlers
- {
- public class RemoveUserFromGroupHandler : IRequestHandler<RemoveUserFromGroupCommand, Unit>
- {
- private readonly IRoomRepository _roomRepository;
-
- public RemoveUserFromGroupHandler(IRoomRepository roomRepository)
- {
- _roomRepository = roomRepository;
- }
-
- public async Task<Unit> Handle(RemoveUserFromGroupCommand request, CancellationToken cancellationToken)
- {
- var room = await _roomRepository.GetByIdAsync(request.RoomId);
-
- if(room == null)
- {
- throw new NotFoundException("Room is not found");
- }
-
- var userConnection = room.Customers.Where(x => x.CustomerId == request.UserId).FirstOrDefault();
-
- if(userConnection == null)
- {
- throw new NotFoundException("User connection is not found");
- }
-
- await _roomRepository.LeaveChatRoom(room, userConnection);
-
- return new Unit();
- }
- }
- }
|