| 1234567891011121314151617181920212223242526272829303132 |
- using Diligent.WebAPI.Business.Interfaces;
- using Diligent.WebAPI.Business.Services;
- using Diligent.WebAPI.Data.Entities;
- using Diligent.WebAPI.Host.Exceptions;
- using Diligent.WebAPI.Host.Mediator.Messages.Commands;
- using MediatR;
-
- namespace Diligent.WebAPI.Host.Mediator.Messages.Handlers
- {
- public class AddMessageHandler : IRequestHandler<AddMessageCommand, Unit>
- {
- private readonly IRoomRepository _roomRepository;
-
- public AddMessageHandler(IRoomRepository roomRepository)
- {
- _roomRepository = roomRepository;
- }
- public async Task<Unit> Handle(AddMessageCommand request, CancellationToken cancellationToken)
- {
- var room = await _roomRepository.GetByIdAsync(request.roomId);
-
- if(room == null)
- {
- throw new NotFoundException("Room is not found");
- }
-
- await _roomRepository.AddMessage(room, request.message);
-
- return new Unit();
- }
- }
- }
|