Skip to content

Commit 1f768cb

Browse files
committed
Use sequential IDs for support task references
1 parent 8a63a3b commit 1f768cb

File tree

14 files changed

+21448
-108
lines changed

14 files changed

+21448
-108
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public async Task<IActionResult> OnPostAsync()
3636

3737
var supportTask = new SupportTask()
3838
{
39-
SupportTaskReference = SupportTask.GenerateSupportTaskReference(),
4039
CreatedOn = clock.UtcNow,
4140
UpdatedOn = clock.UtcNow,
4241
SupportTaskType = SupportTaskType.ConnectOneLoginUser,
@@ -65,19 +64,7 @@ await dbContext.AddEventAndBroadcastAsync(new LegacyEvents.SupportTaskCreatedEve
6564
SupportTask = EventModels.SupportTask.FromModel(supportTask)
6665
});
6766

68-
while (true)
69-
{
70-
try
71-
{
72-
await dbContext.SaveChangesAsync();
73-
break;
74-
}
75-
catch (Exception ex) when (ex.InnerException is PostgresException postgresException && postgresException.SqlState == PostgresErrorCodes.UniqueViolation)
76-
{
77-
supportTask.SupportTaskReference = SupportTask.GenerateSupportTaskReference();
78-
continue;
79-
}
80-
}
67+
await dbContext.SaveChangesAsync();
8168

8269
await JourneyInstance.UpdateStateAsync(state => state.HasPendingSupportRequest = true);
8370

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void Configure(EntityTypeBuilder<SupportTask> builder)
1212
builder.ToTable("support_tasks");
1313
builder.HasKey(p => p.SupportTaskReference);
1414
builder.HasQueryFilter(q => EF.Property<DateTime?>(q, nameof(SupportTask.DeletedOn)) == null);
15-
builder.Property(p => p.SupportTaskReference).HasMaxLength(16);
15+
builder.Property(p => p.SupportTaskReference).HasMaxLength(16).HasDefaultValueSql("'TRS-' || nextval('support_task_reference')::text");
1616
builder.HasOne(t => t.Person).WithMany().HasForeignKey(p => p.PersonId).HasConstraintName("fk_support_tasks_person");
1717
builder.HasIndex(t => t.OneLoginUserSubject);
1818
builder.HasIndex(t => t.PersonId);

0 commit comments

Comments
 (0)