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

47 lines
1.2 KiB
C#
Raw Permalink Normal View History

2020-06-06 18:29:20 +03:00
using AutoMapper;
using Chatbot.Api.Domain.Repositories;
using MediatR;
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;
}
}
}
}