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/general-tidy-up #230

Merged
merged 9 commits into from
Jul 4, 2024
427 changes: 221 additions & 206 deletions content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace Dfe.EarlyYearsQualification.Content.Constants;

public static class QuestionPages
{

//// Radio Button Pages

/// <summary>
Expand All @@ -21,7 +20,7 @@ public static class QuestionPages
/// Entry ID for the "When was the qualification started" question page.
/// </summary>
public const string WhenWasTheQualificationStarted = "2o331MBr0R6nsZNBem4yvk";

//// Dropdown Pages

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class AccessibilityStatementPage
public string Heading { get; init; } = string.Empty;

public Document? Body { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class AdvicePage
public string Heading { get; init; } = string.Empty;

public Document? Body { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class CookiesPage
public Document? SuccessBannerContent { get; init; }

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

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class DateQuestionPage
public string MonthLabel { get; init; } = string.Empty;

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

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class DetailsPage
public string FurtherInfoHeading { get; init; } = string.Empty;

public Document? FurtherInfoText { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class DropdownQuestionPage
public string NotInListText { get; init; } = string.Empty;

public string DefaultText { get; init; } = string.Empty;
public NavigationLink? BackButton { get; set; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Dfe.EarlyYearsQualification.Content.Entities;

public class QualificationListPage
{
public string Header { get; set; } = string.Empty;
public NavigationLink? BackButton { get; set; }
public string Header { get; init; } = string.Empty;

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class RadioQuestionPage
public string AdditionalInformationHeader { get; init; } = string.Empty;

public Document? AdditionalInformationBody { get; init; }

public NavigationLink? BackButton { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private readonly Dictionary<object, string> _contentTypes
{ typeof(Qualification), ContentTypes.Qualification },
{ typeof(DetailsPage), ContentTypes.DetailsPage },
{ typeof(AdvicePage), ContentTypes.AdvicePage },
{ typeof(RadioQuestionPage), ContentTypes.RadioQuestionPage},
{ typeof(RadioQuestionPage), ContentTypes.RadioQuestionPage },
{ typeof(AccessibilityStatementPage), ContentTypes.AccessibilityStatementPage },
{ typeof(NavigationLinks), ContentTypes.NavigationLinks },
{ typeof(CookiesPage), ContentTypes.CookiesPage },
Expand All @@ -29,12 +29,14 @@ private readonly Dictionary<object, string> _contentTypes
{ typeof(DateQuestionPage), ContentTypes.DateQuestionPage },
{ typeof(DropdownQuestionPage), ContentTypes.DropdownQuestionPage },
{ typeof(QualificationListPage), ContentTypes.QualificationListPage },
{ typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage},
{ typeof(ConfirmQualificationPage), ContentTypes.ConfirmQualificationPage }
};

public async Task<StartPage?> GetStartPage()
{
var startPageEntries = await GetEntriesByType<StartPage>();

// ReSharper disable once InvertIf
if (startPageEntries is null || !startPageEntries.Any())
{
logger.LogWarning("No start page entry returned");
Expand All @@ -60,6 +62,8 @@ private readonly Dictionary<object, string> _contentTypes
public async Task<AccessibilityStatementPage?> GetAccessibilityStatementPage()
{
var accessibilityStatementEntities = await GetEntriesByType<AccessibilityStatementPage>();

// ReSharper disable once InvertIf
if (accessibilityStatementEntities is null || !accessibilityStatementEntities.Any())
{
logger.LogWarning("No accessibility statement page entry returned");
Expand Down Expand Up @@ -116,6 +120,8 @@ public async Task<List<NavigationLink>> GetNavigationLinks()
public async Task<AdvicePage?> GetAdvicePage(string entryId)
{
var advicePage = await GetEntryById<AdvicePage>(entryId);

// ReSharper disable once InvertIf
if (advicePage is null)
{
logger.LogWarning("Advice page with {EntryID} could not be found", entryId);
Expand Down Expand Up @@ -143,6 +149,8 @@ public async Task<List<NavigationLink>> GetNavigationLinks()
public async Task<PhaseBanner?> GetPhaseBannerContent()
{
var phaseBannerEntities = await GetEntriesByType<PhaseBanner>();

// ReSharper disable once InvertIf
if (phaseBannerEntities is null || !phaseBannerEntities.Any())
{
logger.LogWarning("No phase banner entry returned");
Expand All @@ -155,6 +163,8 @@ public async Task<List<NavigationLink>> GetNavigationLinks()
public async Task<CookiesBanner?> GetCookiesBannerContent()
{
var cookiesBannerEntry = await GetEntriesByType<CookiesBanner>();

// ReSharper disable once InvertIf
if (cookiesBannerEntry is null || !cookiesBannerEntry.Any())
{
logger.LogWarning("No cookies banner entry returned");
Expand All @@ -173,6 +183,8 @@ public async Task<List<Qualification>> GetQualifications()
public async Task<ConfirmQualificationPage?> GetConfirmQualificationPage()
{
var confirmQualificationEntities = await GetEntriesByType<ConfirmQualificationPage>();

// ReSharper disable once InvertIf
if (confirmQualificationEntities is null || !confirmQualificationEntities.Any())
{
logger.LogWarning("No confirm qualification page entry returned");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@ public class MockContentfulFilterService : IContentFilterService
{
public Task<List<Qualification>> GetFilteredQualifications(int? level, int? startDateMonth, int? startDateYear)
{
var qualifications = new List<Qualification>
{
CreateQualification("EYQ-100", "CACHE", 2, null, "Aug-19"),
CreateQualification("EYQ-101", "NCFE", 2, "Sep-14", "Aug-19"),
CreateQualification("EYQ-102", "Pearson", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-103", "NCFE", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-104", "City & Guilds", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-105", "Montessori Centre International", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-106", "Various Awarding Organisations", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-107", "Edexcel (now Pearson Education Ltd)", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-108", "Kent Sussex Montessori Centre", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-109", "NNEB National Nursery Examination Board", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-110", "Various Awarding Organisations", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-111", "City & Guilds", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-112", "Pearson", 8, "Sep-14", "Aug-19"),
CreateQualification("EYQ-113", "CACHE", 8, "Sep-14", "Aug-19")
};
var qualifications =
new List<Qualification>
{
CreateQualification("EYQ-100", "CACHE", 2, null, "Aug-19"),
CreateQualification("EYQ-101", "NCFE", 2, "Sep-14", "Aug-19"),
CreateQualification("EYQ-102", "Pearson", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-103", "NCFE", 3, "Sep-14", "Aug-19"),
CreateQualification("EYQ-104", "City & Guilds", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-105", "Montessori Centre International", 4, "Sep-14", "Aug-19"),
CreateQualification("EYQ-106", "Various Awarding Organisations", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-107", "Edexcel (now Pearson Education Ltd)", 5, "Sep-14", "Aug-19"),
CreateQualification("EYQ-108", "Kent Sussex Montessori Centre", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-109", "NNEB National Nursery Examination Board", 6, "Sep-14", "Aug-19"),
CreateQualification("EYQ-110", "Various Awarding Organisations", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-111", "City & Guilds", 7, "Sep-14", "Aug-19"),
CreateQualification("EYQ-112", "Pearson", 8, "Sep-14", "Aug-19"),
CreateQualification("EYQ-113", "CACHE", 8, "Sep-14", "Aug-19")
};

return Task.FromResult(qualifications.Where(x => x.QualificationLevel == level).ToList());
}

private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level, string? startDate, string endDate)
private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level,
string? startDate, string endDate)
{
return new Qualification(
qualificationId,
return new Qualification(qualificationId,
$"{qualificationId}-test",
awardingOrganisation,
level,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,37 +218,37 @@ public Task<List<Qualification>> GetQualifications()
public async Task<ConfirmQualificationPage?> GetConfirmQualificationPage()
{
return await Task.FromResult(new ConfirmQualificationPage
{
QualificationLabel = "Test qualification label",
BackButton = new NavigationLink
{
DisplayText = "Test back button",
OpenInNewTab = false,
Href = "/qualifications"
},
ErrorText = "Test error text",
ButtonText = "Test button text",
LevelLabel = "Test level label",
DateAddedLabel = "Test date added label",
Heading = "Test heading",
Options =
[
new Option
{
Label = "yes",
Value = "yes"
},
new Option
{
Label = "no",
Value = "no"
}
],
RadioHeading = "Test radio heading",
AwardingOrganisationLabel = "Test awarding organisation label",
ErrorBannerHeading = "Test error banner heading",
ErrorBannerLink = "Test error banner link"
});
{
QualificationLabel = "Test qualification label",
BackButton = new NavigationLink
{
DisplayText = "Test back button",
OpenInNewTab = false,
Href = "/qualifications"
},
ErrorText = "Test error text",
ButtonText = "Test button text",
LevelLabel = "Test level label",
DateAddedLabel = "Test date added label",
Heading = "Test heading",
Options =
[
new Option
{
Label = "yes",
Value = "yes"
},
new Option
{
Label = "no",
Value = "no"
}
],
RadioHeading = "Test radio heading",
AwardingOrganisationLabel = "Test awarding organisation label",
ErrorBannerHeading = "Test error banner heading",
ErrorBannerLink = "Test error banner link"
});
}

public async Task<StartPage?> GetStartPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private async Task<AccessibilityStatementPageModel> Map(AccessibilityStatementPa
{
Heading = content.Heading,
BodyContent = await renderer.ToHtml(content.Body),
BackButton = content.BackButton,
BackButton = content.BackButton
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task<IActionResult> Index(string qualificationId)
{
return BadRequest();
}

var content = await contentService.GetConfirmQualificationPage();

if (content is null)
Expand All @@ -48,41 +48,44 @@ public async Task<IActionResult> Index(string qualificationId)
[HttpPost]
public async Task<IActionResult> Confirm(ConfirmQualificationPageModel model)
{
if (!ModelState.IsValid)
if (ModelState.IsValid)
{
return model.ConfirmQualificationAnswer == "yes"
? RedirectToAction("Index", "QualificationDetails",
new { qualificationId = model.QualificationId })
: RedirectToAction("Get", "QualificationDetails");
}

var content = await contentService.GetConfirmQualificationPage();

if (content is null)
{
logger.LogError("No content for the cookies page");
return RedirectToAction("Index", "Error");
}

if (string.IsNullOrEmpty(model.QualificationId))
{
var content = await contentService.GetConfirmQualificationPage();

if (content is null)
{
logger.LogError("No content for the cookies page");
return RedirectToAction("Index", "Error");
}

if (string.IsNullOrEmpty(model.QualificationId))
{
logger.LogError("No qualification id provided");
return RedirectToAction("Index", "Error");
}

var qualification = await contentService.GetQualificationById(model.QualificationId);
if (qualification is null)
{
var loggedQualificationId = model.QualificationId.Replace(Environment.NewLine, "");
logger.LogError("Could not find details for qualification with ID: {QualificationId}",
loggedQualificationId);

return RedirectToAction("Index", "Error");
}

model = Map(content, qualification);
model.HasErrors = true;

return View("Index", model);
logger.LogError("No qualification id provided");
return RedirectToAction("Index", "Error");
}

var qualification = await contentService.GetQualificationById(model.QualificationId);
if (qualification is null)
{
var loggedQualificationId = model.QualificationId.Replace(Environment.NewLine, "");
logger.LogError("Could not find details for qualification with ID: {QualificationId}",
loggedQualificationId);

return RedirectToAction("Index", "Error");
}

return model.ConfirmQualificationAnswer == "yes" ? RedirectToAction("Index", "QualificationDetails", new { qualificationId = model.QualificationId }) : RedirectToAction("Get", "QualificationDetails");

model = Map(content, qualification);
model.HasErrors = true;

return View("Index", model);
}

private static ConfirmQualificationPageModel Map(ConfirmQualificationPage content, Qualification qualification)
{
return new ConfirmQualificationPageModel
Expand All @@ -104,7 +107,7 @@ private static ConfirmQualificationPageModel Map(ConfirmQualificationPage conten
QualificationId = qualification.QualificationId,
QualificationAwardingOrganisation = qualification.AwardingOrganisationTitle,
QualificationDateAdded = qualification.FromWhichYear!,
BackButton = content.BackButton,
BackButton = content.BackButton
};
}
}
Loading
Loading