-
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.
Add outbox messages for updating induction status
- Loading branch information
Showing
7 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...chingRecordSystem.Core/Services/DqtOutbox/Handlers/AddInductionExemptionMessageHandler.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,29 @@ | ||
using TeachingRecordSystem.Core.DataStore.Postgres; | ||
using TeachingRecordSystem.Core.Services.DqtOutbox.Messages; | ||
|
||
namespace TeachingRecordSystem.Core.Services.DqtOutbox.Handlers; | ||
|
||
public class AddInductionExemptionMessageHandler(TrsDbContext dbContext, IClock clock) : IMessageHandler<AddInductionExemptionMessage> | ||
{ | ||
public async Task HandleMessageAsync(AddInductionExemptionMessage message) | ||
{ | ||
var person = await dbContext.Persons.SingleAsync(p => p.PersonId == message.PersonId); | ||
|
||
var updatedBy = message.DqtUserId is not null && message.DqtUserName is not null | ||
? EventModels.RaisedByUserInfo.FromDqtUser(message.DqtUserId.Value, message.DqtUserName) | ||
: EventModels.RaisedByUserInfo.FromUserId(message.TrsUserId!.Value); | ||
|
||
person.AddInductionExemptionReason( | ||
message.ExemptionReasonId, | ||
updatedBy: updatedBy, | ||
now: clock.UtcNow, | ||
out var @event); | ||
|
||
if (@event is not null) | ||
{ | ||
await dbContext.AddEventAndBroadcastAsync(@event); | ||
} | ||
|
||
await dbContext.SaveChangesAsync(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rdSystem.Core/Services/DqtOutbox/Handlers/SetInductionRequiredToCompleteMessageHandler.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,40 @@ | ||
using TeachingRecordSystem.Core.DataStore.Postgres; | ||
using TeachingRecordSystem.Core.Services.DqtOutbox.Messages; | ||
|
||
namespace TeachingRecordSystem.Core.Services.DqtOutbox.Handlers; | ||
|
||
public class SetInductionRequiredToCompleteMessageHandler(TrsDbContext dbContext, IClock clock) : IMessageHandler<SetInductionRequiredToCompleteMessage> | ||
{ | ||
public async Task HandleMessageAsync(SetInductionRequiredToCompleteMessage message) | ||
{ | ||
var person = await dbContext.Persons.SingleAsync(p => p.PersonId == message.PersonId); | ||
|
||
if (!InductionStatus.RequiredToComplete.IsHigherPriorityThan(person.InductionStatus)) | ||
{ | ||
return; | ||
} | ||
|
||
var updatedBy = message.DqtUserId is not null && message.DqtUserName is not null | ||
? EventModels.RaisedByUserInfo.FromDqtUser(message.DqtUserId.Value, message.DqtUserName) | ||
: EventModels.RaisedByUserInfo.FromUserId(message.TrsUserId!.Value); | ||
|
||
person.SetInductionStatus( | ||
InductionStatus.RequiredToComplete, | ||
startDate: null, | ||
completedDate: null, | ||
exemptionReasonIds: [], | ||
changeReason: null, | ||
changeReasonDetail: null, | ||
evidenceFile: null, | ||
updatedBy: updatedBy, | ||
now: clock.UtcNow, | ||
out var @event); | ||
|
||
if (@event is not null) | ||
{ | ||
await dbContext.AddEventAndBroadcastAsync(@event); | ||
} | ||
|
||
await dbContext.SaveChangesAsync(); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...src/TeachingRecordSystem.Core/Services/DqtOutbox/Messages/AddInductionExemptionMessage.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,10 @@ | ||
namespace TeachingRecordSystem.Core.Services.DqtOutbox.Messages; | ||
|
||
public record AddInductionExemptionMessage | ||
{ | ||
public required Guid PersonId { get; init; } | ||
public required Guid ExemptionReasonId { get; init; } | ||
public Guid? TrsUserId { get; init; } | ||
public Guid? DqtUserId { get; init; } | ||
public string? DqtUserName { get; init; } | ||
} |
9 changes: 9 additions & 0 deletions
9
...ingRecordSystem.Core/Services/DqtOutbox/Messages/SetInductionRequiredToCompleteMessage.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,9 @@ | ||
namespace TeachingRecordSystem.Core.Services.DqtOutbox.Messages; | ||
|
||
public record SetInductionRequiredToCompleteMessage | ||
{ | ||
public required Guid PersonId { get; init; } | ||
public Guid? TrsUserId { get; init; } | ||
public Guid? DqtUserId { get; init; } | ||
public string? DqtUserName { 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