Skip to content

Commit

Permalink
Release QTLS endpoints (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Sep 12, 2024
1 parent a4df696 commit 58cc546
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 44 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<trn>/qtls`
- `PUT /v3/persons/<trn>/qtls`


## 20240814

### `POST /v3/persons/find`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeachingRecordSystem.Api.V3.VNext.ApiModels;
namespace TeachingRecordSystem.Api.V3.V20240912.ApiModels;

[AutoMap(typeof(Core.SharedModels.QtlsInfo))]
public record QtlsInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IActionResult> 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<IActionResult> GetQtls(
[FromRoute] string trn,
[FromServices] GetQtlsHandler handler)
{
var command = new GetQtlsCommand(trn);
var result = await handler.Handle(command);
var response = mapper.Map<QtlsInfo?>(result);
return response is not null ? Ok(response) : NotFound();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeachingRecordSystem.Api.V3.VNext.Requests;
namespace TeachingRecordSystem.Api.V3.V20240912.Requests;

public record SetQtlsRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<IActionResult> 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<IActionResult> GetQtls(
[FromRoute] string trn,
[FromServices] GetQtlsHandler handler)
{
var command = new GetQtlsCommand(trn);
var result = await handler.Handle(command);
var response = mapper.Map<QtlsInfo?>(result);
return response is not null ? Ok(response) : NotFound();
}

[HttpGet("{trn}")]
[SwaggerOperation(
OperationId = "GetPersonByTrn",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentValidation;
using TeachingRecordSystem.Api.V3.VNext.Requests;
using TeachingRecordSystem.Api.V3.V20240912.Requests;

namespace TeachingRecordSystem.Api.V3.VNext.Validators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class VersionRegistry
V3MinorVersions.V20240416,
V3MinorVersions.V20240606,
V3MinorVersions.V20240814,
V3MinorVersions.V20240912,
V3MinorVersions.VNext,
];

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 58cc546

Please sign in to comment.