45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using AutoMapper;
|
|
using Chatbot.Api.Domain.Repositories;
|
|
using MediatR;
|
|
using NDB.Application.DataContracts;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|