using Application.Abstractions.Messaging; using Application.Abstractions.Data; using Microsoft.EntityFrameworkCore; namespace Application.Features.Admin.Forum.BoardGroup.GetAll { public sealed class Handler(IAppDbContext db) : IQueryHandler { public async Task Handle(Query request, CancellationToken ct) { var items = await db.BoardGroup .AsNoTracking() .OrderBy(c => c.Order) .ThenByDescending(c => c.ID) .Select(c => new { c.ID, c.Code, c.Name, c.Order, c.Boards, c.Posts, c.Comments, c.UpdatedAt, c.CreatedAt }) .ToListAsync(ct); return new Response( items.Count, [..items.Select((c, i) => new Response.Row( i + 1, c.ID, i, c.Code, c.Name, c.Order, c.Boards, c.Posts, c.Comments, c.UpdatedAt, c.CreatedAt ))]); } } }