Skip to content

Commit

Permalink
Use source generator
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Aug 16, 2024
1 parent ae59a7b commit 91b8a43
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TeachingRecordSystem.Api.V3.V20240101.Responses;

[AutoMap(typeof(FindPersonByLastNameAndDateOfBirthResult))]
public record FindTeachersResponse
{
public required int Total { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Security.Claims;
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.Core.Operations;
using TeachingRecordSystem.Api.V3.V20240416.Requests;
using TeachingRecordSystem.Api.V3.V20240416.Responses;

namespace TeachingRecordSystem.Api.V3.V20240416.Controllers;

[Route("teacher")]
public class TeacherController(IMapper mapper) : ControllerBase
{
[Authorize(AuthorizationPolicies.IdentityUserWithTrn)]
[HttpGet]
[SwaggerOperation(
OperationId = "GetCurrentTeacher",
Summary = "Get the current teacher's details",
Description = "Gets the details for the authenticated teacher.")]
[ProducesResponseType(typeof(GetTeacherResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
public async Task<IActionResult> Get(
[FromQuery, ModelBinder(typeof(FlagsEnumStringListModelBinder)), SwaggerParameter("The additional properties to include in the response.")] GetTeacherRequestIncludes? include,
[FromServices] GetPersonHandler handler)
{
var trn = User.FindFirstValue("trn");

if (trn is null)
{
return MissingOrInvalidTrn();
}

var command = new GetPersonCommand(
trn,
include is not null ? (GetPersonCommandIncludes)include : GetPersonCommandIncludes.None,
DateOfBirth: null);

var result = await handler.Handle(command);

if (result is null)
{
return MissingOrInvalidTrn();
}

var response = mapper.Map<GetTeacherResponse>(result);
return Ok(response);

IActionResult MissingOrInvalidTrn() => Forbid();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using TeachingRecordSystem.Api.Infrastructure.ModelBinding;
using TeachingRecordSystem.Api.Infrastructure.Security;
using TeachingRecordSystem.Api.V3.Core.Operations;
using GetTeacherDtoVersion = TeachingRecordSystem.Api.V3.V20240101;
using TeachingRecordSystem.Api.V3.V20240416.Requests;
using TeachingRecordSystem.Api.V3.V20240416.Responses;

namespace TeachingRecordSystem.Api.V3.V20240416.Controllers;

Expand All @@ -16,13 +17,13 @@ public class TeachersController(IMapper mapper) : ControllerBase
OperationId = "GetTeacherByTrn",
Summary = "Get teacher details by TRN",
Description = "Gets the details of the teacher corresponding to the given TRN.")]
[ProducesResponseType(typeof(GetTeacherDtoVersion.Responses.GetTeacherResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(GetTeacherResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
[Authorize(Policy = AuthorizationPolicies.GetPerson)]
public async Task<IActionResult> Get(
[FromRoute] string trn,
[FromQuery, ModelBinder(typeof(FlagsEnumStringListModelBinder)), SwaggerParameter("The additional properties to include in the response.")] GetTeacherDtoVersion.Requests.GetTeacherRequestIncludes? include,
[FromQuery, ModelBinder(typeof(FlagsEnumStringListModelBinder)), SwaggerParameter("The additional properties to include in the response.")] GetTeacherRequestIncludes? include,
[FromQuery, SwaggerParameter("Adds an additional check that the record has the specified dateOfBirth, if provided.")] DateOnly? dateOfBirth,
[FromServices] GetPersonHandler handler)
{
Expand All @@ -38,7 +39,7 @@ public async Task<IActionResult> Get(
return NotFound();
}

var response = mapper.Map<GetTeacherDtoVersion.Responses.GetTeacherResponse>(result);
var response = mapper.Map<GetTeacherResponse>(result);
return Ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel;

namespace TeachingRecordSystem.Api.V3.V20240416.Requests;

[Flags]
[Description("Comma-separated list of data to include in response.")]
public enum GetTeacherRequestIncludes
{
None = 0,

Induction = 1 << 0,
InitialTeacherTraining = 1 << 1,
NpqQualifications = 1 << 2,
MandatoryQualifications = 1 << 3,
PendingDetailChanges = 1 << 4,
HigherEducationQualifications = 1 << 5,
Sanctions = 1 << 6,
Alerts = 1 << 7,
PreviousNames = 1 << 8,

[ExcludeFromSchema]
_AllowIdSignInWithProhibitions = 1 << 9,

All = Induction | InitialTeacherTraining | NpqQualifications | MandatoryQualifications | PendingDetailChanges | HigherEducationQualifications | Sanctions | Alerts | PreviousNames
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using TeachingRecordSystem.Api.V3.Core.Operations;

namespace TeachingRecordSystem.Api.V3.V20240416.Responses;

[AutoMap(typeof(GetPersonResult))]
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponse))]
public partial record GetTeacherResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using TeachingRecordSystem.Api.V3.Core.Operations;
using TeachingRecordSystem.Api.V3.V20240606.Requests;
using TeachingRecordSystem.Api.V3.V20240606.Responses;
using CreateDetailChangeResponseVersion = TeachingRecordSystem.Api.V3.V20240412;

namespace TeachingRecordSystem.Api.V3.V20240606.Controllers;

Expand Down Expand Up @@ -41,7 +40,7 @@ public async Task<IActionResult> Get(
OperationId = "CreateNameChange",
Summary = "Create name change request",
Description = "Creates a name change request for the authenticated teacher.")]
[ProducesResponseType(typeof(CreateDetailChangeResponseVersion.Responses.CreateNameChangeResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(CreateNameChangeResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[Authorize(AuthorizationPolicies.IdentityUserWithTrn)]
public async Task<IActionResult> CreateNameChange(
Expand All @@ -60,7 +59,7 @@ public async Task<IActionResult> CreateNameChange(
};

var caseNumber = await handler.Handle(command);
var response = new CreateDetailChangeResponseVersion.Responses.CreateNameChangeResponse() { CaseNumber = caseNumber };
var response = new CreateNameChangeResponse() { CaseNumber = caseNumber };
return Ok(response);
}

Expand All @@ -69,7 +68,7 @@ public async Task<IActionResult> CreateNameChange(
OperationId = "CreateDobChange",
Summary = "Create DOB change request",
Description = "Creates a date of birth change request for the authenticated teacher.")]
[ProducesResponseType(typeof(CreateDetailChangeResponseVersion.Responses.CreateDateOfBirthChangeResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(CreateDateOfBirthChangeResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[Authorize(AuthorizationPolicies.IdentityUserWithTrn)]
public async Task<IActionResult> CreateDateOfBirthChange(
Expand All @@ -86,7 +85,7 @@ public async Task<IActionResult> CreateDateOfBirthChange(
};

var caseNumber = await handler.Handle(command);
var response = new CreateDetailChangeResponseVersion.Responses.CreateNameChangeResponse() { CaseNumber = caseNumber };
var response = new CreateNameChangeResponse() { CaseNumber = caseNumber };
return Ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace TeachingRecordSystem.Api.V3.V20240606.Responses;

[GenerateVersionedDto(typeof(V20240412.Responses.CreateDateOfBirthChangeResponse))]
public partial record CreateDateOfBirthChangeResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace TeachingRecordSystem.Api.V3.V20240606.Responses;

[GenerateVersionedDto(typeof(V20240412.Responses.CreateNameChangeResponse))]
public partial record CreateNameChangeResponse;
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
using TeachingRecordSystem.Api.V3.Core.Operations;
using TeachingRecordSystem.Api.V3.V20240101.ApiModels;
using TeachingRecordSystem.Api.V3.V20240606.Requests;

namespace TeachingRecordSystem.Api.V3.V20240606.Responses;

[AutoMap(typeof(FindPersonByLastNameAndDateOfBirthResult))]
public record FindPersonResponse
[GenerateVersionedDto(typeof(V20240101.Responses.FindTeachersResponse), excludeMembers: ["Query", "Results"])]
public partial record FindPersonResponse
{
public required int Total { get; init; }
public required FindPersonRequest Query { get; init; }
public required IReadOnlyCollection<FindPersonResponseResult> Results { get; init; }
}

[AutoMap(typeof(FindPersonByLastNameAndDateOfBirthResultItem))]
public record FindPersonResponseResult
{
public required string Trn { get; init; }
public required DateOnly DateOfBirth { get; init; }
public required string FirstName { get; init; }
public required string MiddleName { get; init; }
public required string LastName { get; init; }
public required IReadOnlyCollection<SanctionInfo> Sanctions { get; init; }
public required IReadOnlyCollection<NameInfo> PreviousNames { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.FindTeachersResponseResult))]
public partial record FindPersonResponseResult;
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Text.Json.Serialization;
using Optional;
using TeachingRecordSystem.Api.V3.Core.Operations;
using TeachingRecordSystem.Api.V3.V20240101.ApiModels;

namespace TeachingRecordSystem.Api.V3.V20240606.Responses;

[AutoMap(typeof(GetPersonResult))]
public record GetPersonResponse
public partial record GetPersonResponse
{
public required string Trn { get; init; }
public required string FirstName { get; init; }
Expand All @@ -31,121 +30,61 @@ public record GetPersonResponse
}

[AutoMap(typeof(GetPersonResultQts))]
public record GetPersonResponseQts
{
public required DateOnly? Awarded { get; init; }
public required string CertificateUrl { get; init; }
public required string? StatusDescription { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseQts))]
public partial record GetPersonResponseQts;

[AutoMap(typeof(GetPersonResultEyts))]
public record GetPersonResponseEyts
{
public required DateOnly? Awarded { get; init; }
public required string CertificateUrl { get; init; }
public required string? StatusDescription { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseEyts))]
public partial record GetPersonResponseEyts;

[AutoMap(typeof(GetPersonResultInduction))]
public record GetPersonResponseInduction
{
public required DateOnly? StartDate { get; init; }
public required DateOnly? EndDate { get; init; }
public required InductionStatus? Status { get; init; }
public required string? StatusDescription { get; init; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public required string? CertificateUrl { get; init; }
public required IReadOnlyCollection<GetPersonResponseInductionPeriod> Periods { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInduction))]
public partial record GetPersonResponseInduction;

[AutoMap(typeof(GetPersonResultInductionPeriod))]
public record GetPersonResponseInductionPeriod
{
public required DateOnly? StartDate { get; init; }
public required DateOnly? EndDate { get; init; }
public required int? Terms { get; init; }
public required GetPersonResponseInductionPeriodAppropriateBody? AppropriateBody { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInductionPeriod))]
public partial record GetPersonResponseInductionPeriod;

[AutoMap(typeof(GetPersonResultInductionPeriodAppropriateBody))]
public record GetPersonResponseInductionPeriodAppropriateBody
{
public required string Name { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInductionPeriodAppropriateBody))]
public partial record GetPersonResponseInductionPeriodAppropriateBody;

[AutoMap(typeof(GetPersonResultInitialTeacherTraining))]
public record GetPersonResponseInitialTeacherTraining
{
public required GetPersonResponseInitialTeacherTrainingQualification? Qualification { get; init; }
public required DateOnly? StartDate { get; init; }
public required DateOnly? EndDate { get; init; }
public required IttProgrammeType? ProgrammeType { get; init; }
public required string? ProgrammeTypeDescription { get; init; }
public required IttOutcome? Result { get; init; }
public required GetPersonResponseInitialTeacherTrainingAgeRange? AgeRange { get; init; }
public required GetPersonResponseInitialTeacherTrainingProvider? Provider { get; init; }
public required IReadOnlyCollection<GetPersonResponseInitialTeacherTrainingSubject> Subjects { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInitialTeacherTraining))]
public partial record GetPersonResponseInitialTeacherTraining;

[AutoMap(typeof(GetPersonResultInitialTeacherTrainingQualification))]
public record GetPersonResponseInitialTeacherTrainingQualification
{
public required string Name { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInitialTeacherTrainingQualification))]
public partial record GetPersonResponseInitialTeacherTrainingQualification;

[AutoMap(typeof(GetPersonResultInitialTeacherTrainingAgeRange))]
public record GetPersonResponseInitialTeacherTrainingAgeRange
{
public required string Description { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInitialTeacherTrainingAgeRange))]
public partial record GetPersonResponseInitialTeacherTrainingAgeRange;

[AutoMap(typeof(GetPersonResultInitialTeacherTrainingProvider))]
public record GetPersonResponseInitialTeacherTrainingProvider
{
public required string Name { get; init; }
public required string Ukprn { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInitialTeacherTrainingProvider))]
public partial record GetPersonResponseInitialTeacherTrainingProvider;

[AutoMap(typeof(GetPersonResultInitialTeacherTrainingSubject))]
public record GetPersonResponseInitialTeacherTrainingSubject
{
public required string Code { get; init; }
public required string Name { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseInitialTeacherTrainingSubject))]
public partial record GetPersonResponseInitialTeacherTrainingSubject;

[AutoMap(typeof(GetPersonResultNpqQualification))]
public record GetPersonResponseNpqQualification
{
public required DateOnly Awarded { get; init; }
public required GetPersonResponseNpqQualificationType Type { get; init; }
public required string CertificateUrl { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseNpqQualification))]
public partial record GetPersonResponseNpqQualification;

[AutoMap(typeof(GetPersonResultNpqQualificationType))]
public record GetPersonResponseNpqQualificationType
{
public required NpqQualificationType Code { get; init; }
public required string Name { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseNpqQualificationType))]
public partial record GetPersonResponseNpqQualificationType;

[AutoMap(typeof(GetPersonResultMandatoryQualification))]
public record GetPersonResponseMandatoryQualification
{
public required DateOnly Awarded { get; init; }
public required string Specialism { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseMandatoryQualification))]
public partial record GetPersonResponseMandatoryQualification;

[AutoMap(typeof(GetPersonResultHigherEducationQualification))]
public record GetPersonResponseHigherEducationQualification
{
public required string? Name { get; init; }
public required DateOnly? Awarded { get; init; }
public required IReadOnlyCollection<GetPersonResponseHigherEducationQualificationSubject> Subjects { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseHigherEducationQualification))]
public partial record GetPersonResponseHigherEducationQualification;

[AutoMap(typeof(GetPersonResultHigherEducationQualificationSubject))]
public record GetPersonResponseHigherEducationQualificationSubject
{
public required string Code { get; init; }
public required string Name { get; init; }
}
[GenerateVersionedDto(typeof(V20240101.Responses.GetTeacherResponseHigherEducationQualificationSubject))]
public partial record GetPersonResponseHigherEducationQualificationSubject;

0 comments on commit 91b8a43

Please sign in to comment.