Skip to content

Commit

Permalink
Add alert tables to TRS database (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha authored Aug 15, 2024
1 parent ffc35b0 commit 6d90564
Show file tree
Hide file tree
Showing 11 changed files with 2,715 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ async Task<SanctionResult[]> GetSanctions()
.Where(s => Constants.ProhibitionSanctionCodes.Contains(s.SanctionCode))
.Select(s => new AlertInfo()
{
AlertType = AlertType.Prohibition,
AlertType = SharedModels.AlertType.Prohibition,
DqtSanctionCode = s.SanctionCode,
StartDate = s.Sanction.dfeta_StartDate?.ToDateOnlyWithDqtBstFix(isLocalTime: true),
EndDate = s.Sanction.dfeta_EndDate?.ToDateOnlyWithDqtBstFix(isLocalTime: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Mappings;

public class AlertCategoryMapping : IEntityTypeConfiguration<AlertCategory>
{
public void Configure(EntityTypeBuilder<AlertCategory> builder)
{
builder.ToTable("alert_categories");
builder.HasKey(x => x.AlertCategoryId);
builder.Property(x => x.Name).IsRequired().HasMaxLength(AlertCategory.NameMaxLength).UseCollation("case_insensitive");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Mappings;

public class AlertMapping : IEntityTypeConfiguration<Alert>
{
public void Configure(EntityTypeBuilder<Alert> builder)
{
builder.ToTable("alerts");
builder.HasKey(x => x.AlertId);
builder.HasQueryFilter(q => EF.Property<DateTime?>(q, nameof(Alert.DeletedOn)) == null);
builder.Property(x => x.AlertTypeId).IsRequired();
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.HasIndex(x => x.PersonId).HasDatabaseName(Alert.PersonIdIndexName);
builder.HasOne<Person>().WithMany().HasForeignKey(x => x.PersonId).HasConstraintName(Alert.PersonForeignKeyName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Mappings;

public class AlertTypeMapping : IEntityTypeConfiguration<AlertType>
{
public void Configure(EntityTypeBuilder<AlertType> builder)
{
builder.ToTable("alert_types");
builder.HasKey(x => x.AlertTypeId);
builder.Property(x => x.Name).IsRequired().HasMaxLength(AlertType.NameMaxLength).UseCollation("case_insensitive");
builder.HasIndex(x => x.AlertCategoryId).HasDatabaseName(AlertType.AlertCategoryIdIndexName);
builder.HasOne<AlertCategory>().WithMany().HasForeignKey(x => x.AlertCategoryId).HasConstraintName(AlertType.AlertCategoryForeignKeyName);
}
}
Loading

0 comments on commit 6d90564

Please sign in to comment.