-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from ministryofjustice/develop
Develop
- Loading branch information
Showing
26 changed files
with
3,254 additions
and
187 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
54 changes: 54 additions & 0 deletions
54
src/Application/Features/Participants/Commands/ConfirmEnrolment.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,54 @@ | ||
using Cfo.Cats.Application.Common.Security; | ||
using Cfo.Cats.Application.Common.Validators; | ||
using Cfo.Cats.Application.SecurityConstants; | ||
|
||
namespace Cfo.Cats.Application.Features.Participants.Commands; | ||
|
||
public static class ConfirmEnrolment | ||
{ | ||
[RequestAuthorize(Policy = SecurityPolicies.Enrol)] | ||
public class Command : IRequest<Result> | ||
{ | ||
public required string ParticipantId { get; set; } | ||
} | ||
|
||
class Handler(IUnitOfWork unitOfWork) : IRequestHandler<Command, Result> | ||
{ | ||
public async Task<Result> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
var participant = await unitOfWork.DbContext.Participants.FindAsync(request.ParticipantId); | ||
|
||
if(participant is null) | ||
{ | ||
return Result.Failure("Participant not found"); | ||
} | ||
|
||
participant.TransitionTo(EnrolmentStatus.EnrolmentConfirmedStatus); | ||
|
||
return Result.Success(); | ||
} | ||
} | ||
|
||
class Validator : AbstractValidator<Command> | ||
{ | ||
private readonly IUnitOfWork _unitOfWork; | ||
|
||
public Validator(IUnitOfWork unitOfWork) | ||
{ | ||
_unitOfWork = unitOfWork; | ||
|
||
RuleFor(c => c.ParticipantId) | ||
.NotNull() | ||
.Length(9) | ||
.WithMessage("Invalid Participant Id") | ||
.Matches(ValidationConstants.AlphaNumeric) | ||
.WithMessage(string.Format(ValidationConstants.AlphaNumericMessage, "Participant Id")) | ||
.MustAsync(Exist) | ||
.WithMessage("Participant does not exist"); | ||
} | ||
|
||
private async Task<bool> Exist(string identifier, CancellationToken cancellationToken) | ||
=> await _unitOfWork.DbContext.Participants.AnyAsync(e => e.Id == identifier, cancellationToken); | ||
} | ||
|
||
} |
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
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
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
17 changes: 17 additions & 0 deletions
17
...tion/Features/Timelines/EventHandlers/ParticipantActiveStatusChangedDomainEventHandler.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 @@ | ||
using Cfo.Cats.Domain.Events; | ||
|
||
namespace Cfo.Cats.Application.Features.Timelines.EventHandlers; | ||
|
||
public class ParticipantActiveStatusChangedDomainEventHandler( | ||
ICurrentUserService currentUserService, | ||
IUnitOfWork unitOfWork) : TimelineNotificationHandler<ParticipantActiveStatusChangedDomainEvent>(currentUserService, unitOfWork) | ||
{ | ||
protected override TimelineEventType GetEventType() => TimelineEventType.Dms; | ||
|
||
protected override string GetLine1(ParticipantActiveStatusChangedDomainEvent notification) => "Participant active status updated"; | ||
|
||
protected override string? GetLine2(ParticipantActiveStatusChangedDomainEvent notification) => string.Format("To {0}", notification.To ? "Active" : "Inactive"); | ||
protected override string? GetLine3(ParticipantActiveStatusChangedDomainEvent notification) => string.Format("From {0}", notification.From ? "Active" : "Inactive"); | ||
|
||
protected override string GetParticipantId(ParticipantActiveStatusChangedDomainEvent notification) => notification.Item.Id; | ||
} |
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
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
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.