diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Dfe.PrepareConversions.Data.csproj b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Dfe.PrepareConversions.Data.csproj index 6a3dfdf30..0c9513d16 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Dfe.PrepareConversions.Data.csproj +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Dfe.PrepareConversions.Data.csproj @@ -14,6 +14,7 @@ + diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs index b180371ab..1c2a9dcd6 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/ApiClient.cs @@ -29,7 +29,10 @@ public async Task GetAllProjectsAsync(AcademyConversionSear { return await AcademisationClient.PostAsync(PathFor.GetAllProjects, JsonContent.Create(searchModel)); } - + public async Task DownloadProjectExport(AcademyConversionSearchModel searchModel) + { + return await AcademisationClient.PostAsync(PathFor.DownloadProjectExport, JsonContent.Create(searchModel)); + } public async Task GetProjectByIdAsync(int id) { diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs index d3f8d422c..70800c179 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/IApiClient.cs @@ -7,6 +7,7 @@ namespace Dfe.PrepareConversions.Data.Features; public interface IApiClient { Task GetAllProjectsAsync(AcademyConversionSearchModel searchModel); + Task DownloadProjectExport(AcademyConversionSearchModel searchModel); Task GetProjectByIdAsync(int id); Task UpdateProjectAsync(int id, UpdateAcademyConversionProject updateProject); Task GetFilterParametersAsync(); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs index 574aa8dd2..123591ef1 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Features/PathFor.cs @@ -12,6 +12,7 @@ public PathFor(IFeatureManager features) } public string GetApplicationByReference => _useAcademisationApplication ? "/application/{0}/applicationReference" : "/v2/apply-to-become/application/{0}"; public static string GetAllProjects => "/legacy/projects"; + public static string DownloadProjectExport => "/export/export-projects"; public static string GetProjectById => "/legacy/project/{0}"; public static string UpdateProject => "/legacy/project/{0}"; public static string GetFilterParameters => "/legacy/projects/status"; diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs index 23c72be82..4154dfd23 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/AcademyConversionProjectRepository.cs @@ -4,6 +4,7 @@ using Dfe.PrepareConversions.Data.Models; using Dfe.PrepareConversions.Data.Models.NewProject; using Dfe.PrepareConversions.Data.Services.Interfaces; +using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -132,6 +133,31 @@ public async Task> AddProjectNote(int id, AddProjectNot ? new ApiResponse(response.StatusCode, addProjectNote.ToProjectNote()) : new ApiResponse(response.StatusCode, null); } + public async Task> DownloadProjectExport( + int page, + int count, + string titleFilter = "", + IEnumerable statusFilters = default, + IEnumerable deliveryOfficerFilter = default, + IEnumerable regionsFilter = default, + IEnumerable applicationReferences = default) + { + AcademyConversionSearchModel searchModel = new() { TitleFilter = titleFilter, Page = page, Count = count }; + + ProcessFilters(statusFilters, deliveryOfficerFilter, searchModel, regionsFilter, applicationReferences); + + HttpResponseMessage response = await _apiClient.DownloadProjectExport(searchModel); + if (!response.IsSuccessStatusCode) + { + return new ApiResponse(response.StatusCode, null); + } + + var stream = await response.Content.ReadAsStreamAsync(); + FileStreamResult fileStreamResult = new(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + + return new ApiResponse(response.StatusCode, fileStreamResult); + } + private void ProcessFilters(IEnumerable statusFilters, IEnumerable deliveryOfficerFilter, diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs index c40a18ae7..3b6954b3d 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/IAcademyConversionProjectRepository.cs @@ -1,5 +1,6 @@ using Dfe.PrepareConversions.Data.Models; using Dfe.PrepareConversions.Data.Models.NewProject; +using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; @@ -16,6 +17,15 @@ Task>>> GetAllPro IEnumerable regionsFilter = default, IEnumerable applicationReferences = default ); + Task> DownloadProjectExport( + int page, + int count, + string titleFilter = "", + IEnumerable statusFilters = default, + IEnumerable deliveryOfficerFilter = default, + IEnumerable regionsFilter = default, + IEnumerable applicationReferences = default +); Task> GetProjectById(int id); Task> UpdateProject(int id, UpdateAcademyConversionProject updateProject); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/SchoolOverviewService.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/SchoolOverviewService.cs index dad813df8..ae0690a26 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/SchoolOverviewService.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.Data/Services/SchoolOverviewService.cs @@ -16,6 +16,7 @@ public SchoolOverviewService(IGetEstablishment getEstablishment) public async Task GetSchoolOverviewByUrn(string urn) { + // TODO: Technical Debt - enrich EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn); SchoolOverview schoolOverview = new() { diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs index aa22e465b..cc20b185f 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ProjectList/Index.cshtml.cs @@ -51,4 +51,19 @@ public async Task OnGetAsync() Filters.AvailableRegions = filterParametersResponse.Body.Regions; } } + public async Task OnGetDownload() + { + Filters.PersistUsing(TempData).PopulateFrom(Request.Query); + ApiResponse response = await _repository.DownloadProjectExport(CurrentPage, PageSize, Filters.Title, Filters.SelectedStatuses, Filters.SelectedOfficers, Filters.SelectedRegions); + + if (response.Success) + { + return response.Body; + } + else + { + return null; + } + } + } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_ProjectListFilters.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_ProjectListFilters.cshtml index f605dca0b..3e5f586d3 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_ProjectListFilters.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/Shared/_ProjectListFilters.cshtml @@ -6,6 +6,7 @@ Filter projects + Download as a spreadsheet
diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs index e16bd171d..957b1ed75 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/AcademyConversionProjectItemsCacheDecorator.cs @@ -3,6 +3,7 @@ using Dfe.PrepareConversions.Data.Models.NewProject; using Dfe.PrepareConversions.Data.Services; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Threading.Tasks; @@ -26,7 +27,18 @@ public async Task { return await _innerRepository.GetAllProjects(page, count, titleFilter, statusFilters, deliveryOfficerFilter, regionsFilter, applicationReferences); } - + public async Task> DownloadProjectExport( + int page, + int count, + string titleFilter = "", + IEnumerable statusFilters = default, + IEnumerable deliveryOfficerFilter = default, + IEnumerable regionsFilter = default, + IEnumerable applicationReferences = default +) + { + return await _innerRepository.DownloadProjectExport(page, count, titleFilter, statusFilters, deliveryOfficerFilter, regionsFilter, applicationReferences); + } public async Task> GetProjectById(int id) { if (_httpContext.Items.ContainsKey(id) && _httpContext.Items[id] is ApiResponse cached)