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 GetSession { public class Query : Query { public string BotName { get; set; } public string ExternalId { get; set; } public string ClientApplication { get; set; } public string UserKey { get; set; } public Query() { } } public class Model { public Guid SessionId { get; set; } public DateTime StartDate { get; set; } } public class QueryHandler : IRequestHandler { private readonly IBotRepository _botRepository; private readonly ISessionRepository _sessionRepository; private readonly IMapper _mapper; public QueryHandler(IBotRepository botRepository, ISessionRepository sessionRepository, IMapper mapper) { _botRepository = botRepository; _sessionRepository = sessionRepository; _mapper = mapper; } public async Task Handle(Query request, CancellationToken cancellationToken) { var botId = await _botRepository.GetBotId(request.BotName); var session = await _sessionRepository.CreateSession(botId, request.ClientApplication, request.ExternalId, request.UserKey); var result = _mapper.Map(session); return result; } } } }