fix(scale): page mail and batch roles
This commit is contained in:
@@ -51,14 +51,48 @@ namespace JobTrackerApi.Controllers
|
||||
int LabelCount,
|
||||
int AttachmentCount);
|
||||
|
||||
public sealed record CorrespondenceInboxPageDto(
|
||||
List<CorrespondenceInboxItemDto> Items,
|
||||
int Page,
|
||||
int PageSize,
|
||||
int Total,
|
||||
int TotalPages);
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<List<CorrespondenceInboxItemDto>>> GetInbox(
|
||||
[FromQuery] string? q,
|
||||
[FromQuery] string? direction,
|
||||
[FromQuery] string? linkState,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var query = BuildInboxQuery(q, direction, linkState);
|
||||
var items = await LoadInboxItemsAsync(query, 0, 200, cancellationToken);
|
||||
return Ok(items);
|
||||
}
|
||||
|
||||
[HttpGet("page")]
|
||||
public async Task<ActionResult<CorrespondenceInboxPageDto>> GetInboxPage(
|
||||
[FromQuery] string? q,
|
||||
[FromQuery] string? direction,
|
||||
[FromQuery] string? linkState,
|
||||
[FromQuery] int page = 1,
|
||||
[FromQuery] int pageSize = 50,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
page = Math.Max(1, page);
|
||||
pageSize = Math.Clamp(pageSize, 1, 100);
|
||||
var query = BuildInboxQuery(q, direction, linkState);
|
||||
var total = await query.CountAsync(cancellationToken);
|
||||
var totalPages = total == 0 ? 0 : (int)Math.Ceiling(total / (double)pageSize);
|
||||
if (totalPages > 0) page = Math.Min(page, totalPages);
|
||||
var items = await LoadInboxItemsAsync(query, (page - 1) * pageSize, pageSize, cancellationToken);
|
||||
return Ok(new CorrespondenceInboxPageDto(items, page, pageSize, total, totalPages));
|
||||
}
|
||||
|
||||
private IQueryable<Correspondence> BuildInboxQuery(string? q, string? direction, string? linkState)
|
||||
{
|
||||
var query = _db.Correspondences
|
||||
.AsNoTracking()
|
||||
.Include(c => c.JobApplication)
|
||||
.ThenInclude(j => j.Company)
|
||||
.AsQueryable();
|
||||
@@ -88,9 +122,20 @@ namespace JobTrackerApi.Controllers
|
||||
query = query.Where(c => c.ExternalThreadId == null);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
private static async Task<List<CorrespondenceInboxItemDto>> LoadInboxItemsAsync(
|
||||
IQueryable<Correspondence> query,
|
||||
int skip,
|
||||
int take,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var rows = await query
|
||||
.OrderByDescending(c => c.Date)
|
||||
.Take(200)
|
||||
.ThenByDescending(c => c.Id)
|
||||
.Skip(skip)
|
||||
.Take(take)
|
||||
.Select(c => new
|
||||
{
|
||||
c.Id,
|
||||
@@ -132,7 +177,7 @@ namespace JobTrackerApi.Controllers
|
||||
DeserializeLabels(c.ExternalLabelsJson).Count,
|
||||
DeserializeAttachments(c.AttachmentMetadataJson).Count)).ToList();
|
||||
|
||||
return Ok(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
// GET all messages for a job
|
||||
|
||||
Reference in New Issue
Block a user