Skip to content

Commit 2a75057

Browse files
committed
Set Person.Trn to be non-nullable
1 parent 0d3fb46 commit 2a75057

File tree

42 files changed

+21432
-1547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+21432
-1547
lines changed

TeachingRecordSystem/src/TeachingRecordSystem.Api/V1/Handlers/GetTeacherHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task<GetTeacherResponse> Handle(GetTeacherRequest request, Cancella
2323
var matched = await dbContext.Persons.FromSql(
2424
$"""
2525
SELECT * FROM persons
26-
WHERE status = 0 AND trn IS NOT NULL AND
26+
WHERE status = 0 AND
2727
date_of_birth = {birthDate}::date AND (
2828
trn = {request.Trn} OR
2929
(national_insurance_numbers && array_remove(ARRAY[{nationalInsuranceNumber}]::varchar[], null) COLLATE "case_insensitive")

TeachingRecordSystem/src/TeachingRecordSystem.Api/V2/Handlers/FindTeachersHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ await HandleDefaultRequestAsync() :
2020
{
2121
Results = result.Select(p => new FindTeacherResult
2222
{
23-
Trn = p.Trn!,
23+
Trn = p.Trn,
2424
EmailAddresses = !string.IsNullOrEmpty(p.EmailAddress) ? [p.EmailAddress] : [],
2525
FirstName = p.FirstName,
2626
MiddleName = p.MiddleName,
@@ -101,7 +101,7 @@ SELECT p.* FROM matches m
101101
file static class Extensions
102102
{
103103
public static IQueryable<PostgresModels.Person> ApplyBaseFilters(this IQueryable<PostgresModels.Person> query) =>
104-
query.Include(p => p.Alerts).Where(p => p.Trn != null && p.Status == PersonStatus.Active);
104+
query.Include(p => p.Alerts).Where(p => p.Status == PersonStatus.Active);
105105

106106
public static IEnumerable<string> ExceptEmpty(this IEnumerable<string> source) =>
107107
source.Where(v => !string.IsNullOrEmpty(v));

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/FindPersonsBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ protected async Task<FindPersonsResult> CreateResultAsync(IReadOnlyCollection<Gu
3535
.Include(p => p.Qualifications!).AsSplitQuery()
3636
.Include(p => p.PreviousNames).AsSplitQuery()
3737
.Where(p => matchedPersonIds.Contains(p.PersonId))
38-
.Where(p => p.Trn != null)
3938
.ToDictionaryAsync(p => p.PersonId, p => p);
4039

4140
var items = await matchedPersonIds
@@ -44,7 +43,7 @@ protected async Task<FindPersonsResult> CreateResultAsync(IReadOnlyCollection<Gu
4443
.Select(id => persons[id])
4544
.SelectAwait(async person => new FindPersonsResultItem()
4645
{
47-
Trn = person.Trn!,
46+
Trn = person.Trn,
4847
DateOfBirth = person.DateOfBirth!.Value,
4948
FirstName = person.FirstName,
5049
MiddleName = person.MiddleName,

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/GetPerson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public async Task<ApiResult<GetPersonResult>> ExecuteAsync(GetPersonCommand comm
272272

273273
return new GetPersonResult()
274274
{
275-
Trn = person.Trn!,
275+
Trn = person.Trn,
276276
FirstName = person.FirstName,
277277
MiddleName = person.MiddleName,
278278
LastName = person.LastName,

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/GetPersonHelper.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using OneOf;
32
using TeachingRecordSystem.Core.DataStore.Postgres;
43

@@ -42,8 +41,6 @@ where p.merged_with_person_id is null
4241
return ApiError.RecordIsNotActive(trn);
4342
}
4443

45-
Debug.Assert(person.Trn is not null);
46-
4744
if (person.Trn != trn)
4845
{
4946
return ApiError.RecordIsMerged(trn, person.Trn!);

TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Controllers/OAuth2Controller.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Security.Claims;
2-
using Dfe.Analytics;
32
using Dfe.Analytics.AspNetCore;
43
using Microsoft.AspNetCore;
54
using Microsoft.AspNetCore.Authentication;
@@ -10,6 +9,7 @@
109
using OpenIddict.Server.AspNetCore;
1110
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.Security;
1211
using TeachingRecordSystem.Core.DataStore.Postgres;
12+
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
1313
using static OpenIddict.Abstractions.OpenIddictConstants;
1414

1515
namespace TeachingRecordSystem.AuthorizeAccess.Controllers;
@@ -42,7 +42,7 @@ public async Task<IActionResult> AuthorizeAsync()
4242
var clientId = request.ClientId!;
4343
var client = await dbContext.ApplicationUsers.SingleAsync(u => u.ClientId == clientId);
4444

45-
if (HttpContext.GetWebRequestEvent() is Event webRequestEvent)
45+
if (HttpContext.GetWebRequestEvent() is Dfe.Analytics.Event webRequestEvent)
4646
{
4747
webRequestEvent.Data[DfeAnalyticsEventDataKeys.ApplicationUserId] = [client.UserId.ToString()];
4848
}
@@ -150,9 +150,9 @@ public async Task<IActionResult> UserInfoAsync()
150150
.Include(o => o.Person)
151151
.SingleAsync(u => u.Subject == subject);
152152

153-
if (oneLoginUser.Person?.Trn is string trn)
153+
if (oneLoginUser.Person is Person p)
154154
{
155-
claims.Add(ClaimTypes.Trn, trn);
155+
claims.Add(ClaimTypes.Trn, p.Trn);
156156
}
157157

158158
if (User.HasScope(Scopes.Email))

TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/DebugIdentity.cshtml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public async Task<IActionResult> OnPostAsync()
110110

111111
if (_oneLoginUser!.PersonId is not null && !DetachPerson)
112112
{
113-
await JourneyInstance!.UpdateStateAsync(state => helper.Complete(state, _oneLoginUser.Person!.Trn!));
113+
await JourneyInstance!.UpdateStateAsync(state => helper.Complete(state, _oneLoginUser.Person!.Trn));
114114
return GetNextPage();
115115
}
116116

@@ -167,5 +167,5 @@ public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingConte
167167
await base.OnPageHandlerExecutionAsync(context, next);
168168
}
169169

170-
public record PersonInfo(Guid PersonId, string? Trn, string FirstName, string LastName, DateOnly? DateOfBirth, string? NationalInsuranceNumber);
170+
public record PersonInfo(Guid PersonId, string Trn, string FirstName, string LastName, DateOnly? DateOfBirth, string? NationalInsuranceNumber);
171171
}

TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/SignInJourneyHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ await journeyInstance.UpdateStateAsync(state =>
247247
var matchedDateOfBirth = verifiedDatesOfBirth.FirstOrDefault(dob => dob == getAnIdentityPerson.DateOfBirth);
248248
if (matchedLastName == default || matchedDateOfBirth == default)
249249
{
250-
return new(getAnIdentityPerson.PersonId, getAnIdentityPerson.Trn!, MatchRoute: null, MatchedAttributes: null);
250+
return new(getAnIdentityPerson.PersonId, getAnIdentityPerson.Trn, MatchRoute: null, MatchedAttributes: null);
251251
}
252252
var matchedAttributes = new Dictionary<PersonMatchedAttribute, string>()
253253
{
@@ -262,7 +262,7 @@ await journeyInstance.UpdateStateAsync(state =>
262262
await idDbContext.SaveChangesAsync();
263263
}
264264

265-
return new(getAnIdentityPerson.PersonId, getAnIdentityPerson.Trn!, MatchRoute: matchRoute, matchedAttributes);
265+
return new(getAnIdentityPerson.PersonId, getAnIdentityPerson.Trn, MatchRoute: matchRoute, matchedAttributes);
266266
}
267267
}
268268

@@ -356,7 +356,6 @@ public async Task<bool> TryMatchToTeachingRecordAsync(JourneyInstance<SignInJour
356356
return null;
357357
}
358358
Debug.Assert(trnRequestMetadata.ResolvedPersonId.HasValue);
359-
Debug.Assert(resolvedPerson.Trn is not null);
360359

361360
oneLoginUser.SetVerified(
362361
verifiedOn: trnRequestMetadata.CreatedOn,

TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/Mappings/PersonMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void Configure(EntityTypeBuilder<Person> builder)
1212
builder.HasQueryFilter(p => p.Status == PersonStatus.Active);
1313
builder.HasIndex(p => p.DqtContactId).HasFilter("dqt_contact_id is not null").IsUnique();
1414
builder.HasIndex(p => p.MergedWithPersonId).HasFilter("merged_with_person_id is not null");
15-
builder.HasIndex(p => p.Trn).HasFilter("trn is not null").IsUnique();
15+
builder.HasIndex(p => p.Trn).IsUnique();
1616
builder.Property(p => p.Trn).HasMaxLength(Person.TrnExactLength).IsFixedLength();
1717
builder.Property(p => p.FirstName).HasMaxLength(Person.FirstNameMaxLength).UseCollation(Collations.CaseInsensitive);
1818
builder.Property(p => p.MiddleName).HasMaxLength(Person.MiddleNameMaxLength).UseCollation(Collations.CaseInsensitive);

0 commit comments

Comments
 (0)