using Application.Abstractions.Data;
using Application.Abstractions.Messaging;
using Microsoft.EntityFrameworkCore;

namespace Application.Features.Api.News.GetSources;

public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
{
    public async Task<Response> Handle(Query request, CancellationToken ct)
    {
        var sources = await db.RssFeedSource.AsNoTracking().OrderBy(x => x.ID).Select(x => new Response.Row(x.ID, x.Name, x.Url, x.Description, x.IsActive, x.LastFetchedAt)).ToListAsync(ct);

        return new Response(sources);
    }
}