-
Notifications
You must be signed in to change notification settings - Fork 1
Add API operation to activate a dormant TRN request #3199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
...RecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Security/ICurrentUserProvider.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| namespace TeachingRecordSystem.Api.Infrastructure.Security; | ||
|
|
||
| public interface ICurrentUserProvider | ||
| { | ||
| Guid GetCurrentApplicationUserId(); | ||
| bool TryGetTrnRequestId([NotNullWhen(true)] out string? trnRequestId); | ||
| } |
59 changes: 59 additions & 0 deletions
59
...ordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/ActivateTrnRequest.cs
This file contains hidden or 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,59 @@ | ||
| using TeachingRecordSystem.Api.Infrastructure.Security; | ||
| using TeachingRecordSystem.Api.V3.Implementation.Dtos; | ||
| using TeachingRecordSystem.Core.Services.TrnRequests; | ||
|
|
||
| namespace TeachingRecordSystem.Api.V3.Implementation.Operations; | ||
|
|
||
| public record ActivateTrnRequestCommand(string RequestId) : ICommand<ActivateTrnRequestResult>; | ||
|
|
||
| public record ActivateTrnRequestResult(bool WasActivated, Dtos.TrnRequestInfo TrnRequestInfo); | ||
|
|
||
| public class ActivateTrnRequestHandler(TrnRequestService trnRequestService, TimeProvider timeProvider, ICurrentUserProvider currentUserProvider) : | ||
| ICommandHandler<ActivateTrnRequestCommand, ActivateTrnRequestResult> | ||
| { | ||
| public async Task<ApiResult<ActivateTrnRequestResult>> ExecuteAsync(ActivateTrnRequestCommand command) | ||
| { | ||
| var currentApplicationUserId = currentUserProvider.GetCurrentApplicationUserId(); | ||
|
|
||
| var trnRequestInfo = await trnRequestService.GetTrnRequestAsync(currentApplicationUserId, command.RequestId); | ||
|
|
||
| if (trnRequestInfo is null) | ||
| { | ||
| return ApiError.TrnRequestDoesNotExist(command.RequestId); | ||
| } | ||
|
|
||
| var trnRequest = trnRequestInfo.TrnRequest; | ||
| var needsActivating = trnRequest.Status is TrnRequestStatus.Dormant; | ||
|
|
||
| if (needsActivating) | ||
| { | ||
| var processContext = new ProcessContext(ProcessType.TrnRequestActivating, timeProvider.UtcNow, currentApplicationUserId); | ||
|
|
||
| await trnRequestService.ActivateTrnRequestAsync(trnRequest, processContext); | ||
| } | ||
|
|
||
| return new ActivateTrnRequestResult( | ||
| WasActivated: needsActivating, | ||
| new Dtos.TrnRequestInfo() | ||
| { | ||
| RequestId = command.RequestId, | ||
| #pragma warning disable TRS0001 | ||
| Person = new TrnRequestInfoPerson() | ||
| #pragma warning restore TRS0001 | ||
| { | ||
| FirstName = trnRequest.FirstName!, | ||
| LastName = trnRequest.LastName!, | ||
| MiddleName = trnRequest.MiddleName, | ||
| EmailAddress = trnRequest.EmailAddress, | ||
| NationalInsuranceNumber = trnRequest.NationalInsuranceNumber, | ||
| DateOfBirth = trnRequest.DateOfBirth | ||
| }, | ||
| Trn = trnRequestInfo.ResolvedPersonTrn, | ||
| Status = trnRequest.Status, | ||
| PotentialDuplicate = trnRequest.PotentialDuplicate, | ||
| AccessYourTeachingQualificationsLink = trnRequest is { TrnToken: string trnToken, Status: TrnRequestStatus.Completed } ? | ||
| trnRequestService.GetAccessYourTeachingQualificationsLink(trnToken) : | ||
| null | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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
38 changes: 38 additions & 0 deletions
38
...ecordSystem/src/TeachingRecordSystem.Api/V3/V20260416/Controllers/TrnRequestController.cs
This file contains hidden or 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,38 @@ | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Swashbuckle.AspNetCore.Annotations; | ||
| using TeachingRecordSystem.Api.Infrastructure.Security; | ||
| using TeachingRecordSystem.Api.V3.Implementation.Operations; | ||
| using TeachingRecordSystem.Core.ApiSchema.V3.V20250425.Dtos; | ||
|
|
||
| namespace TeachingRecordSystem.Api.V3.V20260416.Controllers; | ||
|
|
||
| [Route("trn-requests")] | ||
| public class TrnRequestController(ICommandDispatcher commandDispatcher, IMapper mapper, ICurrentUserProvider currentUserProvider) : ControllerBase | ||
| { | ||
| [HttpPut("active/{trnRequestId}")] | ||
| [SwaggerOperation( | ||
| OperationId = "ActivateTrnRequest", | ||
| Summary = "Activate dormant TRN request", | ||
| Description = "Activates a dormant request created by Teacher Auth.")] | ||
| [Authorize(AuthorizationPolicies.IdentityUserWithTrn)] | ||
| [ProducesResponseType(typeof(TrnRequestInfo), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(TrnRequestInfo), StatusCodes.Status204NoContent)] | ||
| [ProducesResponseType(StatusCodes.Status403Forbidden)] | ||
| public async Task<IActionResult> ActivateAsync([FromRoute] string trnRequestId) | ||
| { | ||
| if (!currentUserProvider.TryGetTrnRequestId(out var tokenTrnRequestId) || tokenTrnRequestId != trnRequestId) | ||
| { | ||
| return Forbid(); | ||
| } | ||
|
|
||
| var command = new ActivateTrnRequestCommand(trnRequestId); | ||
| var result = await commandDispatcher.DispatchAsync(command); | ||
|
|
||
| return result.ToActionResult( | ||
| r => StatusCode( | ||
| r.WasActivated ? StatusCodes.Status200OK : StatusCodes.Status204NoContent, | ||
| mapper.Map<TrnRequestInfo>(r.TrnRequestInfo))) | ||
| .MapErrorCode(ApiError.ErrorCodes.TrnRequestDoesNotExist, StatusCodes.Status404NotFound); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.