-
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 induction-journey
- Loading branch information
Showing
11 changed files
with
568 additions
and
16 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
78 changes: 78 additions & 0 deletions
78
...stem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetWelshInductionStatus.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,78 @@ | ||
using System.Diagnostics; | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Api.Infrastructure.Security; | ||
using TeachingRecordSystem.Core.DataStore.Postgres; | ||
using TeachingRecordSystem.Core.DataStore.Postgres.Models; | ||
using TeachingRecordSystem.Core.Dqt; | ||
using TeachingRecordSystem.Core.Dqt.Models; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
using TeachingRecordSystem.Core.Services.TrsDataSync; | ||
|
||
namespace TeachingRecordSystem.Api.V3.Implementation.Operations; | ||
|
||
public record SetWelshInductionStatusCommand(string Trn, bool Passed, DateOnly StartDate, DateOnly CompletedDate); | ||
|
||
public record SetWelshInductionStatusResult; | ||
|
||
public class SetWelshInductionStatusHandler( | ||
TrsDbContext dbContext, | ||
ICrmQueryDispatcher crmQueryDispatcher, | ||
TrsDataSyncHelper syncHelper, | ||
ICurrentUserProvider currentUserProvider, | ||
IClock clock) | ||
{ | ||
public async Task<ApiResult<SetWelshInductionStatusResult>> HandleAsync(SetWelshInductionStatusCommand command) | ||
{ | ||
var dqtContact = await crmQueryDispatcher.ExecuteQueryAsync( | ||
new GetActiveContactByTrnQuery(command.Trn, new ColumnSet(Contact.Fields.dfeta_QTSDate))); | ||
|
||
if (dqtContact is null) | ||
{ | ||
return ApiError.PersonNotFound(command.Trn); | ||
} | ||
|
||
if (dqtContact.dfeta_QTSDate is null) | ||
{ | ||
return ApiError.PersonDoesNotHaveQts(command.Trn); | ||
} | ||
|
||
await using var txn = await dbContext.Database.BeginTransactionAsync(System.Data.IsolationLevel.ReadCommitted); | ||
|
||
var person = await GetPersonAsync(); | ||
|
||
if (person is null) | ||
{ | ||
// The person record hasn't synced to TRS yet - force that to happen so we can assign induction status | ||
var synced = await syncHelper.SyncPersonAsync(dqtContact.Id); | ||
if (!synced) | ||
{ | ||
throw new Exception($"Could not sync Person with contact ID: '{dqtContact.Id}'."); | ||
} | ||
|
||
person = await GetPersonAsync(); | ||
Debug.Assert(person is not null); | ||
} | ||
|
||
var (currentUserId, _) = currentUserProvider.GetCurrentApplicationUser(); | ||
|
||
person.TrySetWelshInductionStatus( | ||
command.Passed, | ||
!command.Passed ? command.StartDate : null, | ||
!command.Passed ? command.CompletedDate : null, | ||
currentUserId, | ||
clock.UtcNow, | ||
out var updatedEvent); | ||
|
||
if (updatedEvent is not null) | ||
{ | ||
dbContext.AddEvent(updatedEvent); | ||
} | ||
|
||
await dbContext.SaveChangesAsync(); | ||
await txn.CommitAsync(); | ||
|
||
return new SetWelshInductionStatusResult(); | ||
|
||
Task<Person?> GetPersonAsync() => dbContext.Persons.SingleOrDefaultAsync(p => p.Trn == command.Trn); | ||
} | ||
} |
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
...rdSystem/src/TeachingRecordSystem.Api/V3/VNext/Requests/SetWelshInductionStatusRequest.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 @@ | ||
namespace TeachingRecordSystem.Api.V3.VNext.Requests; | ||
|
||
public record SetWelshInductionStatusRequest | ||
{ | ||
public required bool Passed { get; init; } | ||
public required DateOnly StartDate { get; init; } | ||
public required DateOnly CompletedDate { get; init; } | ||
} |
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
8 changes: 0 additions & 8 deletions
8
TeachingRecordSystem/src/TeachingRecordSystem.Core/Models/InductionExemptionReason.cs
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
TeachingRecordSystem/src/TeachingRecordSystem.Core/Models/InductionExemptionReasons.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,24 @@ | ||
namespace TeachingRecordSystem.Core.Models; | ||
|
||
[Flags] | ||
public enum InductionExemptionReasons | ||
{ | ||
None = 0, | ||
QualifiedBefore07052000 = 1 << 0, | ||
QualifiedBetween07051999And01042003FirstPostWasInWalesAndLastedAMinimumOfTwoTerms = 1 << 1, | ||
QualifiedThroughFurtherEducationRouteBetween01092001And01092004 = 1 << 2, | ||
PassedInductionInGuernsey = 1 << 3, | ||
PassedInductionInIsleOfMan = 1 << 4, | ||
PassedInductionInJersey = 1 << 5, | ||
PassedInductionInNorthernIreland = 1 << 6, | ||
PassedInductionInServiceChildrensEducationSchoolsInGermanyOrCyprus = 1 << 7, | ||
PassedInductionInWales = 1 << 8, | ||
PassedProbationaryPeriodInGibraltar = 1 << 9, | ||
Exempt = 1 << 10, | ||
ExemptDataLossOrErrorCriteria = 1 << 11, | ||
HasOrIsEligibleForFullRegistrationInScotland = 1 << 12, | ||
OverseasTrainedTeacher = 1 << 13, | ||
QualifiedThroughEeaMutualRecognitionRoute = 1 << 14, | ||
RegisteredTeacherWithAtLeast2YearsFullTimeTeachingExperience = 1 << 15, | ||
ExemptThroughQtlsProvidedTheyMaintainMembershipOfTheSocietyOfEducationAndTraining = 1 << 16, | ||
} |
Oops, something went wrong.