Skip to content

Commit

Permalink
simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zhodges-nimble committed Oct 7, 2024
1 parent a32086f commit d60a3ba
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public class OfstedInspectionTask

public bool? SharedOutcomeWithTrust { get; set; }

public string InspectionConditionsMet { get; set; }
public YesNoNotApplicable? InspectionConditionsMet { get; set; }

public string InspectionConditionsMetNotApplicable { get; set; }

public bool? ProposedToOpenOnGias { get; set; }

public bool? SavedToWorkplaces { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public async Task Patch_NewOfstedInspection_Returns_201()
OfstedAndTrustLiaisonDetailsConfirmed = true,
BlockAndContentDetailsToOpenersSpreadSheet = true,
SharedOutcomeWithTrust = true,
InspectionConditionsMetNotApplicable = "Not applicable",
InspectionConditionsMet = null,
InspectionConditionsMet = YesNoNotApplicable.Yes,
ProposedToOpenOnGias = true,
SavedToWorkplaces = true,
DateInspectionsAndAnyActionsCompleted = new DateTime().Date.AddDays(10)
Expand All @@ -49,8 +48,8 @@ public async Task Patch_NewOfstedInspection_Returns_201()
.Be(request.OfstedInspection.BlockAndContentDetailsToOpenersSpreadSheet);
projectResponse.OfstedInspection.SharedOutcomeWithTrust.Should()
.Be(request.OfstedInspection.SharedOutcomeWithTrust);
projectResponse.OfstedInspection.InspectionConditionsMetNotApplicable.Should()
.Be(request.OfstedInspection.InspectionConditionsMetNotApplicable);
projectResponse.OfstedInspection.InspectionConditionsMet.Should()
.Be(request.OfstedInspection.InspectionConditionsMet);
projectResponse.OfstedInspection.ProposedToOpenOnGias.Should()
.Be(request.OfstedInspection.ProposedToOpenOnGias);
projectResponse.OfstedInspection.SavedToWorkplaces.Should()
Expand Down Expand Up @@ -81,8 +80,7 @@ public async Task Patch_ExistingOfstedInspection_Returns_201()
OfstedAndTrustLiaisonDetailsConfirmed = false,
BlockAndContentDetailsToOpenersSpreadSheet = false,
SharedOutcomeWithTrust = false,
InspectionConditionsMetNotApplicable = null,
InspectionConditionsMet = "No",
InspectionConditionsMet = YesNoNotApplicable.NotApplicable,
ProposedToOpenOnGias = false,
SavedToWorkplaces = false,
DateInspectionsAndAnyActionsCompleted = null
Expand All @@ -103,8 +101,8 @@ public async Task Patch_ExistingOfstedInspection_Returns_201()
.Be(request.OfstedInspection.BlockAndContentDetailsToOpenersSpreadSheet);
projectResponse.OfstedInspection.SharedOutcomeWithTrust.Should()
.Be(request.OfstedInspection.SharedOutcomeWithTrust);
projectResponse.OfstedInspection.InspectionConditionsMetNotApplicable.Should()
.Be(request.OfstedInspection.InspectionConditionsMetNotApplicable);
projectResponse.OfstedInspection.InspectionConditionsMet.Should()
.Be(request.OfstedInspection.InspectionConditionsMet);
projectResponse.OfstedInspection.ProposedToOpenOnGias.Should()
.Be(request.OfstedInspection.ProposedToOpenOnGias);
projectResponse.OfstedInspection.SavedToWorkplaces.Should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Grants;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Common;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Grants;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks;
using Dfe.ManageFreeSchoolProjects.API.Extensions;
using static Dfe.ManageFreeSchoolProjects.API.Contracts.Project.ClassType;
Expand Down Expand Up @@ -69,4 +70,27 @@ public static TypeOfMeetingHeld ParseTypeOfMeetingHeld(string input)
{
return Enum.TryParse<TypeOfMeetingHeld>(input, out var typeOfMeetingHeld) ? typeOfMeetingHeld : TypeOfMeetingHeld.NotSet;
}

public static YesNoNotApplicable? ParseInspectionConditionsMetToEnum(string condition)
{
return condition switch
{
"Yes" => YesNoNotApplicable.Yes,
"No" => YesNoNotApplicable.No,
"Not applicable" => YesNoNotApplicable.NotApplicable,
_ => null
};

}

public static string ParseInspectionConditionsMetToString(YesNoNotApplicable? condition)
{
return condition switch
{
YesNoNotApplicable.Yes => "Yes",
YesNoNotApplicable.No => "No",
YesNoNotApplicable.NotApplicable => "Not applicable",
_ => null
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public static OfstedInspectionTask Build(Milestones milestones)
{
if (milestones == null)
return new OfstedInspectionTask();

var inspectionConditionMet = milestones.FsgPreOpeningMilestonesInspectionConditionsMet;

return new OfstedInspectionTask
{
Expand All @@ -22,8 +24,10 @@ public static OfstedInspectionTask Build(Milestones milestones)
SharedOutcomeWithTrust = milestones.FsgPreOpeningMilestonesSharedOutcomeWithTrust,
ProposedToOpenOnGias = milestones.FsgPreOpeningMilestonesProposedToOpenOnGias,
SavedToWorkplaces = milestones.FsgPreOpeningMilestonesDocumentsAndG6SavedToWorkplaces,
InspectionConditionsMetNotApplicable = milestones.FsgPreOpeningInspectionConditionsMetNotApplicable,
InspectionConditionsMet = milestones.FsgPreOpeningMilestonesInspectionConditionsMet,
InspectionConditionsMet = !string.IsNullOrEmpty(inspectionConditionMet)
? EnumParsers.ParseInspectionConditionsMetToEnum(inspectionConditionMet)
: EnumParsers.ParseInspectionConditionsMetToEnum(milestones
.FsgPreOpeningInspectionConditionsMetNotApplicable),
DateInspectionsAndAnyActionsCompleted = milestones.FsgPreOpeningMilestonesOprActualDateOfCompletion
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dfe.ManageFreeSchoolProjects.API.Extensions;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Common;
using Dfe.ManageFreeSchoolProjects.API.Extensions;
using Dfe.ManageFreeSchoolProjects.Data;
using Dfe.ManageFreeSchoolProjects.Data.Entities.Existing;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -31,8 +32,23 @@ public async Task Update(UpdateTaskServiceParameters parameters)
db.FsgPreOpeningMilestonesProposedToOpenOnGias = task.ProposedToOpenOnGias;
db.FsgPreOpeningMilestonesDocumentsAndG6SavedToWorkplaces = task.SavedToWorkplaces;
db.FsgPreOpeningMilestonesOprActualDateOfCompletion = task.DateInspectionsAndAnyActionsCompleted;
db.FsgPreOpeningInspectionConditionsMetNotApplicable = task.InspectionConditionsMetNotApplicable;
db.FsgPreOpeningMilestonesInspectionConditionsMet = task.InspectionConditionsMet;


switch (task.InspectionConditionsMet)
{
case YesNoNotApplicable.Yes or YesNoNotApplicable.No:
db.FsgPreOpeningMilestonesInspectionConditionsMet = task.InspectionConditionsMet.ToDescription();
db.FsgPreOpeningInspectionConditionsMetNotApplicable = null;
break;
case YesNoNotApplicable.NotApplicable:
db.FsgPreOpeningInspectionConditionsMetNotApplicable = task.InspectionConditionsMet.ToDescription();
db.FsgPreOpeningMilestonesInspectionConditionsMet = null;
break;
default:
db.FsgPreOpeningInspectionConditionsMetNotApplicable = null;
db.FsgPreOpeningMilestonesInspectionConditionsMet = null;
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,9 @@ public async Task<ActionResult> OnPost()
{
OfstedInspection = project.OfstedInspection
};


var parsedInspectionCondition = ParseInspectionConditionsMetToString(InspectionConditionsMet);

switch (InspectionConditionsMet)
{
case YesNoNotApplicable.No or YesNoNotApplicable.Yes:
request.OfstedInspection.InspectionConditionsMet = parsedInspectionCondition;
request.OfstedInspection.InspectionConditionsMetNotApplicable = null;
break;
case YesNoNotApplicable.NotApplicable:
request.OfstedInspection.InspectionConditionsMetNotApplicable = parsedInspectionCondition;
request.OfstedInspection.InspectionConditionsMet = null;
break;
}

request.OfstedInspection.SharedOutcomeWithTrust = SharedOutcomeWithTrust;

request.OfstedInspection.SharedOutcomeWithTrust = SharedOutcomeWithTrust;
request.OfstedInspection.InspectionConditionsMet = InspectionConditionsMet;
request.OfstedInspection.ProposedToOpenOnGias = ProposedToOpenOnGias;
request.OfstedInspection.SavedToWorkplaces = SavedToWorkplaces;
request.OfstedInspection.DateInspectionsAndAnyActionsCompleted = DateInspectionsAndAnyActionsCompleted;
Expand All @@ -92,41 +77,14 @@ public async Task<ActionResult> OnPost()
private async Task LoadProject()
{
var project = await getProjectService.Execute(ProjectId, TaskName.OfstedInspection);

var parsedInspectionConditionsMet = !string.IsNullOrEmpty(project.OfstedInspection.InspectionConditionsMet)
? ParseInspectionConditionsMetToEnum(project.OfstedInspection.InspectionConditionsMet)
: ParseInspectionConditionsMetToEnum(project.OfstedInspection.InspectionConditionsMetNotApplicable);

SharedOutcomeWithTrust = project.OfstedInspection.SharedOutcomeWithTrust;
InspectionConditionsMet = parsedInspectionConditionsMet;
InspectionConditionsMet = project.OfstedInspection.InspectionConditionsMet;
ProposedToOpenOnGias = project.OfstedInspection.ProposedToOpenOnGias;
SavedToWorkplaces = project.OfstedInspection.SavedToWorkplaces;
DateInspectionsAndAnyActionsCompleted = project.OfstedInspection.DateInspectionsAndAnyActionsCompleted;

SchoolName = project.SchoolName;
}

private static YesNoNotApplicable? ParseInspectionConditionsMetToEnum(string condition)
{
return condition switch
{
"Yes" => YesNoNotApplicable.Yes,
"No" => YesNoNotApplicable.No,
"Not applicable" => YesNoNotApplicable.NotApplicable,
_ => null
};

}

private static string ParseInspectionConditionsMetToString(YesNoNotApplicable? condition)
{
return condition switch
{
YesNoNotApplicable.Yes => "Yes",
YesNoNotApplicable.No => "No",
YesNoNotApplicable.NotApplicable => "Not applicable",
_ => null
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
var editBeforelink = string.Format(RouteConstants.EditBeforeOfstedInspectionTask, Model.ProjectId);
var editAfterlink = string.Format(RouteConstants.EditAfterOfstedInspectionTask, Model.ProjectId);
var ofstedPreRegistration = Model.Project.OfstedInspection;

var inspectionConditionsMet = ofstedPreRegistration.InspectionConditionsMet;

var inspectionConditionsMetIncludingNotApplicable = !string.IsNullOrEmpty(inspectionConditionsMet) && string.IsNullOrEmpty(ofstedPreRegistration.InspectionConditionsMetNotApplicable)
? inspectionConditionsMet
: ofstedPreRegistration.InspectionConditionsMetNotApplicable;
}

@section BeforeMain {
Expand Down Expand Up @@ -47,7 +41,7 @@

<govuk-summary-list>
<govuk-summary-item label="Shared the outcome with the trust" asp-for="@ofstedPreRegistration.SharedOutcomeWithTrust" href="@editAfterlink" id="afterpagelink"/>
<govuk-summary-item label="Any actions to meet conditions have been completed" asp-for="@inspectionConditionsMetIncludingNotApplicable" href="@editAfterlink"/>
<govuk-summary-item label="Any actions to meet conditions have been completed" asp-for="@ofstedPreRegistration.InspectionConditionsMet" href="@editAfterlink"/>
<govuk-summary-item label="Date that inspection and any actions completed" asp-for="@ofstedPreRegistration.DateInspectionsAndAnyActionsCompleted" href="@editAfterlink"/>
<govuk-summary-item label="Requested that the school is changed to 'proposed to open' on GIAS" asp-for="@ofstedPreRegistration.ProposedToOpenOnGias" href="@editAfterlink"/>
<govuk-summary-item label="Saved inspection documents and G6 agreement in Workplaces folder" asp-for="@ofstedPreRegistration.SavedToWorkplaces" href="@editAfterlink"/>
Expand Down

0 comments on commit d60a3ba

Please sign in to comment.