refactor: rewrite the configuration for new tables
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m21s

This commit is contained in:
Polianin Nikita 2024-01-26 07:46:23 +03:00
parent 9493d4340f
commit 66dc5e3e38
8 changed files with 86 additions and 105 deletions

View File

@ -1,32 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mirea.Api.DataAccess.Domain.Schedule;
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
public class DayConfiguration : IEntityTypeConfiguration<Day>
{
public void Configure(EntityTypeBuilder<Day> builder)
{
builder.ToTable(nameof(Day));
builder.HasKey(d => d.Id);
builder.HasIndex(d => d.Id).IsUnique();
builder.Property(d => d.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(d => d.PairNumber).HasColumnType("INTEGER").IsRequired();
builder.Property(d => d.Index).HasColumnType("INTEGER").IsRequired();
builder.Property(d => d.GroupId).HasColumnType("INTEGER").IsRequired();
builder.Property(d => d.LessonId).HasColumnType("INTEGER").IsRequired();
builder
.HasOne(d => d.Group)
.WithMany(g => g.Days)
.HasForeignKey(d => d.GroupId)
.OnDelete(DeleteBehavior.Restrict);
builder
.HasOne(d => d.Lesson)
.WithOne(l => l.Day)
.HasForeignKey<Day>(d => d.LessonId)
.OnDelete(DeleteBehavior.Restrict);
}
}

View File

@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mirea.Api.DataAccess.Domain.Schedule;
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
public class DisciplineConfiguration : IEntityTypeConfiguration<Discipline>
{
public void Configure(EntityTypeBuilder<Discipline> builder)
{
builder.ToTable(nameof(Discipline));
builder.HasKey(d => d.Id);
builder.HasIndex(d => d.Id).IsUnique();
builder.Property(d => d.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(d => d.Name).HasColumnType("TEXT").HasMaxLength(256).IsRequired();
}
}

View File

@ -15,6 +15,8 @@ public class FacultyConfiguration : IEntityTypeConfiguration<Faculty>
builder.Property(f => f.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(256); builder.Property(f => f.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(256);
builder.Property(f => f.CampusId).HasColumnType("INTEGER");
builder builder
.HasOne(f => f.Campus) .HasOne(f => f.Campus)
.WithMany(c => c.Faculties) .WithMany(c => c.Faculties)

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mirea.Api.DataAccess.Domain.Schedule;
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
public class LessonAssociationConfiguration : IEntityTypeConfiguration<LessonAssociation>
{
public void Configure(EntityTypeBuilder<LessonAssociation> builder)
{
builder.ToTable(nameof(LessonAssociation));
builder.HasKey(l => l.Id);
builder.HasIndex(l => l.Id).IsUnique();
builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(l => l.LinkToMeet).HasColumnType("TEXT").HasMaxLength(512);
builder.Property(l => l.LessonId).HasColumnType("INTEGER").IsRequired();
builder.Property(l => l.ProfessorId).HasColumnType("INTEGER");
builder.Property(l => l.LectureHallId).HasColumnType("INTEGER");
builder
.HasOne(l => l.Lesson)
.WithMany(d => d.LessonAssociations)
.HasForeignKey(l => l.LessonId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(l => l.Professor)
.WithMany(p => p.LessonAssociations)
.HasForeignKey(l => l.ProfessorId)
.OnDelete(DeleteBehavior.SetNull);
builder
.HasOne(l => l.LectureHall)
.WithMany(l => l.LessonAssociations)
.HasForeignKey(l => l.LectureHallId)
.OnDelete(DeleteBehavior.SetNull);
}
}

View File

@ -13,8 +13,31 @@ public class LessonConfiguration : IEntityTypeConfiguration<Lesson>
builder.HasIndex(l => l.Id).IsUnique(); builder.HasIndex(l => l.Id).IsUnique();
builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(l => l.Discipline).HasColumnType("TEXT").IsRequired().HasMaxLength(256);
builder.Property(l => l.IsEven).HasColumnType("BIT").IsRequired(); builder.Property(l => l.IsEven).HasColumnType("BIT").IsRequired();
builder.Property(l => l.DayOfWeek).HasColumnType("INTEGER").IsRequired();
builder.Property(l => l.PairNumber).HasColumnType("INTEGER").IsRequired();
builder.Property(l => l.GroupId).HasColumnType("INTEGER").IsRequired();
builder.Property(l => l.TypeOfOccupationId).HasColumnType("INTEGER").IsRequired();
builder.Property(l => l.DisciplineId).HasColumnType("INTEGER").IsRequired();
builder
.HasOne(l => l.Group)
.WithMany(g => g.Lessons)
.HasForeignKey(d => d.GroupId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(l => l.TypeOfOccupation)
.WithMany(t => t.Lessons)
.HasForeignKey(d => d.TypeOfOccupationId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(l => l.Discipline)
.WithMany(d => d.Lessons)
.HasForeignKey(l => l.DisciplineId)
.OnDelete(DeleteBehavior.Cascade);
} }
} }

View File

@ -1,31 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mirea.Api.DataAccess.Domain.Schedule;
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
public class LessonToTypeOfOccupationConfiguration : IEntityTypeConfiguration<LessonToTypeOfOccupation>
{
public void Configure(EntityTypeBuilder<LessonToTypeOfOccupation> builder)
{
builder.ToTable(nameof(LessonToTypeOfOccupation));
builder.HasKey(l => l.Id);
builder.HasIndex(l => l.Id).IsUnique();
builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(l => l.LessonId).HasColumnType("INTEGER").IsRequired();
builder.Property(l => l.TypeOfOccupationId).HasColumnType("INTEGER").IsRequired();
builder
.HasOne(l => l.Lesson)
.WithMany(l => l.TypeOfOccupations)
.HasForeignKey(l => l.LessonId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(l => l.TypeOfOccupation)
.WithMany(t => t.Lessons)
.HasForeignKey(l => l.TypeOfOccupationId)
.OnDelete(DeleteBehavior.Cascade);
}
}

View File

@ -1,39 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mirea.Api.DataAccess.Domain.Schedule;
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
public class ProfessorToLessonConfiguration : IEntityTypeConfiguration<ProfessorToLesson>
{
public void Configure(EntityTypeBuilder<ProfessorToLesson> builder)
{
builder.ToTable(nameof(ProfessorToLesson));
builder.HasKey(p => p.Id);
builder.HasIndex(p => p.Id).IsUnique();
builder.Property(p => p.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(l => l.LinkToMeet).HasColumnType("TEXT").HasMaxLength(512);
builder.Property(p => p.LessonId).HasColumnType("INTEGER").IsRequired();
builder.Property(p => p.ProfessorId).HasColumnType("INTEGER");
builder.Property(l => l.LectureHallId).HasColumnType("INTEGER");
builder
.HasOne(p => p.LectureHall)
.WithMany(l => l.ProfessorToLessons)
.HasForeignKey(l => l.LectureHallId)
.OnDelete(DeleteBehavior.SetNull);
builder
.HasOne(p => p.Lesson)
.WithMany(l => l.ProfessorToLesson)
.HasForeignKey(p => p.LessonId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(p => p.Professor)
.WithMany(p => p.ProfessorToLesson)
.HasForeignKey(p => p.ProfessorId)
.OnDelete(DeleteBehavior.Cascade);
}
}

View File

@ -13,7 +13,7 @@ public class TypeOfOccupationConfiguration : IEntityTypeConfiguration<TypeOfOccu
builder.HasIndex(t => t.Id).IsUnique(); builder.HasIndex(t => t.Id).IsUnique();
builder.Property(t => t.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); builder.Property(t => t.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
builder.Property(t => t.FullName).HasColumnType("TEXT").HasMaxLength(64);
builder.Property(t => t.ShortName).HasColumnType("TEXT").IsRequired().HasMaxLength(16); builder.Property(t => t.ShortName).HasColumnType("TEXT").IsRequired().HasMaxLength(16);
builder.Property(t => t.FullName).HasColumnType("TEXT").HasMaxLength(64);
} }
} }