Skip to content

Commit

Permalink
Merge pull request #954 from DFE-Digital/feature/spreadsheet-download
Browse files Browse the repository at this point in the history
Spreadsheet download
  • Loading branch information
dneed-nimble authored Dec 12, 2023
2 parents ccdaa86 + 8cdc929 commit 24ae51e
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="Dfe.Academies.Contracts" Version="1.0.9" />
<PackageReference Include="Dfe.Academisation.CorrelationIdMiddleware" Version="2.0.2" />
<PackageReference Include="Dfe.Academisation.ExtensionMethods" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
<PackageReference Include="Microsoft.FeatureManagement" Version="2.5.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public async Task<HttpResponseMessage> GetAllProjectsAsync(AcademyConversionSear
{
return await AcademisationClient.PostAsync(PathFor.GetAllProjects, JsonContent.Create(searchModel));
}

public async Task<HttpResponseMessage> DownloadProjectExport(AcademyConversionSearchModel searchModel)
{
return await AcademisationClient.PostAsync(PathFor.DownloadProjectExport, JsonContent.Create(searchModel));
}

public async Task<HttpResponseMessage> GetProjectByIdAsync(int id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Dfe.PrepareConversions.Data.Features;
public interface IApiClient
{
Task<HttpResponseMessage> GetAllProjectsAsync(AcademyConversionSearchModel searchModel);
Task<HttpResponseMessage> DownloadProjectExport(AcademyConversionSearchModel searchModel);
Task<HttpResponseMessage> GetProjectByIdAsync(int id);
Task<HttpResponseMessage> UpdateProjectAsync(int id, UpdateAcademyConversionProject updateProject);
Task<HttpResponseMessage> GetFilterParametersAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,6 +133,31 @@ public async Task<ApiResponse<ProjectNote>> AddProjectNote(int id, AddProjectNot
? new ApiResponse<ProjectNote>(response.StatusCode, addProjectNote.ToProjectNote())
: new ApiResponse<ProjectNote>(response.StatusCode, null);
}
public async Task<ApiResponse<FileStreamResult>> DownloadProjectExport(
int page,
int count,
string titleFilter = "",
IEnumerable<string> statusFilters = default,
IEnumerable<string> deliveryOfficerFilter = default,
IEnumerable<string> regionsFilter = default,
IEnumerable<string> 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<FileStreamResult>(response.StatusCode, null);
}

var stream = await response.Content.ReadAsStreamAsync();
FileStreamResult fileStreamResult = new(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

return new ApiResponse<FileStreamResult>(response.StatusCode, fileStreamResult);
}


private void ProcessFilters(IEnumerable<string> statusFilters,
IEnumerable<string> deliveryOfficerFilter,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,6 +17,15 @@ Task<ApiResponse<ApiV2Wrapper<IEnumerable<AcademyConversionProject>>>> GetAllPro
IEnumerable<string> regionsFilter = default,
IEnumerable<string> applicationReferences = default
);
Task<ApiResponse<FileStreamResult>> DownloadProjectExport(
int page,
int count,
string titleFilter = "",
IEnumerable<string> statusFilters = default,
IEnumerable<string> deliveryOfficerFilter = default,
IEnumerable<string> regionsFilter = default,
IEnumerable<string> applicationReferences = default
);

Task<ApiResponse<AcademyConversionProject>> GetProjectById(int id);
Task<ApiResponse<AcademyConversionProject>> UpdateProject(int id, UpdateAcademyConversionProject updateProject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public SchoolOverviewService(IGetEstablishment getEstablishment)

public async Task<SchoolOverview> GetSchoolOverviewByUrn(string urn)
{
// TODO: Technical Debt - enrich
EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn);
SchoolOverview schoolOverview = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@ public async Task OnGetAsync()
Filters.AvailableRegions = filterParametersResponse.Body.Regions;
}
}
public async Task<FileStreamResult> OnGetDownload()
{
Filters.PersistUsing(TempData).PopulateFrom(Request.Query);
ApiResponse<FileStreamResult> response = await _repository.DownloadProjectExport(CurrentPage, PageSize, Filters.Title, Filters.SelectedStatuses, Filters.SelectedOfficers, Filters.SelectedRegions);

if (response.Success)
{
return response.Body;
}
else
{
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<span class="govuk-details__summary-text govuk-button govuk-button--secondary prepare-project-listing__button--main">
Filter projects
</span>
<a class="govuk-button govuk-button--secondary" asp-page-handler="Download"> Download as a spreadsheet</a>
</summary>
<div class="govuk-details__text prepare-project-listing__filters-details" data-id="filter-container">
<form method="get" class="form">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,7 +27,18 @@ public async Task<ApiResponse<ApiV2Wrapper<IEnumerable<AcademyConversionProject>
{
return await _innerRepository.GetAllProjects(page, count, titleFilter, statusFilters, deliveryOfficerFilter, regionsFilter, applicationReferences);
}

public async Task<ApiResponse<FileStreamResult>> DownloadProjectExport(
int page,
int count,
string titleFilter = "",
IEnumerable<string> statusFilters = default,
IEnumerable<string> deliveryOfficerFilter = default,
IEnumerable<string> regionsFilter = default,
IEnumerable<string> applicationReferences = default
)
{
return await _innerRepository.DownloadProjectExport(page, count, titleFilter, statusFilters, deliveryOfficerFilter, regionsFilter, applicationReferences);
}
public async Task<ApiResponse<AcademyConversionProject>> GetProjectById(int id)
{
if (_httpContext.Items.ContainsKey(id) && _httpContext.Items[id] is ApiResponse<AcademyConversionProject> cached)
Expand Down

0 comments on commit 24ae51e

Please sign in to comment.