-
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 fix/contentful-table-renderer
- Loading branch information
Showing
34 changed files
with
1,805 additions
and
90 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/Dfe.EarlyYearsQualification.Content/Constants/ContentTypes.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,19 @@ | ||
namespace Dfe.EarlyYearsQualification.Content.Constants; | ||
|
||
public static class ContentTypes | ||
{ | ||
public const string StartPage = "startPage"; | ||
public const string Qualification = "Qualification"; | ||
public const string DetailsPage = "detailsPage"; | ||
public const string AdvicePage = "advicePage"; | ||
public const string RadioQuestionPage = "radioQuestionPage"; | ||
public const string AccessibilityStatementPage = "accessibilityStatementPage"; | ||
public const string NavigationLinks = "navigationLinks"; | ||
public const string CookiesPage = "cookiesPage"; | ||
public const string PhaseBanner = "phaseBanner"; | ||
public const string CookiesBanner = "cookiesBanner"; | ||
public const string DateQuestionPage = "dateQuestionPage"; | ||
public const string DropdownQuestionPage = "dropdownQuestionPage"; | ||
public const string QualificationListPage = "qualificationListPage"; | ||
public const string ConfirmQualificationPage = "confirmQualificationPage"; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Dfe.EarlyYearsQualification.Content/Entities/ConfirmQualificationPage.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,17 @@ | ||
namespace Dfe.EarlyYearsQualification.Content.Entities; | ||
|
||
public class ConfirmQualificationPage | ||
{ | ||
public string Heading { get; init; } = string.Empty; | ||
public string QualificationLabel { get; init; } = string.Empty; | ||
public string LevelLabel { get; init; } = string.Empty; | ||
public string AwardingOrganisationLabel { get; init; } = string.Empty; | ||
public string DateAddedLabel { get; init; } = string.Empty; | ||
public string RadioHeading { get; init; } = string.Empty; | ||
public List<Option> Options { get; init; } = []; | ||
public string ErrorBannerHeading { get; init; } = string.Empty; | ||
public string ErrorBannerLink { get; init; } = string.Empty; | ||
public string ErrorText { get; init; } = string.Empty; | ||
public string ButtonText { get; init; } = string.Empty; | ||
public NavigationLink? BackButton { get; init; } | ||
} |
135 changes: 135 additions & 0 deletions
135
src/Dfe.EarlyYearsQualification.Content/Services/ContentfulContentFilterService.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,135 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Globalization; | ||
using Contentful.Core; | ||
using Contentful.Core.Models; | ||
using Contentful.Core.Search; | ||
using Dfe.EarlyYearsQualification.Content.Constants; | ||
using Dfe.EarlyYearsQualification.Content.Entities; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Dfe.EarlyYearsQualification.Content.Services; | ||
|
||
public class ContentfulContentFilterService( | ||
IContentfulClient contentfulClient, | ||
ILogger<ContentfulContentFilterService> logger) | ||
: IContentFilterService | ||
{ | ||
private const int Day = 28; | ||
private static readonly DateTimeFormatInfo CurrentFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat; | ||
|
||
private readonly ReadOnlyDictionary<int, string> | ||
_months = new( | ||
new Dictionary<int, string> | ||
{ | ||
{ 1, CurrentFormatInfo.AbbreviatedMonthNames[0] }, | ||
{ 2, CurrentFormatInfo.AbbreviatedMonthNames[1] }, | ||
{ 3, CurrentFormatInfo.AbbreviatedMonthNames[2] }, | ||
{ 4, CurrentFormatInfo.AbbreviatedMonthNames[3] }, | ||
{ 5, CurrentFormatInfo.AbbreviatedMonthNames[4] }, | ||
{ 6, CurrentFormatInfo.AbbreviatedMonthNames[5] }, | ||
{ 7, CurrentFormatInfo.AbbreviatedMonthNames[6] }, | ||
{ 8, CurrentFormatInfo.AbbreviatedMonthNames[7] }, | ||
{ 9, CurrentFormatInfo.AbbreviatedMonthNames[8] }, | ||
{ 10, CurrentFormatInfo.AbbreviatedMonthNames[9] }, | ||
{ 11, CurrentFormatInfo.AbbreviatedMonthNames[10] }, | ||
{ 12, CurrentFormatInfo.AbbreviatedMonthNames[11] } | ||
}); | ||
|
||
// Used by the unit tests to inject a mock builder that returns the query params | ||
public QueryBuilder<Qualification> QueryBuilder { get; init; } = QueryBuilder<Qualification>.New; | ||
|
||
public async Task<List<Qualification>> GetFilteredQualifications(int? level, int? startDateMonth, | ||
int? startDateYear) | ||
{ | ||
logger.LogInformation("Filtering options passed in - level: {Level}, startDateMonth: {StartDateMonth}, startDateYear: {StartDateYear}", | ||
level, | ||
startDateMonth, | ||
startDateYear); | ||
|
||
// create query builder | ||
var queryBuilder = QueryBuilder.ContentTypeIs(ContentTypes.Qualification); | ||
|
||
if (level is > 0) | ||
{ | ||
queryBuilder = queryBuilder.FieldEquals("fields.qualificationLevel", level.Value.ToString()); | ||
} | ||
|
||
// get qualifications | ||
ContentfulCollection<Qualification>? qualifications; | ||
try | ||
{ | ||
qualifications = await contentfulClient.GetEntries(queryBuilder); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError(e, "Error getting qualifications"); | ||
return []; | ||
} | ||
|
||
if (!startDateMonth.HasValue || !startDateYear.HasValue) return qualifications.ToList(); | ||
|
||
// apply start date filtering | ||
var results = FilterQualificationsByDate(startDateMonth.Value, startDateYear.Value, qualifications); | ||
|
||
return results; | ||
} | ||
|
||
private List<Qualification> FilterQualificationsByDate(int startDateMonth, int startDateYear, | ||
ContentfulCollection<Qualification> qualifications) | ||
{ | ||
var results = new List<Qualification>(); | ||
var enteredStartDate = new DateOnly(startDateYear, startDateMonth, Day); | ||
foreach (var qualification in qualifications) | ||
{ | ||
var qualificationStartDate = GetQualificationDate(qualification.FromWhichYear); | ||
var qualificationEndDate = GetQualificationDate(qualification.ToWhichYear); | ||
|
||
if (qualificationStartDate is not null | ||
&& qualificationEndDate is not null | ||
&& enteredStartDate >= qualificationStartDate | ||
&& enteredStartDate <= qualificationEndDate) | ||
{ | ||
// check start date falls between those dates & add to results | ||
results.Add(qualification); | ||
} | ||
else if (qualificationStartDate is null | ||
&& qualificationEndDate is not null | ||
&& enteredStartDate <= qualificationEndDate) | ||
{ | ||
// if qualification start date is null, check entered start date is <= ToWhichYear & add to results | ||
results.Add(qualification); | ||
} | ||
else | ||
{ | ||
// if qualification end date is null, check entered start date is >= FromWhichYear & add to results | ||
if (enteredStartDate >= qualificationStartDate) | ||
{ | ||
results.Add(qualification); | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
private DateOnly? GetQualificationDate(string? qualificationDate) | ||
{ | ||
if (string.IsNullOrEmpty(qualificationDate) || qualificationDate == "null") | ||
{ | ||
return null; | ||
} | ||
|
||
return ConvertToDateTime(qualificationDate); | ||
} | ||
|
||
private DateOnly? ConvertToDateTime(string qualificationDate) | ||
{ | ||
var splitQualificationDate = qualificationDate.Split('-'); | ||
if (splitQualificationDate.Length != 2) return null; | ||
|
||
var month = _months.FirstOrDefault(x => x.Value == splitQualificationDate[0]).Key; | ||
var year = Convert.ToInt32(splitQualificationDate[1]) + 2000; | ||
|
||
return new DateOnly(year, month, Day); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/Dfe.EarlyYearsQualification.Content/Services/IContentFilterService.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,8 @@ | ||
using Dfe.EarlyYearsQualification.Content.Entities; | ||
|
||
namespace Dfe.EarlyYearsQualification.Content.Services; | ||
|
||
public interface IContentFilterService | ||
{ | ||
Task<List<Qualification>> GetFilteredQualifications(int? level, int? startDateMonth, int? startDateYear); | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulFilterService.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,43 @@ | ||
using Dfe.EarlyYearsQualification.Content.Entities; | ||
using Dfe.EarlyYearsQualification.Content.Services; | ||
|
||
namespace Dfe.EarlyYearsQualification.Mock.Content; | ||
|
||
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") | ||
}; | ||
|
||
return Task.FromResult(qualifications.Where(x => x.QualificationLevel == level).ToList()); | ||
} | ||
|
||
private static Qualification CreateQualification(string qualificationId, string awardingOrganisation, int level, string? startDate, string endDate) | ||
{ | ||
return new Qualification( | ||
qualificationId, | ||
$"{qualificationId}-test", | ||
awardingOrganisation, | ||
level, | ||
startDate, | ||
endDate, | ||
"ghi/456/951", | ||
"additional requirements"); | ||
} | ||
} |
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.