30 lines
745 B
C#
30 lines
745 B
C#
using System.Threading;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using MediatR;
|
|
|
|
namespace HN.Application
|
|
{
|
|
public sealed class ListLinksQueryHandler : IRequestHandler<ListLinksQuery, LinkDTO[]>
|
|
{
|
|
private readonly IDbContext _context;
|
|
|
|
public ListLinksQueryHandler(IDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public Task<LinkDTO[]> Handle(ListLinksQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var links = from link in _context.Links
|
|
select new LinkDTO
|
|
{
|
|
Id = link.Id,
|
|
Url = link.Url,
|
|
CreatedAt = link.CreatedAt
|
|
};
|
|
|
|
return Task.FromResult(links.ToArray());
|
|
}
|
|
}
|
|
} |