Skip to content

Commit

Permalink
Add navigation properties to Alert models (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Oct 3, 2024
1 parent a1f8d16 commit 5f8df7a
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion TeachingRecordSystem/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageVersion Include="DistributedLock.Azure" Version="1.0.0" />
<PackageVersion Include="DistributedLock.FileSystem" Version="1.0.2" />
<PackageVersion Include="EFCore.NamingConventions" Version="8.0.3" />
<PackageVersion Include="EntityFrameworkCore.Projectables" Version="3.0.4" />
<PackageVersion Include="Faker.Net" Version="2.0.154" />
<PackageVersion Include="FakeXrmEasy.v9" Version="3.5.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
Expand Down Expand Up @@ -98,4 +99,4 @@
<PackageVersion Include="Xunit.DependencyInjection" Version="8.9.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public void Configure(EntityTypeBuilder<Alert> builder)
builder.Property(x => x.PersonId).IsRequired();
builder.Property(x => x.Details);
builder.HasIndex(x => x.AlertTypeId).HasDatabaseName(Alert.AlertTypeIdIndexName);
builder.HasOne<AlertType>().WithMany().HasForeignKey(x => x.AlertTypeId).HasConstraintName(Alert.AlertTypeForeignKeyName);
builder.HasOne<AlertType>(x => x.AlertType).WithMany().HasForeignKey(x => x.AlertTypeId).HasConstraintName(Alert.AlertTypeForeignKeyName);
builder.HasIndex(x => x.PersonId).HasDatabaseName(Alert.PersonIdIndexName);
builder.HasOne<Person>().WithMany().HasForeignKey(x => x.PersonId).HasConstraintName(Alert.PersonForeignKeyName);
builder.HasOne<Person>().WithMany(p => p.Alerts).HasForeignKey(x => x.PersonId).HasConstraintName(Alert.PersonForeignKeyName);
builder.Ignore(x => x.IsActive);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Configure(EntityTypeBuilder<AlertType> builder)
builder.Property(x => x.IsActive).IsRequired();
builder.HasIndex(x => x.AlertCategoryId).HasDatabaseName(AlertType.AlertCategoryIdIndexName);
builder.HasIndex(x => x.DisplayOrder).HasDatabaseName(AlertType.DisplayOrderIndexName).IsUnique();
builder.HasOne<AlertCategory>().WithMany(c => c.AlertTypes).HasForeignKey(x => x.AlertCategoryId).HasConstraintName(AlertType.AlertCategoryForeignKeyName);
builder.HasOne<AlertCategory>(x => x.AlertCategory).WithMany(c => c.AlertTypes).HasForeignKey(x => x.AlertCategoryId).HasConstraintName(AlertType.AlertCategoryForeignKeyName);
builder.HasData(
new AlertType { AlertTypeId = Guid.Parse("2ca98658-1d5b-49d5-b05f-cc08c8b8502c"), AlertCategoryId = Guid.Parse("ee78d44d-abf8-44a9-b22b-87a821f8d3c9"), Name = "Teacher sanctioned in other EEA member state", DqtSanctionCode = "T8", ProhibitionLevel = ProhibitionLevel.Notify, InternalOnly = true, IsActive = true, DisplayOrder = 1 },
new AlertType { AlertTypeId = Guid.Parse("9fafaa80-f9f8-44a0-b7b3-cffedcbe0298"), AlertCategoryId = Guid.Parse("0ae0707b-1503-477d-bc0f-1505ed95dbdf"), Name = "Failed induction", DqtSanctionCode = "C2", ProhibitionLevel = ProhibitionLevel.Teaching, InternalOnly = false, IsActive = true, DisplayOrder = 2 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Configure(EntityTypeBuilder<Qualification> builder)
builder.HasQueryFilter(q => EF.Property<DateTime?>(q, nameof(Qualification.DeletedOn)) == null);
builder.HasDiscriminator(q => q.QualificationType)
.HasValue<MandatoryQualification>(QualificationType.MandatoryQualification);
builder.HasOne<Person>().WithMany().HasForeignKey(q => q.PersonId).HasConstraintName(Qualification.PersonForeignKeyName);
builder.HasOne<Person>().WithMany(p => p.Qualifications).HasForeignKey(q => q.PersonId).HasConstraintName(Qualification.PersonForeignKeyName);
builder.HasIndex(q => q.PersonId);
builder.HasIndex(q => q.DqtQualificationId).HasFilter("dqt_qualification_id is not null").IsUnique();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using EntityFrameworkCore.Projectables;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Models;

public class Alert
Expand All @@ -8,6 +10,7 @@ public class Alert
public const string PersonForeignKeyName = "fk_alerts_person";

public required Guid AlertId { get; init; }
public AlertType AlertType { get; } = null!;
public required Guid AlertTypeId { get; init; }
public required Guid PersonId { get; init; }
public required string? Details { get; init; }
Expand All @@ -17,6 +20,7 @@ public class Alert
public required DateTime CreatedOn { get; init; }
public required DateTime UpdatedOn { get; set; }
public DateTime? DeletedOn { get; set; }
[Projectable] public bool IsActive => EndDate == null;

public Guid? DqtSanctionId { get; set; }
public int? DqtState { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class AlertType

public required Guid AlertTypeId { get; init; }
public required Guid AlertCategoryId { get; init; }
public AlertCategory AlertCategory { get; } = null!;
public required string Name { get; init; }
public required string? DqtSanctionCode { get; init; }
public required ProhibitionLevel ProhibitionLevel { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Person
public required DateOnly? DateOfBirth { get; set; } // A few DQT records in prod have a null DOB
public string? EmailAddress { get; set; }
public string? NationalInsuranceNumber { get; set; }
public ICollection<Qualification> Qualifications { get; } = new List<Qualification>();
public ICollection<Alert> Alerts { get; } = new List<Alert>();

public Guid? DqtContactId { get; init; }
public DateTime? DqtFirstSync { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public static void ConfigureOptions(DbContextOptionsBuilder optionsBuilder, stri
optionsBuilder
.UseSnakeCaseNamingConvention()
.UseOpenIddict<Guid>()
.AddInterceptors(new PopulateOidcApplicationInterceptor());
.AddInterceptors(new PopulateOidcApplicationInterceptor())
.UseProjectables();
}

public void AddEvent(EventBase @event, DateTime? inserted = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<PackageReference Include="DistributedLock.Azure" />
<PackageReference Include="DistributedLock.FileSystem" />
<PackageReference Include="EFCore.NamingConventions" />
<PackageReference Include="EntityFrameworkCore.Projectables" />
<PackageReference Include="Google.Cloud.Storage.V1" />
<PackageReference Include="GovukNotify" />
<PackageReference Include="Hangfire.Core" />
Expand Down

0 comments on commit 5f8df7a

Please sign in to comment.