2020-06-06 18:29:20 +03:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Chatbot.Api.Domain.Repositories;
|
|
|
|
|
using MediatR;
|
2020-12-20 23:07:49 +02:00
|
|
|
|
using NDB.Application.DataContracts;
|
2020-06-06 18:29:20 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Chatbot.Api.Application.Queries
|
|
|
|
|
{
|
|
|
|
|
public class GetBots
|
|
|
|
|
{
|
|
|
|
|
public class Query : Query<Model[]>
|
|
|
|
|
{
|
|
|
|
|
public Query() { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Model
|
|
|
|
|
{
|
|
|
|
|
public Guid BotId { get; set; }
|
|
|
|
|
public string BotCode { get; set; }
|
|
|
|
|
public string BotName { get; set; }
|
|
|
|
|
public DateTime CreationDate { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class QueryHandler : IRequestHandler<Query, Model[]>
|
|
|
|
|
{
|
|
|
|
|
private readonly IBotRepository _botRepository;
|
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
|
|
|
|
public QueryHandler(IBotRepository botRepository, IMapper mapper)
|
|
|
|
|
{
|
|
|
|
|
_botRepository = botRepository;
|
|
|
|
|
_mapper = mapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Model[]> Handle(Query request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var bots = await _botRepository.GetBots();
|
|
|
|
|
var result = _mapper.Map<Model[]>(bots);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|