-
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.
Release V20250203 API version (#1851)
In preparation for induction migration, we need the related APIs to be available in a formal API version. I've added every other pending change in `VNext` too save for those that are not implemented.
- Loading branch information
Showing
30 changed files
with
242 additions
and
178 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
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
123 changes: 123 additions & 0 deletions
123
...ngRecordSystem/src/TeachingRecordSystem.Api/V3/V20250203/Controllers/PersonsController.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,123 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
using TeachingRecordSystem.Api.Infrastructure.ModelBinding; | ||
using TeachingRecordSystem.Api.Infrastructure.Security; | ||
using TeachingRecordSystem.Api.V3.Implementation.Operations; | ||
using TeachingRecordSystem.Api.V3.V20250203.Requests; | ||
using TeachingRecordSystem.Api.V3.V20250203.Responses; | ||
|
||
namespace TeachingRecordSystem.Api.V3.V20250203.Controllers; | ||
|
||
[Route("persons")] | ||
public class PersonsController(IMapper mapper) : ControllerBase | ||
{ | ||
[HttpPut("{trn}/cpd-induction")] | ||
[SwaggerOperation( | ||
OperationId = "SetPersonCpdInductionStatus", | ||
Summary = "Set person induction status", | ||
Description = "Sets the induction details of the person with the given TRN.")] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
[Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.SetCpdInduction)] | ||
public async Task<IActionResult> SetCpdInductionStatusAsync( | ||
[FromRoute] string trn, | ||
[FromBody] SetCpdInductionStatusRequest request, | ||
[FromServices] SetCpdInductionStatusHandler handler) | ||
{ | ||
var command = new SetCpdInductionStatusCommand( | ||
trn, | ||
mapper.Map<InductionStatus>(request.Status), | ||
request.StartDate, | ||
request.CompletedDate, | ||
request.ModifiedOn.UtcDateTime); | ||
|
||
var result = await handler.HandleAsync(command); | ||
|
||
return result.ToActionResult(_ => NoContent()) | ||
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound) | ||
.MapErrorCode(ApiError.ErrorCodes.StaleRequest, StatusCodes.Status409Conflict); | ||
} | ||
|
||
[HttpGet("{trn}")] | ||
[SwaggerOperation( | ||
OperationId = "GetPersonByTrn", | ||
Summary = "Get person details by TRN", | ||
Description = "Gets the details of the person corresponding to the given TRN.")] | ||
[ProducesResponseType(typeof(GetPersonResponse), StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
[Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = $"{ApiRoles.GetPerson},{ApiRoles.AppropriateBody}")] | ||
public async Task<IActionResult> GetAsync( | ||
[FromRoute] string trn, | ||
[FromQuery, ModelBinder(typeof(FlagsEnumStringListModelBinder)), SwaggerParameter("The additional properties to include in the response.")] GetPersonRequestIncludes? include, | ||
[FromQuery, SwaggerParameter("Adds an additional check that the record has the specified dateOfBirth, if provided.")] DateOnly? dateOfBirth, | ||
[FromQuery, SwaggerParameter("Adds an additional check that the record has the specified nationalInsuranceNumber, if provided.")] string? nationalInsuranceNumber, | ||
[FromServices] GetPersonHandler handler) | ||
{ | ||
include ??= GetPersonRequestIncludes.None; | ||
|
||
// For now we don't support both a DOB and NINO being passed | ||
if (dateOfBirth is not null && nationalInsuranceNumber is not null) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
var command = new GetPersonCommand( | ||
trn, | ||
(GetPersonCommandIncludes)include, | ||
dateOfBirth, | ||
ApplyLegacyAlertsBehavior: false, | ||
ApplyAppropriateBodyUserRestrictions: User.IsInRole(ApiRoles.AppropriateBody), | ||
nationalInsuranceNumber); | ||
|
||
var result = await handler.HandleAsync(command); | ||
|
||
return result | ||
.ToActionResult(r => Ok(mapper.Map<GetPersonResponse>(r))) | ||
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound) | ||
.MapErrorCode(ApiError.ErrorCodes.ForbiddenForAppropriateBody, StatusCodes.Status403Forbidden); | ||
} | ||
|
||
[HttpPost("find")] | ||
[SwaggerOperation( | ||
OperationId = "FindPersons", | ||
Summary = "Find persons", | ||
Description = "Finds persons matching the specified criteria.")] | ||
[ProducesResponseType(typeof(FindPersonsResponse), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.GetPerson)] | ||
public async Task<IActionResult> FindPersonsAsync( | ||
[FromBody] FindPersonsRequest request, | ||
[FromServices] FindPersonsByTrnAndDateOfBirthHandler handler) | ||
{ | ||
var command = new FindPersonsByTrnAndDateOfBirthCommand(request.Persons.Select(p => (p.Trn, p.DateOfBirth))); | ||
var result = await handler.HandleAsync(command); | ||
return result.ToActionResult(r => Ok(mapper.Map<FindPersonsResponse>(r))); | ||
} | ||
|
||
[HttpGet("")] | ||
[SwaggerOperation( | ||
OperationId = "FindPerson", | ||
Summary = "Find person", | ||
Description = "Finds a person matching the specified criteria.")] | ||
[ProducesResponseType(typeof(FindPersonResponse), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.GetPerson)] | ||
public async Task<IActionResult> FindPersonsAsync( | ||
FindPersonRequest request, | ||
[FromServices] FindPersonByLastNameAndDateOfBirthHandler handler) | ||
{ | ||
var command = new FindPersonByLastNameAndDateOfBirthCommand(request.LastName!, request.DateOfBirth!.Value); | ||
var result = await handler.HandleAsync(command); | ||
|
||
return result.ToActionResult(r => | ||
Ok(new FindPersonResponse() | ||
{ | ||
Total = r.Total, | ||
Query = request, | ||
Results = r.Items.Select(mapper.Map<FindPersonResponseResult>).AsReadOnly() | ||
})); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250203/MapperProfile.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,13 @@ | ||
using TeachingRecordSystem.Core.ApiSchema.V3.V20250203.Dtos; | ||
using TrnRequestInfo = TeachingRecordSystem.Core.ApiSchema.V3.V20250203.Dtos.TrnRequestInfo; | ||
|
||
namespace TeachingRecordSystem.Api.V3.V20250203; | ||
|
||
public class MapperProfile : Profile | ||
{ | ||
public MapperProfile() | ||
{ | ||
CreateMap<Implementation.Dtos.TrnRequestInfo, TrnRequestInfo>(); | ||
CreateMap<Implementation.Dtos.InductionInfo, InductionInfo>(); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...VNext/Requests/CreateTrnRequestRequest.cs → ...50203/Requests/CreateTrnRequestRequest.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
2 changes: 1 addition & 1 deletion
2
...pi/V3/VNext/Requests/FindPersonRequest.cs → ...3/V20250203/Requests/FindPersonRequest.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
2 changes: 1 addition & 1 deletion
2
...i/V3/VNext/Requests/FindPersonsRequest.cs → .../V20250203/Requests/FindPersonsRequest.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
2 changes: 1 addition & 1 deletion
2
...Next/Requests/GetPersonRequestIncludes.cs → ...0203/Requests/GetPersonRequestIncludes.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
4 changes: 2 additions & 2 deletions
4
.../Requests/SetCpdInductionStatusRequest.cs → .../Requests/SetCpdInductionStatusRequest.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
8 changes: 4 additions & 4 deletions
8
.../V3/VNext/Responses/FindPersonResponse.cs → ...V20250203/Responses/FindPersonResponse.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
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
4 changes: 2 additions & 2 deletions
4
...ators/CreateTrnRequestRequestValidator.cs → ...ators/CreateTrnRequestRequestValidator.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
Oops, something went wrong.