Handler.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Api.Stocks.GetDisclosures;
  5. /// <summary>
  6. /// 전자공시(DART) 최신 공시 목록 — corpCls 선택 필터 후 접수일(RceptDt) 내림차순, 동일자는 접수번호(RceptNo) 내림차순 페이징 (익명).
  7. /// </summary>
  8. internal sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
  9. {
  10. private const ushort MaxPerPage = 100;
  11. public async Task<Response> Handle(Query request, CancellationToken ct)
  12. {
  13. var page = request.Page < 1 ? 1 : request.Page;
  14. var perPage = request.PerPage is 0 or > MaxPerPage ? (ushort)20 : request.PerPage;
  15. var query = db.Disclosure.AsNoTracking();
  16. if (!string.IsNullOrWhiteSpace(request.CorpCls))
  17. {
  18. var corpCls = request.CorpCls.Trim();
  19. query = query.Where(c => c.CorpCls == corpCls);
  20. }
  21. var total = await query.CountAsync(ct);
  22. var list = await query
  23. .OrderByDescending(c => c.RceptDt).ThenByDescending(c => c.RceptNo)
  24. .Skip((page - 1) * perPage)
  25. .Take(perPage)
  26. .Select(c => new Response.Row
  27. {
  28. RceptNo = c.RceptNo,
  29. CorpCode = c.CorpCode,
  30. CorpName = c.CorpName,
  31. StockCode = c.StockCode,
  32. CorpCls = c.CorpCls,
  33. ReportNm = c.ReportNm,
  34. FlrNm = c.FlrNm,
  35. RceptDt = c.RceptDt,
  36. Rm = c.Rm
  37. })
  38. .ToListAsync(ct);
  39. return new Response
  40. {
  41. Total = total,
  42. List = list
  43. };
  44. }
  45. }