| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Api.Stocks.GetDisclosures;
- /// <summary>
- /// 전자공시(DART) 최신 공시 목록 — corpCls 선택 필터 후 접수일(RceptDt) 내림차순, 동일자는 접수번호(RceptNo) 내림차순 페이징 (익명).
- /// </summary>
- internal sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
- {
- private const ushort MaxPerPage = 100;
- public async Task<Response> Handle(Query request, CancellationToken ct)
- {
- var page = request.Page < 1 ? 1 : request.Page;
- var perPage = request.PerPage is 0 or > MaxPerPage ? (ushort)20 : request.PerPage;
- var query = db.Disclosure.AsNoTracking();
- if (!string.IsNullOrWhiteSpace(request.CorpCls))
- {
- var corpCls = request.CorpCls.Trim();
- query = query.Where(c => c.CorpCls == corpCls);
- }
- var total = await query.CountAsync(ct);
- var list = await query
- .OrderByDescending(c => c.RceptDt).ThenByDescending(c => c.RceptNo)
- .Skip((page - 1) * perPage)
- .Take(perPage)
- .Select(c => new Response.Row
- {
- RceptNo = c.RceptNo,
- CorpCode = c.CorpCode,
- CorpName = c.CorpName,
- StockCode = c.StockCode,
- CorpCls = c.CorpCls,
- ReportNm = c.ReportNm,
- FlrNm = c.FlrNm,
- RceptDt = c.RceptDt,
- Rm = c.Rm
- })
- .ToListAsync(ct);
- return new Response
- {
- Total = total,
- List = list
- };
- }
- }
|