55using GovUK . Dfe . CoreLibs . Contracts . ExternalApplications . Models . Request ;
66using GovUK . Dfe . CoreLibs . Contracts . ExternalApplications . Models . Response ;
77using DfE . ExternalApplications . Application . Interfaces ;
8+ using DfE . ExternalApplications . Application . Options ;
89using GovUK . Dfe . ExternalApplications . Api . Client . Contracts ;
910using GovUK . Dfe . ExternalApplications . Api . Client . Security ;
1011using Microsoft . AspNetCore . Authorization ;
1112using Microsoft . AspNetCore . Mvc ;
1213using Microsoft . AspNetCore . Mvc . RazorPages ;
14+ using Microsoft . Extensions . Options ;
1315using SystemTask = System . Threading . Tasks . Task ;
1416using Microsoft . Extensions . Configuration ;
1517
@@ -22,7 +24,8 @@ public class DashboardModel(
2224 IApplicationsClient applicationsClient ,
2325 IHttpContextAccessor httpContextAccessor ,
2426 IApplicationResponseService applicationResponseService ,
25- IFormTemplateProvider templateProvider )
27+ IFormTemplateProvider templateProvider ,
28+ IOptions < DashboardOptions > dashboardOptions )
2629 : PageModel
2730 {
2831 public string ? Email { get ; private set ; }
@@ -33,6 +36,12 @@ public class DashboardModel(
3336 public bool HasError { get ; private set ; }
3437 public string ? ErrorMessage { get ; private set ; }
3538
39+ [ BindProperty ( SupportsGet = true ) ]
40+ public int CurrentPage { get ; set ; } = 1 ;
41+
42+ public int TotalPages { get ; private set ; }
43+ public int PageSize => dashboardOptions . Value . PageSize ;
44+
3645 public class ApplicationWithCalculatedStatus
3746 {
3847 public ApplicationDto Application { get ; set ; } = null ! ;
@@ -157,20 +166,23 @@ private async SystemTask LoadApplicationsAsync()
157166 return ;
158167 }
159168
160- var applications = await applicationsClient . GetMyApplicationsAsync ( templateId : templateGuid . Value ) ;
169+ var pageSize = dashboardOptions . Value . PageSize ;
170+ var result = await applicationsClient . GetMyApplicationsAsync (
171+ templateId : templateGuid . Value ,
172+ pageNumber : CurrentPage ,
173+ pageSize : pageSize ) ;
161174
162- // Calculate status for each application
163- var applicationTasks = applications . Select ( async app => new ApplicationWithCalculatedStatus
175+ TotalPages = result . TotalPages ;
176+ CurrentPage = Math . Clamp ( CurrentPage , 1 , Math . Max ( 1 , TotalPages ) ) ;
177+
178+ var applicationTasks = result . Items . AsEnumerable ( ) . Select ( async app => new ApplicationWithCalculatedStatus
164179 {
165180 Application = app ,
166181 CalculatedStatus = await GetCalculatedApplicationStatusAsync ( app )
167182 } ) ;
168183
169- var applicationsWithStatus = await SystemTask . WhenAll ( applicationTasks ) ;
170-
171- Applications = applicationsWithStatus
172- . OrderByDescending ( a => a . DateCreated )
173- . ToList ( ) ;
184+ Applications = [ ..( await SystemTask . WhenAll ( applicationTasks ) )
185+ . OrderByDescending ( a => a . DateCreated ) ] ;
174186 }
175187
176188 private Guid ? ResolveTemplateId ( )
0 commit comments