chatbot/Chatbot.Api.Application/Queries/GetChat.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2020-06-06 23:18:41 +03:00
using AutoMapper;
using Chatbot.Api.Domain.Repositories;
using MediatR;
using NDB.Application.DataContracts;
2020-06-06 23:18:41 +03:00
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Chatbot.Api.Application.Queries
{
public class GetChat
{
public class Query : Query<Model>
{
public Guid SessionId { get; set; }
public Query() { }
}
public class Model
{
public Guid ChatId { get; set; }
}
public class QueryHandler : IRequestHandler<Query, Model>
{
private readonly IChatRepository _chatRepository;
private readonly IMapper _mapper;
public QueryHandler(IChatRepository chatRepository, IMapper mapper)
{
_chatRepository = chatRepository;
_mapper = mapper;
}
public async Task<Model> Handle(Query request, CancellationToken cancellationToken)
{
var chat = await _chatRepository.CreateChat(request.SessionId);
var result = _mapper.Map<Model>(chat);
return result;
}
}
}
}