Skip to content

Commit

Permalink
Merge pull request #869 from DFE-Digital/feature/178419-ofsted-prereg…
Browse files Browse the repository at this point in the history
…istration-actualdate

178419 - Build: Ofsted pre-registration, change fields & add actual date inspections completed
  • Loading branch information
sukhybhullar-nimble authored Oct 7, 2024
2 parents c4435e2 + d60a3ba commit c7195c7
Show file tree
Hide file tree
Showing 18 changed files with 13,126 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Dfe.ManageFreeSchoolProjects.API.Contracts.Common;

namespace Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks;

public class OfstedInspectionTask
Expand All @@ -12,9 +14,11 @@ public class OfstedInspectionTask

public bool? SharedOutcomeWithTrust { get; set; }

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

public bool? ProposedToOpenOnGias { get; set; }

public bool? SavedToWorkplaces { get; set; }

public DateTime? DateInspectionsAndAnyActionsCompleted { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
using Dfe.ManageFreeSchoolProjects.API.Tests.Fixtures;
using Dfe.ManageFreeSchoolProjects.API.Tests.Helpers;
using System.Threading.Tasks;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Common;

namespace Dfe.ManageFreeSchoolProjects.API.Tests.Integration.Tasks
{
[Collection(ApiTestCollection.ApiTestCollectionName)]
public class OfstedInspectionApiTests : ApiTestsBase
public class OfstedInspectionApiTests(ApiTestFixture apiTestFixture) : ApiTestsBase(apiTestFixture)
{
public OfstedInspectionApiTests(ApiTestFixture apiTestFixture) : base(apiTestFixture)
{
}

[Fact]
public async Task Patch_NewOfstedInspection_Returns_201()
{
Expand All @@ -32,9 +29,10 @@ public async Task Patch_NewOfstedInspection_Returns_201()
OfstedAndTrustLiaisonDetailsConfirmed = true,
BlockAndContentDetailsToOpenersSpreadSheet = true,
SharedOutcomeWithTrust = true,
InspectionConditionsMet = true,
InspectionConditionsMet = YesNoNotApplicable.Yes,
ProposedToOpenOnGias = true,
SavedToWorkplaces = true,
DateInspectionsAndAnyActionsCompleted = new DateTime().Date.AddDays(10)
}
};

Expand All @@ -56,6 +54,8 @@ public async Task Patch_NewOfstedInspection_Returns_201()
.Be(request.OfstedInspection.ProposedToOpenOnGias);
projectResponse.OfstedInspection.SavedToWorkplaces.Should()
.Be(request.OfstedInspection.SavedToWorkplaces);
projectResponse.OfstedInspection.DateInspectionsAndAnyActionsCompleted.Should()
.Be(request.OfstedInspection.DateInspectionsAndAnyActionsCompleted);
}

[Fact]
Expand All @@ -80,19 +80,15 @@ public async Task Patch_ExistingOfstedInspection_Returns_201()
OfstedAndTrustLiaisonDetailsConfirmed = false,
BlockAndContentDetailsToOpenersSpreadSheet = false,
SharedOutcomeWithTrust = false,
InspectionConditionsMet = false,
InspectionConditionsMet = YesNoNotApplicable.NotApplicable,
ProposedToOpenOnGias = false,
SavedToWorkplaces = false
SavedToWorkplaces = false,
DateInspectionsAndAnyActionsCompleted = null
}
};

await _client.UpdateProjectTask(projectId, request, TaskName.OfstedInspection.ToString());

var updateRequest = new UpdateProjectByTaskRequest()
{
OfstedInspection = new()
};


var projectResponse = await _client.UpdateProjectTask(projectId, request, TaskName.OfstedInspection.ToString());

projectResponse.OfstedInspection.ProcessDetailsProvided.Should()
Expand All @@ -111,6 +107,8 @@ public async Task Patch_ExistingOfstedInspection_Returns_201()
.Be(request.OfstedInspection.ProposedToOpenOnGias);
projectResponse.OfstedInspection.SavedToWorkplaces.Should()
.Be(request.OfstedInspection.SavedToWorkplaces);
projectResponse.OfstedInspection.DateInspectionsAndAnyActionsCompleted.Should()
.Be(request.OfstedInspection.DateInspectionsAndAnyActionsCompleted);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,19 @@ namespace Dfe.ManageFreeSchoolProjects.API.Controllers
{
[Route("api/v{version:apiVersion}/client/projects/{projectId}/tasks")]
[ApiController]
public class ProjectTaskController : ControllerBase
public class ProjectTaskController(
IUpdateProjectByTaskService updateProjectTaskService,
IGetProjectByTaskService getProjectByTaskService,
IGetTasksService getTasksService,
ILogger<ProjectTaskController> logger)
: ControllerBase
{
private readonly IUpdateProjectByTaskService _updateProjectTaskService;
private readonly IGetProjectByTaskService _getProjectByTaskService;
private readonly IGetTasksService _getTasksService;
private readonly ILogger<ProjectTaskController> _logger;

public ProjectTaskController(
IUpdateProjectByTaskService updateProjectTaskService,
IGetProjectByTaskService getProjectByTaskService,
IGetTasksService getTasksService,
ILogger<ProjectTaskController> logger)
{
_updateProjectTaskService = updateProjectTaskService;
_getProjectByTaskService = getProjectByTaskService;
_getTasksService = getTasksService;
_logger = logger;
}

[HttpPatch]
public async Task<ActionResult> PatchTask(string projectId, UpdateProjectByTaskRequest request)
{
_logger.LogMethodEntered();
logger.LogMethodEntered();

await _updateProjectTaskService.Execute(projectId, request);
await updateProjectTaskService.Execute(projectId, request);

return new OkResult();
}
Expand All @@ -42,13 +30,13 @@ public async Task<ActionResult> PatchTask(string projectId, UpdateProjectByTaskR
[Route("{taskName}")]
public async Task<ActionResult<ApiSingleResponseV2<GetProjectByTaskResponse>>> GetProjectByTask(string projectId, TaskName taskName)
{
_logger.LogMethodEntered();
logger.LogMethodEntered();

var projectByTask = await _getProjectByTaskService.Execute(projectId, taskName);
var projectByTask = await getProjectByTaskService.Execute(projectId, taskName);

if (projectByTask == null)
{
_logger.LogInformation("No project could be found for the given project id {projectId}", projectId);
logger.LogInformation("No project could be found for the given project id {projectId}", projectId);
return new NotFoundResult();
}

Expand All @@ -62,9 +50,9 @@ public async Task<ActionResult<ApiSingleResponseV2<GetProjectByTaskResponse>>> G
public async Task<ActionResult<ApiSingleResponseV2<ProjectByTaskSummaryResponse>>> GetProjectTaskListSummary(
string projectId)
{
_logger.LogMethodEntered();
logger.LogMethodEntered();

var summary = await _getTasksService.Execute(projectId);
var summary = await getTasksService.Execute(projectId);

var response = new ApiSingleResponseV2<ProjectByTaskSummaryResponse>(summary);

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
@@ -1,4 +1,5 @@
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Common;
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks;
using Dfe.ManageFreeSchoolProjects.Data.Entities.Existing;

namespace Dfe.ManageFreeSchoolProjects.API.UseCases.Project.Tasks.OfstedInspection
Expand All @@ -8,35 +9,27 @@ public static class OfstedInspectionTaskBuilder
public static OfstedInspectionTask Build(Milestones milestones)
{
if (milestones == null)
{
return new OfstedInspectionTask();
}

var inspectionConditionMet = milestones.FsgPreOpeningMilestonesInspectionConditionsMet;

return new OfstedInspectionTask()
return new OfstedInspectionTask
{
ProcessDetailsProvided = milestones.FsgPreOpeningMilestonesProcessDetailsProvided,
InspectionBlockDecided = milestones.FsgPreOpeningMilestonesInspectionBlockDecided,
OfstedAndTrustLiaisonDetailsConfirmed = milestones.FsgPreOpeningMilestonesOfstedAndTrustLiaisonDetailsConfirmed,
BlockAndContentDetailsToOpenersSpreadSheet = milestones.FsgPreOpeningMilestonesBlockAndContentDetailsToOpenersSpreadSheet,
OfstedAndTrustLiaisonDetailsConfirmed =
milestones.FsgPreOpeningMilestonesOfstedAndTrustLiaisonDetailsConfirmed,
BlockAndContentDetailsToOpenersSpreadSheet =
milestones.FsgPreOpeningMilestonesBlockAndContentDetailsToOpenersSpreadSheet,
SharedOutcomeWithTrust = milestones.FsgPreOpeningMilestonesSharedOutcomeWithTrust,
ProposedToOpenOnGias = milestones.FsgPreOpeningMilestonesProposedToOpenOnGias,
SavedToWorkplaces = milestones.FsgPreOpeningMilestonesDocumentsAndG6SavedToWorkplaces,
InspectionConditionsMet = InspectionConditionsMet(milestones.FsgPreOpeningMilestonesInspectionConditionsMet),
InspectionConditionsMet = !string.IsNullOrEmpty(inspectionConditionMet)
? EnumParsers.ParseInspectionConditionsMetToEnum(inspectionConditionMet)
: EnumParsers.ParseInspectionConditionsMetToEnum(milestones
.FsgPreOpeningInspectionConditionsMetNotApplicable),
DateInspectionsAndAnyActionsCompleted = milestones.FsgPreOpeningMilestonesOprActualDateOfCompletion
};

}

private static bool? InspectionConditionsMet(string condition)
{
switch (condition)
{
case "Yes":
return true;
case "No":
return false;
default:
return null;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@

using Dfe.ManageFreeSchoolProjects.API.Contracts.Common;
using Dfe.ManageFreeSchoolProjects.API.Extensions;
using Dfe.ManageFreeSchoolProjects.Data;
using Dfe.ManageFreeSchoolProjects.Data.Entities.Existing;
using Microsoft.EntityFrameworkCore;

namespace Dfe.ManageFreeSchoolProjects.API.UseCases.Project.Tasks.OfstedInspection
{
public class UpdateOfstedInspectionTaskService : IUpdateTaskService
public class UpdateOfstedInspectionTaskService(MfspContext context) : IUpdateTaskService
{

private readonly MfspContext _context;

public UpdateOfstedInspectionTaskService(MfspContext context)
{
_context = context;
}

public async Task Update(UpdateTaskServiceParameters parameters)
{
var task = parameters.Request.OfstedInspection;
var dbKpi = parameters.Kpi;

if (task is null)
{
return;
}

var db = await _context.Milestones.FirstOrDefaultAsync(r => r.Rid == dbKpi.Rid);

var db = await context.Milestones.FirstOrDefaultAsync(r => r.Rid == dbKpi.Rid);

if (db == null)
{
db = new Data.Entities.Existing.Milestones();
db.Rid = dbKpi.Rid;
_context.Add(db);
db = new Milestones { Rid = dbKpi.Rid };
context.Add(db);
}

db.FsgPreOpeningMilestonesProcessDetailsProvided = task.ProcessDetailsProvided;
db.FsgPreOpeningMilestonesInspectionBlockDecided = task.InspectionBlockDecided;
db.FsgPreOpeningMilestonesOfstedAndTrustLiaisonDetailsConfirmed = task.OfstedAndTrustLiaisonDetailsConfirmed;
db.FsgPreOpeningMilestonesBlockAndContentDetailsToOpenersSpreadSheet = task.BlockAndContentDetailsToOpenersSpreadSheet;
db.FsgPreOpeningMilestonesSharedOutcomeWithTrust = task.SharedOutcomeWithTrust;
db.FsgPreOpeningMilestonesInspectionConditionsMet = InspectionConditionsMet(task.InspectionConditionsMet);
db.FsgPreOpeningMilestonesProposedToOpenOnGias = task.ProposedToOpenOnGias;
db.FsgPreOpeningMilestonesDocumentsAndG6SavedToWorkplaces = task.SavedToWorkplaces;
}

private static string InspectionConditionsMet(bool? conditionMet)
{
switch (conditionMet)
db.FsgPreOpeningMilestonesOprActualDateOfCompletion = task.DateInspectionsAndAnyActionsCompleted;


switch (task.InspectionConditionsMet)
{
case true:
return "Yes";
case false:
return "No";
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:
return null;
db.FsgPreOpeningInspectionConditionsMetNotApplicable = null;
db.FsgPreOpeningMilestonesInspectionConditionsMet = null;
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,11 @@ public interface IUpdateProjectByTaskService
public Task Execute(string projectId, UpdateProjectByTaskRequest request);
}

public class UpdateProjectByTaskService : IUpdateProjectByTaskService
public class UpdateProjectByTaskService(MfspContext context, IEnumerable<IUpdateTaskService> updateTaskServices) : IUpdateProjectByTaskService
{
private readonly MfspContext _context;
private readonly IEnumerable<IUpdateTaskService> _updateTaskServices;

public UpdateProjectByTaskService(
MfspContext context,
IEnumerable<IUpdateTaskService> updateTaskServices)
{
_context = context;
_updateTaskServices = updateTaskServices;
}

public async Task Execute(string projectId, UpdateProjectByTaskRequest request)
{
var dbKpi = await _context.Kpi.FirstOrDefaultAsync(p => p.ProjectStatusProjectId == projectId);
var dbKpi = await context.Kpi.FirstOrDefaultAsync(p => p.ProjectStatusProjectId == projectId);

if (dbKpi == null)
{
Expand All @@ -40,21 +29,22 @@ public async Task Execute(string projectId, UpdateProjectByTaskRequest request)
Request = request
};

foreach (var updateTaskService in _updateTaskServices)
foreach (var updateTaskService in updateTaskServices)
{
await updateTaskService.Update(updateParameters);
}

await UpdateTaskStatus(dbKpi.Rid, Status.InProgress, request);

await _context.SaveChangesAsync();
await context.SaveChangesAsync();
}

private async Task UpdateTaskStatus(string taskRid, Status updatedStatus, UpdateProjectByTaskRequest updateProjectByTaskRequest)
private async Task UpdateTaskStatus(string taskRid, Status updatedStatus,
UpdateProjectByTaskRequest updateProjectByTaskRequest)
{
var taskNameToUpdate = Enum.Parse<TaskName>(updateProjectByTaskRequest.TaskToUpdate);

var task = await _context.Tasks.FirstOrDefaultAsync(x => x.Rid == taskRid && x.TaskName == taskNameToUpdate);
var task = await context.Tasks.FirstOrDefaultAsync(x => x.Rid == taskRid && x.TaskName == taskNameToUpdate);
if (task is null)
return;

Expand Down
Loading

0 comments on commit c7195c7

Please sign in to comment.