chatbot/Chatbot.Api.Application/CommandHandlers/CloseChatHandler.cs

26 lines
754 B
C#

using Chatbot.Api.Application.Commands;
using Chatbot.Api.Application.Events;
using Chatbot.Api.Domain.Repositories;
using MediatR;
using System.Threading;
using System.Threading.Tasks;
namespace Chatbot.Api.Application.CommandHandlers
{
public class CloseChatHandler : IRequestHandler<CloseChat, ChatClosed>
{
private readonly IChatRepository _chatRepository;
public CloseChatHandler(IChatRepository chatRepository)
{
_chatRepository = chatRepository;
}
public async Task<ChatClosed> Handle(CloseChat request, CancellationToken cancellationToken)
{
await _chatRepository.CloseChat(request.ChatId);
return new ChatClosed(request.ChatId);
}
}
}