Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split QualificationDetailsController.cs #479

Open
wants to merge 8 commits into
base: release/02-Dec-24-R1
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<IActionResult> Confirm(ConfirmQualificationPageModel model)
"QualificationDetails",
new { qualificationId = model.QualificationId }),

_ => RedirectToAction("Get", "QualificationDetails")
_ => RedirectToAction("Get", "QualificationSearch")
};
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Dfe.EarlyYearsQualification.Web.Attributes;
using Dfe.EarlyYearsQualification.Web.Controllers.Base;
using Dfe.EarlyYearsQualification.Web.Services.QualificationSearch;
using Microsoft.AspNetCore.Mvc;

namespace Dfe.EarlyYearsQualification.Web.Controllers;

[Route("/qualifications")]
[RedirectIfDateMissing]
public class QualificationSearchController(
ILogger<QualificationSearchController> logger,
IQualificationSearchService qualificationSearchService)
: ServiceController
{
[HttpGet]
public async Task<IActionResult> Get()
{
var qualifications = await qualificationSearchService.GetQualifications();
if (qualifications is null)
{
logger.LogError("No content for the qualification list page");
return RedirectToAction("Index", "Error");
}

return View(qualifications);
}

[HttpPost]
public IActionResult Refine(string? refineSearch)
{
if (!ModelState.IsValid)
{
logger.LogWarning($"Invalid model state in {nameof(QualificationSearchController)} POST");
}

qualificationSearchService.Refine(refineSearch ?? string.Empty);

return RedirectToAction("Get");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Dfe.EarlyYearsQualification.Web.Models.Content.QuestionModels.Validators;
using Dfe.EarlyYearsQualification.Web.Services.UserJourneyCookieService;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Dfe.EarlyYearsQualification.Web.Controllers;

Expand Down Expand Up @@ -218,7 +217,7 @@ public async Task<IActionResult> WhatIsTheAwardingOrganisation(DropdownQuestionM
userJourneyCookieService.SetAwardingOrganisation(model.NotInTheList ? string.Empty : model.SelectedValue!);
userJourneyCookieService.SetAwardingOrganisationNotOnList(model.NotInTheList);

return RedirectToAction("Get", "QualificationDetails");
return RedirectToAction("Get", "QualificationSearch");
}

private async Task<List<Qualification>> GetFilteredQualifications()
Expand Down Expand Up @@ -251,7 +250,7 @@ private async Task<RadioQuestionModel> MapRadioModel(RadioQuestionModel model, R
{
var additionalInformationBody = await contentParser.ToHtml(question.AdditionalInformationBody);
return RadioQuestionMapper.Map(model, question, actionName, controllerName, additionalInformationBody,
selectedAnswer);
selectedAnswer);
}

private async Task<DateQuestionModel> MapDateModel(DateQuestionModel model, DateQuestionPage question,
Expand All @@ -264,21 +263,21 @@ private async Task<DateQuestionModel> MapDateModel(DateQuestionModel model, Date
var bannerErrorText = validationResult is { BannerErrorMessages.Count: > 0 }
? string.Join("<br />", validationResult!.BannerErrorMessages)
: null;

var errorMessageText = validationResult is { ErrorMessages.Count: > 0 }
? string.Join("<br />", validationResult!.ErrorMessages)
: null;
? string.Join("<br />", validationResult!.ErrorMessages)
: null;

var errorBannerLinkText =
placeholderUpdater.Replace(bannerErrorText ?? question.ErrorBannerLinkText);

var errorMessage = placeholderUpdater.Replace(errorMessageText ?? question.ErrorMessage);

var additionalInformationBody = await contentParser.ToHtml(question.AdditionalInformationBody);

return DateQuestionMapper.Map(model, question, actionName, controllerName, errorBannerLinkText,
errorMessage, additionalInformationBody, validationResult, selectedMonth,
selectedYear);
errorMessage, additionalInformationBody, validationResult, selectedMonth,
selectedYear);
}

private async Task<DropdownQuestionModel> MapDropdownModel(DropdownQuestionModel model,
Expand All @@ -296,7 +295,7 @@ var uniqueAwardingOrganisations
.Distinct()
.Where(x => !Array.Exists(awardingOrganisationExclusions, x.Contains))
.Order();

var additionalInformationBodyHtml = await contentParser.ToHtml(question.AdditionalInformationBody);

return DropdownQuestionMapper.Map(model, question, actionName, controllerName, uniqueAwardingOrganisations,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
using Dfe.EarlyYearsQualification.Content.Entities;

namespace Dfe.EarlyYearsQualification.Web.Models.Content;

public class BasicQualificationModel
{
protected BasicQualificationModel()
{
}

public BasicQualificationModel(Qualification qualification)
{
QualificationId = qualification.QualificationId;
QualificationLevel = qualification.QualificationLevel;
QualificationName = qualification.QualificationName;
AwardingOrganisationTitle = qualification.AwardingOrganisationTitle;
}

public string QualificationId { get; init; } = string.Empty;

public string QualificationName { get; init; } = string.Empty;

public string AwardingOrganisationTitle { get; init; } = string.Empty;

public int QualificationLevel { get; init; }
}
4 changes: 4 additions & 0 deletions src/Dfe.EarlyYearsQualification.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Dfe.EarlyYearsQualification.Web.Services.Cookies;
using Dfe.EarlyYearsQualification.Web.Services.CookiesPreferenceService;
using Dfe.EarlyYearsQualification.Web.Services.DatesAndTimes;
using Dfe.EarlyYearsQualification.Web.Services.QualificationDetails;
using Dfe.EarlyYearsQualification.Web.Services.QualificationSearch;
using Dfe.EarlyYearsQualification.Web.Services.UserJourneyCookieService;
using GovUk.Frontend.AspNetCore;
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
Expand Down Expand Up @@ -99,6 +101,8 @@
builder.Services.AddTransient<IQualificationsRepository, QualificationsRepository>();
}

builder.Services.AddTransient<IQualificationDetailsService, QualificationDetailsService>();
builder.Services.AddTransient<IQualificationSearchService, QualificationSearchService>();
builder.Services.AddModelRenderers();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddScoped<ICookieManager, CookieManager>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Dfe.EarlyYearsQualification.Content.Entities;
using Dfe.EarlyYearsQualification.Web.Models.Content;

namespace Dfe.EarlyYearsQualification.Web.Services.QualificationDetails;

public interface IQualificationDetailsService
{
Task<Qualification?> GetQualification(string qualificationId);
Task<DetailsPage?> GetDetailsPage();
bool HasStartDate();
Task<string?> GetFeedbackBannerBodyToHtml(FeedbackBanner? feedbackBanner);
Comment on lines +8 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in two minds about these ones. I wonder if they should be moved out of this service, then the service only focuses on the mapping etc. of qualification data?

bool QualificationContainsQtsQuestion(Qualification qualification);
bool UserAnswerMatchesQtsQuestionAnswerToBeFullAndRelevant(Qualification qualification, List<AdditionalRequirementAnswerModel>? additionalRequirementAnswerModels);
bool AnswersIndicateNotFullAndRelevant(List<AdditionalRequirementAnswerModel> additionalRequirementsAnswers);
RatioRequirementModel MarkAsNotFullAndRelevant(RatioRequirementModel model);
Task QualificationLevel3OrAboveMightBeRelevantAtLevel2(QualificationDetailsModel model, Qualification qualification);
Task CheckRatioRequirements(Qualification qualification, QualificationDetailsModel model);
(bool isFullAndRelevant, QualificationDetailsModel details) RemainingAnswersIndicateFullAndRelevant(QualificationDetailsModel details, AdditionalRequirementQuestion qtsQuestion);
Task<QualificationDetailsModel> CheckLevel6Requirements(Qualification qualification, QualificationDetailsModel details);
bool DoAdditionalAnswersMatchQuestions(QualificationDetailsModel details);
NavigationLink? CalculateBackButton(DetailsPage content, string qualificationId);
List<AdditionalRequirementAnswerModel>? MapAdditionalRequirementAnswers(List<AdditionalRequirementQuestion>? additionalRequirementQuestions);
Task<QualificationDetailsModel> MapDetails(Qualification qualification, DetailsPage content);
}
Loading
Loading