47 lines
1.2 KiB
C#
47 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 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;
|
|
}
|
|
}
|
|
}
|
|
}
|