-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/prod-deployment
- Loading branch information
Showing
32 changed files
with
1,191 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,21 @@ runs: | |
path: code-coverage-results.md | ||
message: | | ||
Code coverage report | ||
- name: Create Html coverage report | ||
uses: danielpalme/[email protected] | ||
if: github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' | ||
with: | ||
reports: 'coverage/**/coverage.cobertura.xml' | ||
targetdir: 'CoverageReports' | ||
reporttypes: 'Html' | ||
|
||
- name: Upload coverage reports | ||
uses: actions/upload-artifact@v4 | ||
if: github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' | ||
with: | ||
name: CoverageReports | ||
path: CoverageReports | ||
|
||
- name: Write to Job Summary | ||
shell: bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Dfe.EarlyYearsQualification.Content/Entities/CheckAdditionalRequirementsPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Dfe.EarlyYearsQualification.Content.Entities; | ||
|
||
public class CheckAdditionalRequirementsPage | ||
{ | ||
public string Heading { get; init; } = string.Empty; | ||
|
||
public NavigationLink? BackButton { get; init; } | ||
|
||
public string QualificationLabel { get; init; } = string.Empty; | ||
|
||
public string QualificationLevelLabel { get; init; } = string.Empty; | ||
|
||
public string AwardingOrganisationLabel { get; init; } = string.Empty; | ||
|
||
public string InformationMessage { get; init; } = string.Empty; | ||
|
||
public string CtaButtonText { get; init; } = string.Empty; | ||
|
||
public string QuestionSectionHeading { get; init; } = string.Empty; | ||
|
||
public string ErrorMessage { get; init; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Dfe.EarlyYearsQualification.Web/Attributes/AnswerValidationAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Dfe.EarlyYearsQualification.Web.Attributes; | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | ||
public class AnswerValidationAttribute : ValidationAttribute | ||
{ | ||
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) | ||
{ | ||
if (value is not Dictionary<string, string> dictionary) | ||
{ | ||
return new ValidationResult("Object is not of type Dictionary<string, string>()"); | ||
} | ||
|
||
if (dictionary.Count == 0) | ||
{ | ||
return new ValidationResult("Answers are required"); | ||
} | ||
|
||
foreach (var keyValuePair in dictionary.Where(keyValuePair => string.IsNullOrEmpty(keyValuePair.Value))) | ||
{ | ||
return new ValidationResult($"Value is required for key: {keyValuePair.Key}"); | ||
} | ||
|
||
return ValidationResult.Success; | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/Dfe.EarlyYearsQualification.Web/Controllers/CheckAdditionalRequirementsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using Dfe.EarlyYearsQualification.Content.Entities; | ||
using Dfe.EarlyYearsQualification.Content.Renderers.Entities; | ||
using Dfe.EarlyYearsQualification.Content.Services; | ||
using Dfe.EarlyYearsQualification.Web.Controllers.Base; | ||
using Dfe.EarlyYearsQualification.Web.Models.Content; | ||
using Dfe.EarlyYearsQualification.Web.Models.Content.QuestionModels; | ||
using Dfe.EarlyYearsQualification.Web.Services.UserJourneyCookieService; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Dfe.EarlyYearsQualification.Web.Controllers; | ||
|
||
[Route("qualifications/check-additional-questions")] | ||
public class CheckAdditionalRequirementsController( | ||
ILogger<CheckAdditionalRequirementsController> logger, | ||
IContentService contentService, | ||
IHtmlRenderer htmlRenderer, | ||
IUserJourneyCookieService userJourneyCookieService) | ||
: ServiceController | ||
{ | ||
[HttpGet("{qualificationId}")] | ||
public async Task<IActionResult> Index(string qualificationId) | ||
{ | ||
if (ModelState.IsValid) return await GetResponse(qualificationId); | ||
|
||
logger.LogError("No qualificationId passed in"); | ||
return RedirectToAction("Index", "Error"); | ||
|
||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Post([FromForm]CheckAdditionalRequirementsPageModel model) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
userJourneyCookieService.SetAdditionalQuestionsAnswers(model.Answers); | ||
return RedirectToAction("Index", "QualificationDetails", | ||
new { model.QualificationId }); | ||
} | ||
|
||
model.HasErrors = true; | ||
return await GetResponse(model.QualificationId, model); | ||
} | ||
|
||
private async Task<IActionResult> GetResponse(string qualificationId, | ||
CheckAdditionalRequirementsPageModel? model = null) | ||
{ | ||
var qualification = await contentService.GetQualificationById(qualificationId); | ||
if (qualification is null) | ||
{ | ||
var loggedQualificationId = qualificationId.Replace(Environment.NewLine, ""); | ||
logger.LogError("Could not find details for qualification with ID: {QualificationId}", | ||
loggedQualificationId); | ||
|
||
return RedirectToAction("Index", "Error"); | ||
} | ||
|
||
if (qualification.AdditionalRequirementQuestions is null || qualification.AdditionalRequirementQuestions.Count == 0) | ||
{ | ||
var loggedQualificationId = qualificationId.Replace(Environment.NewLine, ""); | ||
logger.LogInformation("QualificationId has no additional requirement questions: {QualificationId}", | ||
loggedQualificationId); | ||
return RedirectToAction("Index", "QualificationDetails", | ||
new { qualificationId }); | ||
} | ||
|
||
var content = await contentService.GetCheckAdditionalRequirementsPage(); | ||
if (content is null) | ||
{ | ||
logger.LogError("No content for the check additional requirements page"); | ||
return RedirectToAction("Index", "Error"); | ||
} | ||
|
||
var mappedModel = await MapModel(content, qualification, model); | ||
|
||
return View("Index", mappedModel); | ||
} | ||
|
||
private async Task<CheckAdditionalRequirementsPageModel> MapModel(CheckAdditionalRequirementsPage content, Qualification qualification, | ||
CheckAdditionalRequirementsPageModel? model = null) | ||
{ | ||
var mappedModel = model ?? new CheckAdditionalRequirementsPageModel(); | ||
mappedModel.QualificationId = qualification.QualificationId; | ||
mappedModel.AwardingOrganisation = qualification.AwardingOrganisationTitle; | ||
mappedModel.AwardingOrganisationLabel = content.AwardingOrganisationLabel; | ||
mappedModel.CtaButtonText = content.CtaButtonText; | ||
mappedModel.QualificationLevel = qualification.QualificationLevel; | ||
mappedModel.QualificationLabel = content.QualificationLabel; | ||
mappedModel.QualificationName = qualification.QualificationName; | ||
mappedModel.Heading = content.Heading; | ||
mappedModel.InformationMessage = content.InformationMessage; | ||
mappedModel.QualificationLevelLabel = content.QualificationLevelLabel; | ||
mappedModel.QuestionSectionHeading = content.QuestionSectionHeading; | ||
mappedModel.BackButton = content.BackButton; | ||
mappedModel.AdditionalRequirementQuestions = | ||
await MapAdditionalRequirementQuestions(qualification.AdditionalRequirementQuestions!); | ||
mappedModel.Answers = MapQuestionsToDictionary(qualification.AdditionalRequirementQuestions!); | ||
mappedModel.ErrorMessage = content.ErrorMessage; | ||
return mappedModel; | ||
} | ||
|
||
private async Task<List<AdditionalRequirementQuestionModel>> MapAdditionalRequirementQuestions(List<AdditionalRequirementQuestion> additionalRequirementQuestions) | ||
{ | ||
var results = new List<AdditionalRequirementQuestionModel>(); | ||
|
||
foreach (var additionalRequirementQuestion in additionalRequirementQuestions) | ||
{ | ||
results.Add(new AdditionalRequirementQuestionModel | ||
{ | ||
Question = additionalRequirementQuestion.Question, | ||
HintText = additionalRequirementQuestion.HintText, | ||
DetailsHeading = additionalRequirementQuestion.DetailsHeading, | ||
DetailsContent = await htmlRenderer.ToHtml(additionalRequirementQuestion.DetailsContent), | ||
Options = MapOptions(additionalRequirementQuestion.Answers) | ||
}); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
private static List<OptionModel> MapOptions(List<Option> options) | ||
{ | ||
return options.Select(option => new OptionModel { Label = option.Label, Value = option.Value }).ToList(); | ||
} | ||
|
||
private static Dictionary<string, string> MapQuestionsToDictionary(List<AdditionalRequirementQuestion> additionalRequirementQuestions) | ||
{ | ||
return additionalRequirementQuestions.ToDictionary(additionalRequirementQuestion => additionalRequirementQuestion.Question, additionalRequirementQuestion => string.Empty); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.