Skip to content

Commit e52f705

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

File tree

14 files changed

+21448
-110
lines changed

14 files changed

+21448
-110
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.AspNetCore.Mvc.Filters;
44
using Microsoft.AspNetCore.Mvc.RazorPages;
5-
using Npgsql;
65
using TeachingRecordSystem.Core.DataStore.Postgres;
76
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
87
using TeachingRecordSystem.Core.Models.SupportTasks;
@@ -36,7 +35,6 @@ public async Task<IActionResult> OnPostAsync()
3635

3736
var supportTask = new SupportTask()
3837
{
39-
SupportTaskReference = SupportTask.GenerateSupportTaskReference(),
4038
CreatedOn = clock.UtcNow,
4139
UpdatedOn = clock.UtcNow,
4240
SupportTaskType = SupportTaskType.ConnectOneLoginUser,
@@ -65,19 +63,7 @@ await dbContext.AddEventAndBroadcastAsync(new LegacyEvents.SupportTaskCreatedEve
6563
SupportTask = EventModels.SupportTask.FromModel(supportTask)
6664
});
6765

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-
}
66+
await dbContext.SaveChangesAsync();
8167

8268
await JourneyInstance.UpdateStateAsync(state => state.HasPendingSupportRequest = true);
8369

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)