Skip to content

Commit 420b65f

Browse files
authored
APPT-2150 - Removing auto mapper as a dependency (#1620)
# Description Removing Auto Mapper as a dependency on the solution and updating all mappings in the persistence layer. There should be no functional changes so also ensuring all existing integration tests and playwright tests pass. Fixes # (issue) # Checklist: - [ ] My work is behind a feature toggle (if appropriate) - [ ] If my work is behind a feature toggle, I've added a full suite of tests for both the ON and OFF state - [ ] The ticket number is in the Pull Request title, with format "APPT-XXX: My Title Here" - [x] I have ran npm tsc / lint (in the future these will be ran automatically) - [x] My code generates no new .NET warnings (in the future these will be treated as errors) - [ ] If I've added a new Function, it is disabled in all but one of the terraform groups (e.g. http_functions) - [ ] If I've added a new Function, it has both unit and integration tests. Any request body validators have unit tests also - [ ] If I've made UI changes, I've added appropriate Playwright and Jest tests - [ ] If I've added/updated an end-point, I've added the appropriate annotations and tested the Swagger documentation reflects the change
1 parent 35e18f1 commit 420b65f

32 files changed

Lines changed: 620 additions & 469 deletions

src/api/Nhs.Appointments.Api/FunctionConfigurationExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ public static IFunctionsWorkerApplicationBuilder ConfigureFunctionDependencies(
117117
.AddTransient<IClinicalServiceProvider, ClinicalServiceProvider>()
118118
.AddScoped<IMetricsRecorder, InMemoryMetricsRecorder>()
119119
.AddUserNotifications(configuration)
120-
.AddAutoMapper(typeof(CosmosAutoMapperProfile))
121120
.AddTransient<IAdminUserDataImportHandler, AdminUserDataImportHandler>()
122121
.AddTransient<ISiteStatusDataImportHandler, SiteStatusDataImportHandler>()
123122
.AddTransient<IAvailableSlotsFilter, AvailableSlotsFilter>()

src/api/Nhs.Appointments.Core/Bookings/BookingAvailabilityStateService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ private BookingAvailabilityState BuildState(IEnumerable<Booking> bookings, List<
156156

157157
var state = new BookingAvailabilityState();
158158

159+
var bookingsList = bookings.ToList();
160+
159161
//have to materialise to a list as we transform the data within
160162
var slotsList = sessions.SelectMany(session => session.ToSlots()).ToList();
161163

162-
var liveBookings = bookings.Where(x => _liveStatuses.Contains(x.Status));
164+
var liveBookings = bookingsList.Where(x => _liveStatuses.Contains(x.Status));
163165

164166
List<DayAvailabilitySummary> daySummaries = [];
165167

@@ -249,7 +251,7 @@ private BookingAvailabilityState BuildState(IEnumerable<Booking> bookings, List<
249251
state.AvailableSlots = slotsList.Where(s => s.Capacity > 0);
250252
break;
251253
case BookingAvailabilityStateReturnType.Summary:
252-
state.Summary = GenerateSummary(bookings, daySummaries);
254+
state.Summary = GenerateSummary(bookingsList, daySummaries);
253255
break;
254256
case BookingAvailabilityStateReturnType.Recalculations:
255257
case BookingAvailabilityStateReturnType.SessionUpdateProposalMetrics:

src/api/Nhs.Appointments.Persistance/AccessibilityDefinitionsStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AccessibilityDefinitionsStore(ITypedDocumentCosmosStore<Accessibili
88
private const string AccessibilitySetsDocumentId = "accessibilities";
99
public async Task<IEnumerable<AccessibilityDefinition>> GetAccessibilityDefinitionsDocument()
1010
{
11-
var document = await cosmosStore.GetDocument<AccessibilityDefinitionsDocument>(AccessibilitySetsDocumentId);
11+
var document = await cosmosStore.GetDocument(AccessibilitySetsDocumentId);
1212
return document.AccessibilityDefinitions;
1313
}
1414
}

src/api/Nhs.Appointments.Persistance/AggregationStore.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ public class AggregationStore(ITypedDocumentCosmosStore<AggregationDocument> sto
1111

1212
public async Task<Aggregation> GetLastRun()
1313
{
14-
return await Store.GetByIdOrDefaultAsync<Aggregation>(AggregationDocumentId);
14+
var document = await Store.GetByIdOrDefaultAsync(AggregationDocumentId);
15+
return document is null ? null : MapToAggregation(document);
1516
}
1617

1718
public async Task SetLastRun(DateTimeOffset lastTriggerUtcDate, DateOnly aggregationFrom, DateOnly aggregationTo, DateOnly dateUntilAggregated)
1819
{
19-
var document = await Store.GetByIdOrDefaultAsync<AggregationDocument>(AggregationDocumentId);
20+
var document = await Store.GetByIdOrDefaultAsync(AggregationDocumentId);
2021

2122
if (document is not null)
2223
{
@@ -41,4 +42,15 @@ await Store.WriteAsync(new AggregationDocument
4142
}
4243
});
4344
}
45+
46+
private static Aggregation MapToAggregation(AggregationDocument document)
47+
{
48+
return new Aggregation
49+
{
50+
LastTriggeredUtcDate = document.LastTriggeredUtcDate,
51+
FromDateOnly = document.LastRunMetaData.FromDateOnly,
52+
ToDateOnly = document.LastRunMetaData.ToDateOnly,
53+
LastRanToDateOnly = document.LastRunMetaData.LastRanToDateOnly
54+
};
55+
}
4456
}

src/api/Nhs.Appointments.Persistance/AvailabilityCreatedEventDocumentStore.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,19 @@ public async Task<IEnumerable<AvailabilityCreatedEvent>> GetAvailabilityCreatedE
5050
{
5151
var docType = documentStore.GetDocumentType();
5252

53-
return await documentStore.RunQueryAsync<AvailabilityCreatedEvent>(b =>
53+
var documents = await documentStore.RunQueryAsync(b =>
5454
b.DocumentType == docType
5555
&& b.Site == site);
56+
57+
return documents.Any() ? documents.Select(d => new AvailabilityCreatedEvent()
58+
{
59+
Created = d.Created,
60+
By = d.By,
61+
Site = d.Site,
62+
Template = d.Template,
63+
From = d.From,
64+
To = d.To,
65+
Sessions = d.Sessions
66+
}) : [];
5667
}
57-
}
68+
}

src/api/Nhs.Appointments.Persistance/AvailabilityDocumentStore.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public async Task<IEnumerable<SessionInstance>> GetSessions(string site, DateOnl
1212
{
1313
var results = new List<SessionInstance>();
1414
var docType = documentStore.GetDocumentType();
15-
var documents = await documentStore.RunQueryAsync<DailyAvailabilityDocument>(b =>
15+
var documents = await documentStore.RunQueryAsync(b =>
1616
b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= to);
1717

1818
foreach (var day in documents)
@@ -65,8 +65,9 @@ public async Task ApplyAvailabilityTemplate(string site, DateOnly date, Session[
6565
public async Task<IEnumerable<DailyAvailability>> GetDailyAvailability(string site, DateOnly from, DateOnly to)
6666
{
6767
var docType = documentStore.GetDocumentType();
68-
return await documentStore.RunQueryAsync<DailyAvailability>(b =>
68+
var availabilityDocuments = await documentStore.RunQueryAsync(b =>
6969
b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= to);
70+
return availabilityDocuments.Select(MapToDailyAvailability) ?? [];
7071
}
7172

7273
public async Task<SessionInstance> CancelSession(string site, DateOnly date, Session session)
@@ -89,9 +90,7 @@ public async Task<SessionInstance> CancelSession(string site, DateOnly date, Ses
8990
return new SessionInstance(dayDocument.Date.ToDateTime(session.From),
9091
dayDocument.Date.ToDateTime(session.Until))
9192
{
92-
Services = session.Services,
93-
SlotLength = session.SlotLength,
94-
Capacity = session.Capacity,
93+
Services = session.Services, SlotLength = session.SlotLength, Capacity = session.Capacity,
9594
};
9695
}
9796

@@ -118,7 +117,6 @@ SELECT VALUE svc FROM session IN bd.sessions JOIN svc IN session.services
118117
.WithParameter("@requestedServiceCount", services.Count);
119118

120119
var dailyAvailabilityCount = (await documentStore.RunSqlQueryAsync<int>(queryDef)).Single();
121-
122120
return dailyAvailabilityCount > 0;
123121
}
124122

@@ -134,7 +132,7 @@ public async Task CancelDayAsync(string site, DateOnly date)
134132
public async Task<OperationResult> EditSessionsAsync(string site, DateOnly from, DateOnly until, Session sessionMatcher, Session sessionReplacement)
135133
{
136134
var docType = documentStore.GetDocumentType();
137-
var documents = await documentStore.RunQueryAsync<DailyAvailabilityDocument>(b => b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= until);
135+
var documents = await documentStore.RunQueryAsync(b => b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= until);
138136

139137
if (documents == null || !documents.Any())
140138
{
@@ -152,7 +150,7 @@ public async Task<OperationResult> EditSessionsAsync(string site, DateOnly from,
152150
public async Task<OperationResult> CancelMultipleSessions(string site, DateOnly from, DateOnly until, Session sessionMatcher = null)
153151
{
154152
var docType = documentStore.GetDocumentType();
155-
var documents = await documentStore.RunQueryAsync<DailyAvailabilityDocument>(b => b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= until);
153+
var documents = await documentStore.RunQueryAsync(b => b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= until);
156154

157155
if (documents == null || !documents.Any())
158156
{
@@ -175,7 +173,7 @@ public async Task<OperationResult> CancelMultipleSessions(string site, DateOnly
175173
public async Task<int> CancelAllSessionsInDateRange(string site, DateOnly from, DateOnly until)
176174
{
177175
var docType = documentStore.GetDocumentType();
178-
var documents = await documentStore.RunQueryAsync<DailyAvailabilityDocument>(b => b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= until);
176+
var documents = await documentStore.RunQueryAsync(b => b.DocumentType == docType && b.Site == site && b.Date >= from && b.Date <= until);
179177

180178
if (documents is null || !documents.Any())
181179
{
@@ -231,7 +229,7 @@ private async Task PatchAvailabilityDocument(string documentId, Session[] sessio
231229

232230
private async Task<DailyAvailabilityDocument> GetOrDefaultAsync(string documentId, string partitionKey)
233231
{
234-
return await documentStore.GetByIdOrDefaultAsync<DailyAvailabilityDocument>(documentId, partitionKey);
232+
return await documentStore.GetByIdOrDefaultAsync(documentId, partitionKey);
235233
}
236234

237235
private static Session FindMatchingSession(List<Session> sessions, Session sessionToMatch)
@@ -272,4 +270,20 @@ private static bool SessionsMatch(Session session, Session sessionToMatch)
272270
&& session.Capacity == sessionToMatch.Capacity
273271
&& session.Services.SequenceEqual(sessionToMatch.Services);
274272
}
273+
274+
private static DailyAvailability MapToDailyAvailability(DailyAvailabilityDocument document)
275+
{
276+
return document is null ? null : new DailyAvailability
277+
{
278+
Date = document.Date,
279+
Sessions = [.. document.Sessions.Select(s => new Session
280+
{
281+
From = s.From,
282+
Until = s.Until,
283+
Services = s.Services,
284+
SlotLength = s.SlotLength,
285+
Capacity = s.Capacity
286+
})]
287+
};
288+
}
275289
}

0 commit comments

Comments
 (0)