From 7681ae99a3ec4e4cb1584df95df7c860fbaf7b05 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 20 Apr 2026 15:49:34 +0000
Subject: [PATCH] Replace AutoMapper with Mapperly: create ApiMappers, update
controllers, fix Extensions/GlobalUsings, delete old files
Agent-Logs-Url: https://github.com/DFE-Digital/teaching-record-system/sessions/8b6ce974-583c-4911-8066-c0443ea8a848
Co-authored-by: gunndabad <2041280+gunndabad@users.noreply.github.com>
---
TeachingRecordSystem/Directory.Packages.props | 2 +-
.../TeachingRecordSystem.Api/Extensions.cs | 36 ++--
.../TeachingRecordSystem.Api/GlobalUsings.cs | 1 -
.../Infrastructure/Mapping/OptionMapper.cs | 40 ----
.../TeachingRecordSystem.Api.csproj | 2 +-
.../V3/V20240101/ApiMapper.cs | 152 +++++++++++++
.../Controllers/TeacherController.cs | 4 +-
.../Controllers/TeachersController.cs | 6 +-
.../V3/V20240101/MapperProfile.cs | 39 ----
.../Responses/FindTeachersResponse.cs | 2 -
.../V20240101/Responses/GetTeacherResponse.cs | 19 --
.../V3/V20240307/ApiMapper.cs | 29 +++
.../Controllers/TrnRequestsController.cs | 6 +-
.../V3/V20240307/MapperProfile.cs | 14 --
.../V3/V20240412/ApiMapper.cs | 15 ++
.../Controllers/TeacherController.cs | 6 +-
.../CreateDateOfBirthChangeResponse.cs | 3 -
.../Responses/CreateNameChangeResponse.cs | 3 -
.../V3/V20240416/ApiMapper.cs | 124 +++++++++++
.../Controllers/TeacherController.cs | 4 +-
.../Controllers/TeachersController.cs | 4 +-
.../V3/V20240416/MapperProfile.cs | 23 --
.../V20240416/Responses/GetTeacherResponse.cs | 18 --
.../V3/V20240606/ApiMapper.cs | 134 ++++++++++++
.../V20240606/Controllers/PersonController.cs | 8 +-
.../Controllers/PersonsController.cs | 6 +-
.../Controllers/TrnRequestsController.cs | 6 +-
.../V3/V20240606/MapperProfile.cs | 25 ---
.../CreateDateOfBirthChangeResponse.cs | 3 -
.../Responses/CreateNameChangeResponse.cs | 3 -
.../V20240606/Responses/FindPersonResponse.cs | 2 -
.../V20240606/Responses/GetPersonResponse.cs | 18 --
.../V3/V20240814/ApiMapper.cs | 78 +++++++
.../Controllers/PersonsController.cs | 6 +-
.../V3/V20240814/MapperProfile.cs | 15 --
.../V20240814/Responses/FindPersonResponse.cs | 4 -
.../Responses/FindPersonsResponse.cs | 6 -
.../V3/V20240912/ApiMapper.cs | 12 ++
.../Controllers/PersonsController.cs | 6 +-
.../V3/V20240912/MapperProfile.cs | 11 -
.../V3/V20240920/ApiMapper.cs | 157 ++++++++++++++
.../V20240920/Controllers/PersonController.cs | 4 +-
.../Controllers/PersonsController.cs | 8 +-
.../V3/V20240920/MapperProfile.cs | 13 --
.../V20240920/Responses/FindPersonResponse.cs | 4 -
.../Responses/FindPersonsResponse.cs | 6 -
.../V20240920/Responses/GetPersonResponse.cs | 17 --
.../V3/V20250203/ApiMapper.cs | 155 ++++++++++++++
.../V20250203/Controllers/PersonController.cs | 4 +-
.../Controllers/PersonsController.cs | 10 +-
.../Controllers/TrnRequestsController.cs | 6 +-
.../V3/V20250203/MapperProfile.cs | 13 --
.../V20250203/Responses/FindPersonResponse.cs | 4 -
.../Responses/FindPersonsResponse.cs | 6 -
.../V20250203/Responses/GetPersonResponse.cs | 15 --
.../V3/V20250327/ApiMapper.cs | 140 ++++++++++++
.../V20250327/Controllers/PersonController.cs | 4 +-
.../Controllers/PersonsController.cs | 8 +-
.../V3/V20250327/MapperProfile.cs | 12 --
.../V20250327/Responses/FindPersonResponse.cs | 4 -
.../Responses/FindPersonsResponse.cs | 6 -
.../V20250327/Responses/GetPersonResponse.cs | 15 --
.../V3/V20250425/ApiMapper.cs | 24 +++
.../Controllers/PersonsController.cs | 4 +-
.../Controllers/TrnRequestsController.cs | 8 +-
.../V3/V20250425/MapperProfile.cs | 11 -
.../V3/V20250627/ApiMapper.cs | 199 ++++++++++++++++++
.../V20250627/Controllers/PersonController.cs | 4 +-
.../Controllers/PersonsController.cs | 10 +-
.../V3/V20250627/MapperProfile.cs | 22 --
.../V20250627/Responses/FindPersonResponse.cs | 2 -
.../Responses/FindPersonsResponse.cs | 5 -
.../V20250627/Responses/GetPersonResponse.cs | 6 -
.../Controllers/PersonsController.cs | 4 +-
.../Controllers/TrnRequestController.cs | 4 +-
.../packages.lock.json | 12 +-
.../packages.lock.json | 14 +-
.../packages.lock.json | 17 +-
78 files changed, 1326 insertions(+), 526 deletions(-)
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Mapping/OptionMapper.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240101/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240101/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240307/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240307/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240412/ApiMapper.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240416/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240416/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240606/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240606/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240814/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240814/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240912/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240920/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240920/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250203/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250203/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250327/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250327/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250425/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250425/MapperProfile.cs
create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250627/ApiMapper.cs
delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20250627/MapperProfile.cs
diff --git a/TeachingRecordSystem/Directory.Packages.props b/TeachingRecordSystem/Directory.Packages.props
index 777b8f931d..46a8aeffa9 100644
--- a/TeachingRecordSystem/Directory.Packages.props
+++ b/TeachingRecordSystem/Directory.Packages.props
@@ -9,7 +9,7 @@
-
+
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Extensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Extensions.cs
index b631fb3b2f..f65c0f7156 100644
--- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Extensions.cs
+++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Extensions.cs
@@ -5,11 +5,8 @@
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
-using OneOf;
-using Optional;
using TeachingRecordSystem.Api.Infrastructure.ApplicationModel;
using TeachingRecordSystem.Api.Infrastructure.Filters;
-using TeachingRecordSystem.Api.Infrastructure.Mapping;
using TeachingRecordSystem.Api.Infrastructure.ModelBinding;
using TeachingRecordSystem.Api.Infrastructure.OpenApi;
using TeachingRecordSystem.Api.Infrastructure.RateLimiting;
@@ -47,14 +44,6 @@ public static IHostApplicationBuilder AddApiServices(this IHostApplicationBuilde
public static IServiceCollection AddApiServices(this IServiceCollection services, IConfiguration configuration, IHostEnvironment environment)
{
- services.Scan(scan =>
- {
- scan.FromAssemblies(typeof(Extensions).Assembly)
- .AddClasses(filter => filter.AssignableTo(typeof(ITypeConverter<,>)))
- .AsSelf()
- .WithTransientLifetime();
- });
-
services
.AddMvc(options =>
{
@@ -132,7 +121,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services
.AddWebhookOptions(configuration)
.AddOpenApi(configuration)
.AddFluentValidation()
- .AddAutoMapper()
+ .AddApiMappers()
.AddHttpContextAccessor()
.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining())
.AddSingleton()
@@ -156,16 +145,21 @@ public static IServiceCollection AddApiServices(this IServiceCollection services
return services;
}
- private static IServiceCollection AddAutoMapper(this IServiceCollection services)
+ private static IServiceCollection AddApiMappers(this IServiceCollection services)
{
- services.AddAutoMapper(cfg =>
- {
- cfg.AddMaps(typeof(Program).Assembly);
- cfg.CreateMap(typeof(Option<>), typeof(Option<>)).ConvertUsing(typeof(OptionToOptionTypeConverter<,>));
- cfg.CreateMap(typeof(OneOf<,>), typeof(OneOf<,>)).ConvertUsing(typeof(OneOfToOneOfTypeConverter<,,,>));
- })
- .AddTransient(typeof(WrapWithOptionValueConverter<>))
- .AddTransient(typeof(WrapWithOptionValueConverter<,>));
+ services
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton();
return services;
}
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/GlobalUsings.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/GlobalUsings.cs
index 80de4427a0..634d42c715 100644
--- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/GlobalUsings.cs
+++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/GlobalUsings.cs
@@ -1,3 +1,2 @@
-global using AutoMapper;
global using TeachingRecordSystem.Core.ApiSchema;
global using PostgresModels = TeachingRecordSystem.Core.DataStore.Postgres.Models;
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Mapping/OptionMapper.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Mapping/OptionMapper.cs
deleted file mode 100644
index 5c88122a11..0000000000
--- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Mapping/OptionMapper.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using OneOf;
-using Optional;
-
-namespace TeachingRecordSystem.Api.Infrastructure.Mapping;
-
-public class OptionToOptionTypeConverter : ITypeConverter