| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using Application.Abstractions.Messaging;
- using Application.Abstractions.Data;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Forum.BoardGroup.GetAll
- {
- public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
- {
- public async Task<Response> 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
- ))]);
- }
- }
- }
|