Skip to content

Commit

Permalink
Merge branch 'main' into induction-view-details
Browse files Browse the repository at this point in the history
  • Loading branch information
CathLass committed Dec 9, 2024
2 parents cef6596 + b0f90bb commit e809fca
Show file tree
Hide file tree
Showing 85 changed files with 1,854 additions and 725 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ jobs:
run: terraform fmt -check -diff
working-directory: terraform/aks

- name: Download terraform modules
run: make ci dev vendor-modules

- name: Validate
run: |
curl -sL https://github.com/coretech/terrafile/releases/download/v0.8/terrafile_0.8_Linux_x86_64.tar.gz | tar xz terrafile
./terrafile -p vendor/modules -f config/dev_Terrafile
terraform init -backend=false
terraform validate -no-color
working-directory: terraform/aks
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ docs/build
docs/source/dqt-api.yaml
**/.DS_Store

bin/terrafile
terraform/domains/environment_domains/vendor/
terraform/domains/infrastructure/vendor/
terraform/aks/vendor/
Expand Down
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.DEFAULT_GOAL :=help
SHELL :=/bin/bash

TERRAFILE_VERSION=0.8
RG_TAGS={"Product" : "Teaching Record System"}
ARM_TEMPLATE_TAG=1.1.10
REGION=UK South
Expand Down Expand Up @@ -60,19 +59,19 @@ ci: ## Run in automation environment
$(eval CONFIRM_DEPLOY=true)
$(eval SKIP_CONFIRM=true)

bin/terrafile: ## Install terrafile to manage terraform modules
curl -sL https://github.com/coretech/terrafile/releases/download/v${TERRAFILE_VERSION}/terrafile_${TERRAFILE_VERSION}_$$(uname)_$$(uname -m).tar.gz \
| tar xz -C ./bin terrafile
vendor-modules:
rm -rf terraform/aks/vendor/modules/aks
git -c advice.detachedHead=false clone --depth=1 --single-branch --branch ${TERRAFORM_MODULES_TAG} https://github.com/DFE-Digital/terraform-modules.git terraform/aks/vendor/modules/aks

terraform-init: bin/terrafile
terraform-init: vendor-modules
$(eval export TF_VAR_service_name=$(SERVICE_SHORT))
$(eval export TF_VAR_service_short_name=$(SERVICE_SHORT))
$(eval export TF_VAR_config=${CONFIG})
$(eval export TF_VAR_environment_short_name=$(CONFIG_SHORT))
$(eval export TF_VAR_azure_resource_prefix=$(AZURE_RESOURCE_PREFIX))

[[ "${SP_AUTH}" != "true" ]] && az account set -s $(AZURE_SUBSCRIPTION) || true
./bin/terrafile -p terraform/aks/vendor/modules -f terraform/aks/config/${CONFIG}_Terrafile

terraform -chdir=terraform/aks init -upgrade -backend-config config/${CONFIG}.backend.tfvars $(backend_key) -reconfigure

terraform-plan: terraform-init # make [env] terraform-plan init
Expand All @@ -91,8 +90,10 @@ deploy-azure-resources: set-azure-account # make dev deploy-azure-resources CONF
validate-azure-resources: set-azure-account # make dev validate-azure-resources
az deployment sub create --name "resourcedeploy-trs-$(shell date +%Y%m%d%H%M%S)" -l "${REGION}" --template-uri "https://raw.githubusercontent.com/DFE-Digital/tra-shared-services/main/azure/resourcedeploy.json" --parameters "resourceGroupName=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-rg" 'tags=${RG_TAGS}' "tfStorageAccountName=${AZURE_RESOURCE_PREFIX}${SERVICE_SHORT}tfstate${CONFIG_SHORT}" "tfStorageContainerName=${SERVICE_SHORT}-tfstate" "dbBackupStorageAccountName=${AZURE_BACKUP_STORAGE_ACCOUNT_NAME}" "dbBackupStorageContainerName=${AZURE_BACKUP_STORAGE_CONTAINER_NAME}" "keyVaultNames=['${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-api-kv', '${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-authz-kv', '${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-inf-kv', '${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-ui-kv', '${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-worker-kv']" --what-if

domains-init: bin/terrafile domains set-azure-pd-subscription ## make [env] domains-init - terraform init for environment dns/afd resources
./bin/terrafile -p terraform/domains/environment_domains/vendor/modules -f terraform/domains/environment_domains/config/${CONFIG}_Terrafile
domains-init: domains set-azure-pd-subscription ## make [env] domains-init - terraform init for environment dns/afd resources
rm -rf terraform/domains/environment_domains/vendor/modules/domains
git -c advice.detachedHead=false clone --depth=1 --single-branch --branch ${TERRAFORM_MODULES_TAG} https://github.com/DFE-Digital/terraform-modules.git terraform/domains/environment_domains/vendor/modules/domains

terraform -chdir=terraform/domains/environment_domains init -reconfigure -upgrade -backend-config=config/${CONFIG}_backend.tfvars

domains-plan: domains-init ## terraform plan for environment dns/afd resources
Expand All @@ -101,8 +102,10 @@ domains-plan: domains-init ## terraform plan for environment dns/afd resources
domains-apply: domains-init ## terraform apply for environment dns/afd resources, needs CONFIRM_DEPLOY=1 for production
terraform -chdir=terraform/domains/environment_domains apply -var-file config/${CONFIG}.tfvars.json

domains-infra-init: bin/terrafile domains set-azure-pd-subscription ## make domains-infra-init - terraform init for dns/afd core resources, eg Main FrontDoor resource
./bin/terrafile -p terraform/domains/infrastructure/vendor/modules -f terraform/domains/infrastructure/config/trs_Terrafile
domains-infra-init: domains set-azure-pd-subscription ## make domains-infra-init - terraform init for dns/afd core resources, eg Main FrontDoor resource
rm -rf terraform/domains/infrastructure/vendor/modules/domains
git -c advice.detachedHead=false clone --depth=1 --single-branch --branch ${TERRAFORM_MODULES_TAG} https://github.com/DFE-Digital/terraform-modules.git terraform/domains/infrastructure/vendor/modules/domains

terraform -chdir=terraform/domains/infrastructure init -reconfigure -upgrade

domains-infra-plan: domains-infra-init ## terraform plan for dns core resources
Expand Down
33 changes: 33 additions & 0 deletions TeachingRecordSystem/src/TeachingRecordSystem.Api/ApiError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public static class ErrorCodes
public static int SpecifiedResourceUrlDoesNotExist => 10028;
public static int TrnRequestAlreadyCreated => 10029;
public static int TrnRequestDoesNotExist => 10031;
public static int UnexpectedInductionStatus => 10032;
public static int StaleRequest => 10033;
public static int PersonDoesNotHaveQts => 10034;
public static int InvalidInductionStatus => 10035;
public static int InductionStartDateIsRequired => 10036;
public static int InductionCompletedDateIsRequired => 10037;
public static int InductionStartDateIsNotPermitted => 10038;
public static int InductionCompletedDateIsNotPermitted => 10039;
public static int ForbiddenForAppropriateBody => 10040;
}

public static ApiError PersonNotFound(string trn, DateOnly? dateOfBirth = null, string? nationalInsuranceNumber = null)
Expand Down Expand Up @@ -38,6 +47,30 @@ public static ApiError TrnRequestAlreadyCreated(string requestId) =>
public static ApiError TrnRequestDoesNotExist(string requestId) =>
new(ErrorCodes.TrnRequestDoesNotExist, "TRN request does not exist.", $"TRN request ID: '{requestId}'");

public static ApiError StaleRequest(DateTime timestamp) =>
new(ErrorCodes.StaleRequest, "Request is stale.", $"Timestamp: {timestamp:yyyy-MM-dd}");

public static ApiError PersonDoesNotHaveQts(string trn) =>
new(ErrorCodes.PersonDoesNotHaveQts, "Person does not have QTS.", $"TRN: '{trn}'");

public static ApiError InvalidInductionStatus(InductionStatus status) =>
new(ErrorCodes.InvalidInductionStatus, "Invalid induction status.", $"Status: '{status}'");

public static ApiError InductionStartDateIsRequired(InductionStatus status) =>
new(ErrorCodes.InductionStartDateIsRequired, "Induction start date is required.", $"Status: '{status}'");

public static ApiError InductionStartDateIsNotPermitted(InductionStatus status) =>
new(ErrorCodes.InductionStartDateIsNotPermitted, "Induction start date is not permitted.", $"Status: '{status}'");

public static ApiError InductionCompletedDateIsRequired(InductionStatus status) =>
new(ErrorCodes.InductionCompletedDateIsRequired, "Induction completed date is required.", $"Status: '{status}'");

public static ApiError InductionCompletedDateIsNotPermitted(InductionStatus status) =>
new(ErrorCodes.InductionCompletedDateIsNotPermitted, "Induction completed date is not permitted.", $"Status: '{status}'");

public static ApiError ForbiddenForAppropriateBody() =>
new(ErrorCodes.ForbiddenForAppropriateBody, "Forbidden.", "");

public IActionResult ToActionResult(int statusCode = 400)
{
var problemDetails = new ProblemDetails()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Optional;
using Optional.Unsafe;

namespace TeachingRecordSystem.Api.Infrastructure.Mapping;

Expand All @@ -20,3 +21,14 @@ public Option<T> Convert(T sourceMember, ResolutionContext context) =>
Option.Some(sourceMember);
}

public class UnwrapFromOptionValueConverter<TSource, TDestination> : IValueConverter<Option<TSource>, TDestination>
{
public TDestination Convert(Option<TSource> sourceMember, ResolutionContext context) =>
context.Mapper.Map<TDestination>(sourceMember.ValueOrFailure());
}

public class UnwrapFromOptionValueConverter<T> : IValueConverter<Option<T>, T>
{
public T Convert(Option<T> sourceMember, ResolutionContext context) =>
sourceMember.ValueOrFailure();
}
4 changes: 3 additions & 1 deletion TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ public static void Main(string[] args)
cfg.CreateMap(typeof(Option<>), typeof(Option<>)).ConvertUsing(typeof(OptionToOptionTypeConverter<,>));
})
.AddTransient(typeof(WrapWithOptionValueConverter<>))
.AddTransient(typeof(WrapWithOptionValueConverter<,>));
.AddTransient(typeof(WrapWithOptionValueConverter<,>))
.AddTransient(typeof(UnwrapFromOptionValueConverter<>))
.AddTransient(typeof(UnwrapFromOptionValueConverter<,>));

services.Scan(scan =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using TeachingRecordSystem.Core.Dqt.Models;

namespace TeachingRecordSystem.Api.V3.Implementation.Dtos;

public enum DqtInductionStatus
{
Exempt = 1,
Fail = 2,
FailedInWales = 3,
InductionExtended = 4,
InProgress = 5,
NotYetCompleted = 6,
Pass = 7,
PassedInWales = 8,
RequiredToComplete = 9,
}

public static class DqtInductionStatusExtensions
{
public static DqtInductionStatus ConvertToDqtInductionStatus(this dfeta_InductionStatus input) => input switch
{
dfeta_InductionStatus.Exempt => DqtInductionStatus.Exempt,
dfeta_InductionStatus.Fail => DqtInductionStatus.Fail,
dfeta_InductionStatus.FailedinWales => DqtInductionStatus.FailedInWales,
dfeta_InductionStatus.InductionExtended => DqtInductionStatus.InductionExtended,
dfeta_InductionStatus.InProgress => DqtInductionStatus.InProgress,
dfeta_InductionStatus.NotYetCompleted => DqtInductionStatus.NotYetCompleted,
dfeta_InductionStatus.Pass => DqtInductionStatus.Pass,
dfeta_InductionStatus.PassedinWales => DqtInductionStatus.PassedInWales,
dfeta_InductionStatus.RequiredtoComplete => DqtInductionStatus.RequiredToComplete,
_ => throw new ArgumentException($"Unknown {nameof(DqtInductionStatus)}: '{input}'.")
};

public static string GetDescription(this dfeta_InductionStatus input) => ConvertToDqtInductionStatus(input).GetDescription();

public static string GetDescription(this DqtInductionStatus input) => input switch
{
DqtInductionStatus.Exempt => "Exempt",
DqtInductionStatus.Fail => "Fail",
DqtInductionStatus.FailedInWales => "Failed in Wales",
DqtInductionStatus.InductionExtended => "Extended",
DqtInductionStatus.InProgress => "In progress",
DqtInductionStatus.NotYetCompleted => "Not yet completed",
DqtInductionStatus.Pass => "Pass",
DqtInductionStatus.PassedInWales => "Passed in Wales",
DqtInductionStatus.RequiredToComplete => "Required to complete",
_ => throw new ArgumentException($"Unknown {nameof(DqtInductionStatus)}: '{input}'.")
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace TeachingRecordSystem.Api.V3.Implementation.Dtos;

public record InductionStatusInfo
public record DqtInductionStatusInfo
{
public required InductionStatus Status { get; init; }
public required DqtInductionStatus Status { get; init; }
public required string StatusDescription { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TeachingRecordSystem.Core.Dqt.Models;

namespace TeachingRecordSystem.Api.V3.Core.SharedModels;
namespace TeachingRecordSystem.Api.V3.Implementation.Dtos;

public enum Gender
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TeachingRecordSystem.Api.V3.Implementation.Dtos;

public record InductionInfo
{
public required InductionStatus Status { get; init; }
public required DateOnly? StartDate { get; init; }
public required DateOnly? CompletedDate { get; init; }
}

This file was deleted.

Loading

0 comments on commit e809fca

Please sign in to comment.