From 66dc5e3e3828e9759482338fa3ce1b880037fb45 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Fri, 26 Jan 2024 07:46:23 +0300 Subject: [PATCH] refactor: rewrite the configuration for new tables --- .../Schedule/DayConfiguration.cs | 32 --------------- .../Schedule/DisciplineConfiguration.cs | 18 +++++++++ .../Schedule/FacultyConfiguration.cs | 2 + .../LessonAssociationConfiguration.cs | 40 +++++++++++++++++++ .../Schedule/LessonConfiguration.cs | 27 ++++++++++++- .../LessonToTypeOfOccupationConfiguration.cs | 31 -------------- .../ProfessorToLessonConfiguration.cs | 39 ------------------ .../Schedule/TypeOfOccupationConfiguration.cs | 2 +- 8 files changed, 86 insertions(+), 105 deletions(-) delete mode 100644 Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs create mode 100644 Persistence/EntityTypeConfigurations/Schedule/DisciplineConfiguration.cs create mode 100644 Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs delete mode 100644 Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs delete mode 100644 Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs diff --git a/Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs deleted file mode 100644 index 486013e..0000000 --- a/Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs +++ /dev/null @@ -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 -{ - public void Configure(EntityTypeBuilder 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(d => d.LessonId) - .OnDelete(DeleteBehavior.Restrict); - } -} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/DisciplineConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/DisciplineConfiguration.cs new file mode 100644 index 0000000..f92ac02 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/DisciplineConfiguration.cs @@ -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 +{ + public void Configure(EntityTypeBuilder 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(); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/FacultyConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/FacultyConfiguration.cs index fccac7f..d61fce5 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/FacultyConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/FacultyConfiguration.cs @@ -15,6 +15,8 @@ public class FacultyConfiguration : IEntityTypeConfiguration builder.Property(f => f.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(256); + builder.Property(f => f.CampusId).HasColumnType("INTEGER"); + builder .HasOne(f => f.Campus) .WithMany(c => c.Faculties) diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs new file mode 100644 index 0000000..44152dd --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs @@ -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 +{ + public void Configure(EntityTypeBuilder 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); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs index 82885d4..a3e878a 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs @@ -13,8 +13,31 @@ public class LessonConfiguration : IEntityTypeConfiguration builder.HasIndex(l => l.Id).IsUnique(); 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.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); } } \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs deleted file mode 100644 index dfe7010..0000000 --- a/Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs +++ /dev/null @@ -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 -{ - public void Configure(EntityTypeBuilder 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); - } -} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs deleted file mode 100644 index 02ab493..0000000 --- a/Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs +++ /dev/null @@ -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 -{ - public void Configure(EntityTypeBuilder 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); - } -} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs index 24f3b55..82c0b61 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs @@ -13,7 +13,7 @@ public class TypeOfOccupationConfiguration : IEntityTypeConfiguration t.Id).IsUnique(); 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.FullName).HasColumnType("TEXT").HasMaxLength(64); } } \ No newline at end of file