Skip to content

Commit

Permalink
Merge pull request #815 from DFE-Digital/177731-iterate-capacity-when…
Browse files Browse the repository at this point in the history
…-full-pupil-numbers

177731 - Iterate capacity when fill (pupil numbers)
  • Loading branch information
sukhybhullar-nimble authored Sep 16, 2024
2 parents a7d8432 + bbe55fb commit e6b0e0a
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public record ProjectRiskOverviewResponse

public record PupilNumbersOverviewResponse
{
public int Capacity { get; set; }
public int TotalCapacity { get; set; }
public int Pre16PublishedAdmissionNumber { get; set; }
public int Post16PublishedAdmissionNumber { get; set; }
public int MinimumViableNumberForFirstYear { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task When_Get_AllFieldsSet_Returns_200()

// Pupil numbers
var pupilNumbers = result.Data.PupilNumbers;
pupilNumbers.Capacity.Should().Be(300);
pupilNumbers.TotalCapacity.Should().Be(300);
pupilNumbers.Pre16PublishedAdmissionNumber.Should().Be(15);
pupilNumbers.Post16PublishedAdmissionNumber.Should().Be(67);
pupilNumbers.MinimumViableNumberForFirstYear.Should().Be(121);
Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task When_Get_MandatoryFieldsSet_Returns_200()

// Pupil numbers
var pupilNumbers = result.Data.PupilNumbers;
pupilNumbers.Capacity.Should().Be(0);
pupilNumbers.TotalCapacity.Should().Be(0);
pupilNumbers.Pre16PublishedAdmissionNumber.Should().Be(0);
pupilNumbers.Post16PublishedAdmissionNumber.Should().Be(0);
pupilNumbers.MinimumViableNumberForFirstYear.Should().Be(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,30 @@ public interface IGetProjectOverviewService
public Task<ProjectOverviewResponse> Execute(string projectId);
}

public class GetProjectOverviewService : IGetProjectOverviewService
public class GetProjectOverviewService(MfspContext context, IGetProjectSitesService getProjectSitesService) : IGetProjectOverviewService
{
private readonly MfspContext _context;
private readonly IGetProjectSitesService _getProjectSitesService;

public GetProjectOverviewService(
MfspContext context,
IGetProjectSitesService getProjectSitesService)
{
_context = context;
_getProjectSitesService = getProjectSitesService;
}

public async Task<ProjectOverviewResponse> Execute(string projectId)
{
var project = await _context.Kpi.FirstOrDefaultAsync(k => k.ProjectStatusProjectId == projectId);
var project = await context.Kpi.FirstOrDefaultAsync(k => k.ProjectStatusProjectId == projectId);

if (project == null)
{
throw new NotFoundException($"Project {projectId} not found");
}

var risk = await GetRisk(project.Rid);
var sites = await _getProjectSitesService.Execute(project);
var sites = await getProjectSitesService.Execute(project);
var pupilNumbers = await GetPupilNumbers(project.Rid);

return BuildOverviewResponse(project, risk, sites, pupilNumbers);
}

private static ProjectOverviewResponse BuildOverviewResponse(
Kpi project,
ProjectRiskOverviewResponse risk,
GetProjectSitesResponse sites,
Kpi project,
ProjectRiskOverviewResponse risk,
GetProjectSitesResponse sites,
PupilNumbersOverviewResponse pupilNumbers)
{

var projectOverviewResponse = new ProjectOverviewResponse()
{
ProjectStatus = new ProjectStatusResponse()
Expand Down Expand Up @@ -116,25 +104,26 @@ private static ProjectOverviewResponse BuildOverviewResponse(
PupilNumbers = pupilNumbers
};

projectOverviewResponse.ProjectType = projectOverviewResponse.ProjectStatus.ApplicationWave == "FS - Presumption"
projectOverviewResponse.ProjectType =
projectOverviewResponse.ProjectStatus.ApplicationWave == "FS - Presumption"
? "Presumption"
: "Central Route";

return projectOverviewResponse;
return projectOverviewResponse;
}

private async Task<ProjectRiskOverviewResponse> GetRisk(string rid)
{
var rag = await _context.Rag
.Select(e => new
var rag = await context.Rag
.Select(e => new
{
e.Rid,
RiskRating = e.RagRatingsOverallRagRating,
Summary = e.RagRatingsOverallRagSummary,
Date = EF.Property<DateTime>(e, "PeriodStart")
}).FirstOrDefaultAsync(r => r.Rid == rid);

if (rag == null)
if (rag == null)
{
return new ProjectRiskOverviewResponse();
}
Expand All @@ -151,31 +140,21 @@ private async Task<ProjectRiskOverviewResponse> GetRisk(string rid)

private async Task<PupilNumbersOverviewResponse> GetPupilNumbers(string rid)
{
var result = await _context.Po
var result = await context.Po
.Where(p => p.Rid == rid)
.Select(po =>
new PupilNumbersOverviewResponse()
.Select(po => new PupilNumbersOverviewResponse
{
Capacity = po.PupilNumbersAndCapacityNurseryUnder5s.ToInt() +
po.PupilNumbersAndCapacityYrY6Capacity.ToInt() +
po.PupilNumbersAndCapacityY7Y11Capacity.ToInt() +
po.PupilNumbersAndCapacityY12Y14Post16Capacity.ToInt() +
po.PupilNumbersAndCapacitySpecialistResourceProvisionSpecial.ToInt() +
po.PupilNumbersAndCapacitySpecialistResourceProvisionAp.ToInt(),
TotalCapacity = po.PupilNumbersAndCapacityTotalOfCapacityTotals.ToInt(),
Pre16PublishedAdmissionNumber = po.PupilNumbersAndCapacityTotalPanPre16.ToInt(),
Post16PublishedAdmissionNumber = po.PupilNumbersAndCapacityTotalPanPost16.ToInt(),
MinimumViableNumberForFirstYear = po.PupilNumbersAndCapacityMinimumFirstYearRecruitmentForViabilityTotal.ToInt(),
MinimumViableNumberForFirstYear =
po.PupilNumbersAndCapacityMinimumFirstYearRecruitmentForViabilityTotal.ToInt(),
ApplicationsReceived = po.PupilNumbersAndCapacityNoApplicationsReceivedTotal.ToInt(),
AcceptedOffers = po.PupilNumbersAndCapacityNoApplicationsAcceptedTotal.ToInt(),
})
.FirstOrDefaultAsync();

if (result == null)
{
return new PupilNumbersOverviewResponse();
}

return result;
return result ?? new PupilNumbersOverviewResponse();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("Testing the setting of pupil numbers", () => {
.hasYear12ToYear14("40")
.hasSpecialEducationalNeeds("50")
.hasAlternativeProvision("60")
.hasTotal("210");
.hasTotal("90");
});

it("Should be able to edit the pre-16 published admission numbers", () => {
Expand Down Expand Up @@ -592,7 +592,7 @@ describe("Testing the setting of pupil numbers", () => {
viewPupilNumbersPage.backToProjectOverview();

pupilNumbersSummaryComponent
.hasCapacity("210")
.hasCapacity("90")
.hasPre16PublishedAdmissionNumber("110")
.hasPost16PublishedAdmissionNumber("35")
.hasMinimumViableNumber("168")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class PupilNumbersSummaryComponent {

public hasCapacity(value: string): this {
cy.getByTestId("capacity").should("contain.text", value);
cy.getByTestId("total-capacity").should("contain.text", value);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,10 @@
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Capacity
Total capacity
</dt>
<dd class="govuk-summary-list__value" data-testid="capacity">
@Model.Project.PupilNumbers.Capacity
<dd class="govuk-summary-list__value" data-testid="total-capacity">
@Model.Project.PupilNumbers.TotalCapacity
</dd>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@

<table class="govuk-table govuk-table__border--full govuk-table--small">
<caption class="govuk-table__caption govuk-table__caption--m govuk-visually-hidden">Edit Capacity when full</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header mfsp-pupil-numbers-table__first-header">School group</th>
<th scope="col" class="govuk-table__header">Capacity</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">Reception to year 6</td>
<td class="govuk-table__cell">
<govuk-number-input-cell id="reception-to-year6" name="reception-to-year6" asp-for="@Model.ReceptionToYear6" label="Reception to year 6" />
</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Year 7 to year 11</td>
<td class="govuk-table__cell">
<govuk-number-input-cell id="year7-to-year11" name="year7-to-year11" asp-for="@Model.Year7ToYear11" label="Year 7 to year 11" />

</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Year 12 to year 14</td>
<td class="govuk-table__cell">
<govuk-number-input-cell id="year12-to-year14" name="year12-to-year14" asp-for="@Model.Year12ToYear14" label="Year 12 to year 14" />

</td>
</tr>
</tbody>
</table>


<table class="govuk-table govuk-table__border--full govuk-table--small">
<caption class="govuk-table__caption govuk-table__caption--m govuk-visually-hidden">Nursery and specialist resource provision</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header mfsp-pupil-numbers-table__first-header">School group</th>
Expand All @@ -40,27 +73,6 @@
<govuk-number-input-cell id="nursery" name="nursery" asp-for="@Model.Nursery" label="Nursery" />
</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Reception to year 6</td>
<td class="govuk-table__cell">
<govuk-number-input-cell id="reception-to-year6" name="reception-to-year6" asp-for="@Model.ReceptionToYear6" label="Reception to year 6" />

</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Year 7 to year 11</td>
<td class="govuk-table__cell">
<govuk-number-input-cell id="year7-to-year11" name="year7-to-year11" asp-for="@Model.Year7ToYear11" label="Year 7 to year 11" />

</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Year 12 to year 14</td>
<td class="govuk-table__cell">
<govuk-number-input-cell id="year12-to-year14" name="year12-to-year14" asp-for="@Model.Year12ToYear14" label="Year 12 to year 14" />

</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">Special educational needs (specialist resource provision)</td>
<td class="govuk-table__cell">
Expand Down
Loading

0 comments on commit e6b0e0a

Please sign in to comment.