Skip to content

Commit

Permalink
Merge pull request #1326 from DFE-Digital/rtta-primary-support
Browse files Browse the repository at this point in the history
Add support for Primary education phase
  • Loading branch information
martyn-w authored Dec 7, 2023
2 parents 5e3fe16 + 14bf928 commit 0732742
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 23 deletions.
8 changes: 4 additions & 4 deletions GetIntoTeachingApi/Adapters/NotificationClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public Task SendEmailAsync(string apiKey, string email, string templateId, Dicti

private NotificationClient Client(string apiKey)
{
if (!_clients.ContainsKey(apiKey))
if (!_clients.TryGetValue(apiKey, out NotificationClient value))
{
_clients[apiKey] = new NotificationClient(apiKey);
value = new NotificationClient(apiKey);
_clients[apiKey] = value;
}

return _clients[apiKey];
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using FluentValidation.AspNetCore;
Expand Down Expand Up @@ -81,12 +82,12 @@ public async Task<IActionResult> Search(
var typeIds = request.TypeIds == null ? string.Empty : string.Join(",", request.TypeIds);

_metrics.TeachingEventSearchResults
.WithLabels(typeIds, request.Radius.ToString())
.WithLabels(typeIds, String.Format(CultureInfo.InvariantCulture, "{0}", request.Radius))
.Observe(teachingEvents.Count());

var inPesonTeachingEvents = teachingEvents.Where(e => e.IsInPerson);
_metrics.InPersonTeachingEventResults
.WithLabels(typeIds, request.Radius.ToString())
.WithLabels(typeIds, String.Format(CultureInfo.InvariantCulture, "{0}", request.Radius))
.Observe(inPesonTeachingEvents.Count());

return Ok(teachingEvents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CandidatePastTeachingPosition : BaseModel, IHasCandidateId
{
public enum EducationPhase
{
Primary = 222750000,
Secondary = 222750001,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum ResubscribableAdviserStatus
public int? DegreeStatusId { get; set; }
public int? DegreeTypeId { get; set; }
public int? InitialTeacherTrainingYearId { get; set; }
public int? StageTaughtId { get; set; }
public int? PreferredEducationPhaseId { get; set; }
public int? HasGcseMathsAndEnglishId { get; set; }
public int? HasGcseScienceId { get; set; }
Expand Down Expand Up @@ -115,7 +116,7 @@ private static bool CanSubscribe(Candidate candidate)

private static void DefaultPreferredEducationPhase(Candidate candidate)
{
if (candidate.IsReturningToTeaching())
if (candidate.IsReturningToTeaching() && candidate.PreferredEducationPhaseId == null)
{
candidate.PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Secondary;
}
Expand Down Expand Up @@ -323,14 +324,31 @@ private void AddQualification(Candidate candidate)

private void AddPastTeachingPosition(Candidate candidate)
{
if (ContainsPastTeachingPosition())
// NB: StageTaughtId is a new parameter and might not be set by older clients.
// NB: If the StageTaughtId==primary, SubjectTaughtId will be null
if (candidate.IsReturningToTeaching())
{
candidate.PastTeachingPositions.Add(new CandidatePastTeachingPosition()
if (StageTaughtId == (int)CandidatePastTeachingPosition.EducationPhase.Primary ||
SubjectTaughtId == TeachingSubject.PrimaryTeachingSubjectId)
{
Id = PastTeachingPositionId,
SubjectTaughtId = SubjectTaughtId,
EducationPhaseId = (int)CandidatePastTeachingPosition.EducationPhase.Secondary,
});
candidate.PastTeachingPositions.Add(new CandidatePastTeachingPosition()
{
Id = PastTeachingPositionId,
SubjectTaughtId = TeachingSubject.PrimaryTeachingSubjectId,
EducationPhaseId = (int)CandidatePastTeachingPosition.EducationPhase.Primary,
});
}
else if ((StageTaughtId == null ||
StageTaughtId == (int)CandidatePastTeachingPosition.EducationPhase.Secondary) &&
SubjectTaughtId != null)
{
candidate.PastTeachingPositions.Add(new CandidatePastTeachingPosition()
{
Id = PastTeachingPositionId,
SubjectTaughtId = SubjectTaughtId,
EducationPhaseId = (int)CandidatePastTeachingPosition.EducationPhase.Secondary,
});
}
}
}

Expand Down Expand Up @@ -360,10 +378,5 @@ private bool ContainsQualification()
{
return UkDegreeGradeId != null || DegreeStatusId != null || DegreeSubject != null || DegreeTypeId != null;
}

private bool ContainsPastTeachingPosition()
{
return SubjectTaughtId != null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,21 @@ public TeacherTrainingAdviserSignUpValidator(IStore store, IDateTimeProvider dat

When(request => request.Candidate.IsReturningToTeaching(), () =>
{
RuleFor(request => request.SubjectTaughtId).NotNull()
.WithMessage("Must be set for candidates returning to teacher training.");
RuleFor(request => request.PreferredTeachingSubjectId).NotNull()
.WithMessage("Must be set for candidates returning to teacher training.");
.When(request => request.Candidate.PreferredEducationPhaseId == (int)Candidate.PreferredEducationPhase.Secondary)
.WithMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary.");

RuleFor(request => request.PreferredTeachingSubjectId).NotNull()
.When(request => request.Candidate.PreferredEducationPhaseId == null)
.WithMessage("For candidates returning to teacher training, must be set when preferred education phase defaults to secondary.");

RuleFor(request => request.SubjectTaughtId).NotNull()
.When(request => request.StageTaughtId == null)
.WithMessage("For candidates returning to teacher training, must be set when stage taught defaults to secondary.");

RuleFor(request => request.SubjectTaughtId).NotNull()
.When(request => request.StageTaughtId == (int) CandidatePastTeachingPosition.EducationPhase.Secondary)
.WithMessage("For candidates returning to teacher training, must be set when stage taught is secondary.");
});

When(request => request.Candidate.IsInterestedInTeaching(), () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,80 @@ public void Validate_WhenRequiredAttributesAreNull_HasErrors()
var result = _validator.TestValidate(_request);

result.ShouldHaveValidationErrorFor(request => request.SubjectTaughtId)
.WithErrorMessage("Must be set for candidates returning to teacher training.");
.WithErrorMessage("For candidates returning to teacher training, must be set when stage taught defaults to secondary.");

result.ShouldHaveValidationErrorFor(request => request.PreferredTeachingSubjectId)
.WithErrorMessage("Must be set for candidates returning to teacher training.");
.WithErrorMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary.");
}

[Fact]
public void Validate_WhenPreferredEducationPhaseNullRequiredAttributesAreNull_HasErrors()
{
_request.PreferredEducationPhaseId = null;
_request.PreferredTeachingSubjectId = null;

var result = _validator.TestValidate(_request);

result.ShouldHaveValidationErrorFor(request => request.PreferredTeachingSubjectId)
.WithErrorMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary.");
}

[Fact]
public void Validate_WhenPreferredEducationPhasePrimaryRequiredAttributesAreNull_HasErrors()
{
_request.PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Primary;
_request.PreferredTeachingSubjectId = null;

var result = _validator.TestValidate(_request);

result.ShouldNotHaveValidationErrorFor(request => request.PreferredTeachingSubjectId);
}

[Fact]
public void Validate_WhenPreferredEducationPhaseSecondaryRequiredAttributesAreNull_HasErrors()
{
_request.PreferredEducationPhaseId = (int)Candidate.PreferredEducationPhase.Secondary;
_request.PreferredTeachingSubjectId = null;

var result = _validator.TestValidate(_request);

result.ShouldHaveValidationErrorFor(request => request.PreferredTeachingSubjectId)
.WithErrorMessage("For candidates returning to teacher training, must be set when preferred education phase is secondary.");
}

[Fact]
public void Validate_WhenStageTaughtNullRequiredAttributesAreNull_HasErrors()
{
_request.StageTaughtId = null;
_request.SubjectTaughtId = null;

var result = _validator.TestValidate(_request);

result.ShouldHaveValidationErrorFor(request => request.SubjectTaughtId)
.WithErrorMessage("For candidates returning to teacher training, must be set when stage taught defaults to secondary.");
}

[Fact]
public void Validate_WhenStageTaughtPrimaryRequiredAttributesAreNull_HasErrors()
{
_request.StageTaughtId = (int)CandidatePastTeachingPosition.EducationPhase.Primary;
_request.SubjectTaughtId = null;

var result = _validator.TestValidate(_request);

result.ShouldNotHaveValidationErrorFor(request => request.SubjectTaughtId);
}

[Fact]
public void Validate_WhenStageTaughtSecondaryRequiredAttributesAreNull_HasErrors()
{
_request.StageTaughtId = (int)CandidatePastTeachingPosition.EducationPhase.Secondary;
_request.SubjectTaughtId = null;

var result = _validator.TestValidate(_request);

result.ShouldHaveValidationErrorFor(request => request.SubjectTaughtId)
.WithErrorMessage("For candidates returning to teacher training, must be set when stage taught is secondary.");
}
}

Expand Down

0 comments on commit 0732742

Please sign in to comment.