diff --git a/CHANGELOG.md b/CHANGELOG.md index 330db432b..feae62cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ All references to `sanctions` have been removed and replaced with `alerts`; the - `GET /v3/persons/find` +## 20240912 + +Endpoints have been added for setting and retrieving QTS via QTLS date. +- `GET /v3/persons//qtls` +- `PUT /v3/persons//qtls` + + ## 20240814 ### `POST /v3/persons/find` diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/ApiModels/QtlsInfo.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/ApiModels/QtlsInfo.cs similarity index 74% rename from TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/ApiModels/QtlsInfo.cs rename to TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/ApiModels/QtlsInfo.cs index c4265f7e2..859832c47 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/ApiModels/QtlsInfo.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/ApiModels/QtlsInfo.cs @@ -1,4 +1,4 @@ -namespace TeachingRecordSystem.Api.V3.VNext.ApiModels; +namespace TeachingRecordSystem.Api.V3.V20240912.ApiModels; [AutoMap(typeof(Core.SharedModels.QtlsInfo))] public record QtlsInfo diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/Controllers/PersonsController.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/Controllers/PersonsController.cs new file mode 100644 index 000000000..c8c3e2a37 --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/Controllers/PersonsController.cs @@ -0,0 +1,49 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using TeachingRecordSystem.Api.Infrastructure.Security; +using TeachingRecordSystem.Api.V3.Core.Operations; +using TeachingRecordSystem.Api.V3.V20240912.ApiModels; +using TeachingRecordSystem.Api.V3.V20240912.Requests; + +namespace TeachingRecordSystem.Api.V3.V20240912.Controllers; + +[Route("persons")] +public class PersonsController(IMapper mapper) : ControllerBase +{ + [HttpPut("{trn}/qtls")] + [SwaggerOperation( + OperationId = "SetQtls", + Summary = "Set QTLS status for a teacher", + Description = "Sets the QTLS status for the teacher with the given TRN.")] + [ProducesResponseType(typeof(QtlsInfo), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(void), StatusCodes.Status202Accepted)] + [MapError(10001, statusCode: StatusCodes.Status404NotFound)] + [Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.AssignQtls)] + public async Task PutQtls( + [FromRoute] string trn, + [FromBody] SetQtlsRequest request, + [FromServices] SetQtlsHandler handler) + { + var command = new SetQtlsCommand(trn, request.QtsDate); + var result = await handler.Handle(command); + return result is { Succeeded: true } ? Ok(result.QtlsInfo!) : Accepted(); + } + + [HttpGet("{trn}/qtls")] + [SwaggerOperation( + OperationId = "GetQtls", + Summary = "Get QTLS status for a teacher", + Description = "Gets the QTLS status for the teacher with the given TRN.")] + [ProducesResponseType(typeof(QtlsInfo), StatusCodes.Status200OK)] + [Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.AssignQtls)] + public async Task GetQtls( + [FromRoute] string trn, + [FromServices] GetQtlsHandler handler) + { + var command = new GetQtlsCommand(trn); + var result = await handler.Handle(command); + var response = mapper.Map(result); + return response is not null ? Ok(response) : NotFound(); + } +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Requests/SetQtlsRequest.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/Requests/SetQtlsRequest.cs similarity index 60% rename from TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Requests/SetQtlsRequest.cs rename to TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/Requests/SetQtlsRequest.cs index 85ca366a5..d38c72384 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Requests/SetQtlsRequest.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/Requests/SetQtlsRequest.cs @@ -1,4 +1,4 @@ -namespace TeachingRecordSystem.Api.V3.VNext.Requests; +namespace TeachingRecordSystem.Api.V3.V20240912.Requests; public record SetQtlsRequest { diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Controllers/PersonsController.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Controllers/PersonsController.cs index bef060061..df2bc5a9a 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Controllers/PersonsController.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Controllers/PersonsController.cs @@ -4,7 +4,6 @@ using TeachingRecordSystem.Api.Infrastructure.ModelBinding; using TeachingRecordSystem.Api.Infrastructure.Security; using TeachingRecordSystem.Api.V3.Core.Operations; -using TeachingRecordSystem.Api.V3.VNext.ApiModels; using TeachingRecordSystem.Api.V3.VNext.Requests; using TeachingRecordSystem.Api.V3.VNext.Responses; @@ -13,42 +12,6 @@ namespace TeachingRecordSystem.Api.V3.VNext.Controllers; [Route("persons")] public class PersonsController(IMapper mapper) : ControllerBase { - [HttpPut("{trn}/qtls")] - [SwaggerOperation( - OperationId = "SetQtls", - Summary = "Set QTLS status for a teacher", - Description = "Sets the QTLS status for the teacher with the given TRN.")] - [ProducesResponseType(typeof(QtlsInfo), StatusCodes.Status200OK)] - [ProducesResponseType(typeof(void), StatusCodes.Status202Accepted)] - [MapError(10001, statusCode: StatusCodes.Status404NotFound)] - [Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.AssignQtls)] - public async Task PutQtls( - [FromRoute] string trn, - [FromBody] SetQtlsRequest request, - [FromServices] SetQtlsHandler handler) - { - var command = new SetQtlsCommand(trn, request.QtsDate); - var result = await handler.Handle(command); - return result is { Succeeded: true } ? Ok(result.QtlsInfo!) : Accepted(); - } - - [HttpGet("{trn}/qtls")] - [SwaggerOperation( - OperationId = "GetQtls", - Summary = "Get QTLS status for a teacher", - Description = "Gets the QTLS status for the teacher with the given TRN.")] - [ProducesResponseType(typeof(QtlsInfo), StatusCodes.Status200OK)] - [Authorize(Policy = AuthorizationPolicies.ApiKey, Roles = ApiRoles.AssignQtls)] - public async Task GetQtls( - [FromRoute] string trn, - [FromServices] GetQtlsHandler handler) - { - var command = new GetQtlsCommand(trn); - var result = await handler.Handle(command); - var response = mapper.Map(result); - return response is not null ? Ok(response) : NotFound(); - } - [HttpGet("{trn}")] [SwaggerOperation( OperationId = "GetPersonByTrn", diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Validators/SetQtlsRequestValidator.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Validators/SetQtlsRequestValidator.cs index 06ba1bc12..ff90c4197 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Validators/SetQtlsRequestValidator.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/VNext/Validators/SetQtlsRequestValidator.cs @@ -1,5 +1,5 @@ using FluentValidation; -using TeachingRecordSystem.Api.V3.VNext.Requests; +using TeachingRecordSystem.Api.V3.V20240912.Requests; namespace TeachingRecordSystem.Api.V3.VNext.Validators; diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/VersionRegistry.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/VersionRegistry.cs index 1b109d544..4a95e0dd2 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/VersionRegistry.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/VersionRegistry.cs @@ -15,6 +15,7 @@ public static class VersionRegistry V3MinorVersions.V20240416, V3MinorVersions.V20240606, V3MinorVersions.V20240814, + V3MinorVersions.V20240912, V3MinorVersions.VNext, ]; @@ -56,6 +57,7 @@ public static class V3MinorVersions public const string V20240416 = "20240416"; public const string V20240606 = "20240606"; public const string V20240814 = "20240814"; + public const string V20240912 = "20240912"; public const string VNext = VNextVersion; } } diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/VNext/GetQtlsDateRequestTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/GetQtlsDateRequestTests.cs similarity index 95% rename from TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/VNext/GetQtlsDateRequestTests.cs rename to TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/GetQtlsDateRequestTests.cs index bea8355b3..408dcb7b0 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/VNext/GetQtlsDateRequestTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/GetQtlsDateRequestTests.cs @@ -1,13 +1,13 @@ using System.Net; -namespace TeachingRecordSystem.Api.Tests.V3.VNext; +namespace TeachingRecordSystem.Api.Tests.V3.V20240912; public class GetQtlsDateRequestTests : TestBase { public GetQtlsDateRequestTests(HostFixture hostFixture) : base(hostFixture) { - SetCurrentApiClient(new[] { ApiRoles.AssignQtls }); + SetCurrentApiClient([ApiRoles.AssignQtls]); } [Theory, RoleNamesData(except: ApiRoles.AssignQtls)] diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/VNext/SetQtlsDateRequestTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/SetQtlsDateRequestTests.cs similarity index 99% rename from TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/VNext/SetQtlsDateRequestTests.cs rename to TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/SetQtlsDateRequestTests.cs index 4f7e54495..340d7b1be 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/VNext/SetQtlsDateRequestTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/SetQtlsDateRequestTests.cs @@ -1,8 +1,8 @@ using System.Net; -using TeachingRecordSystem.Api.V3.VNext.Requests; +using TeachingRecordSystem.Api.V3.V20240912.Requests; using TeachingRecordSystem.Core.Dqt; -namespace TeachingRecordSystem.Api.Tests.V3.VNext; +namespace TeachingRecordSystem.Api.Tests.V3.V20240912; [Collection(nameof(DisableParallelization))] public class SetQtlsDateRequestTests : TestBase diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/TestBase.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/TestBase.cs new file mode 100644 index 000000000..527ab60db --- /dev/null +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.Api.Tests/V3/V20240912/TestBase.cs @@ -0,0 +1,16 @@ +namespace TeachingRecordSystem.Api.Tests.V3.V20240912; + +public abstract class TestBase : Tests.TestBase +{ + public const string Version = VersionRegistry.V3MinorVersions.V20240912; + + protected TestBase(HostFixture hostFixture) : base(hostFixture) + { + } + + public HttpClient GetHttpClientWithApiKey() => + GetHttpClientWithApiKey(Version); + + public HttpClient GetHttpClientWithIdentityAccessToken(string trn, string scope = "dqt:read") => + GetHttpClientWithIdentityAccessToken(trn, scope, Version); +}