update
This commit is contained in:
1 parent
37997203b2
commit
b4fac2bd3c
2 files changed
+30
-6
No files matched your search
@@ -265,12 +265,33 @@ public sealed class CampusRegistrationsController(AppDbContext db, ICurrentUserD
|
||||
|
||||
[HttpGet("applications")]
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> GetApplications([FromQuery] Guid? projectId, [FromQuery] CampusRegistrationApplicationStatus? status, CancellationToken ct)
|
||||
public async Task<ActionResult> GetApplications(
|
||||
[FromQuery] Guid? projectId,
|
||||
[FromQuery] CampusRegistrationApplicationStatus? status,
|
||||
[FromQuery] int? page,
|
||||
[FromQuery] int? pageSize,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var source = ScopedApplications().AsNoTracking();
|
||||
if (projectId.HasValue) source = source.Where(x => x.ProjectId == projectId);
|
||||
if (status.HasValue) source = source.Where(x => x.Status == status);
|
||||
return Ok(await source.OrderByDescending(x => x.CreatedAt).Select(ProjectApplicationDto()).ToListAsync(ct));
|
||||
|
||||
var ordered = source
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.ThenByDescending(x => x.Id);
|
||||
if (!page.HasValue && !pageSize.HasValue)
|
||||
return Ok(await ordered.Select(ProjectApplicationDto()).ToListAsync(ct));
|
||||
|
||||
var normalizedPage = Math.Max(1, page ?? 1);
|
||||
var normalizedPageSize = Math.Clamp(pageSize ?? 20, 1, 100);
|
||||
|
||||
var total = await source.CountAsync(ct);
|
||||
var items = await ordered
|
||||
.Skip((normalizedPage - 1) * normalizedPageSize)
|
||||
.Take(normalizedPageSize)
|
||||
.Select(ProjectApplicationDto())
|
||||
.ToListAsync(ct);
|
||||
return Ok(new PagedResult<object>(items, total, normalizedPage, normalizedPageSize));
|
||||
}
|
||||
|
||||
[HttpGet("applications/export.xlsx")]
|
||||
|
||||
Reference in new issue
Block a user