diff --git a/Application/Interfaces/DbContexts/Schedule/IDayDbContext.cs b/Application/Interfaces/DbContexts/Schedule/IDisciplineDbContext.cs similarity index 61% rename from Application/Interfaces/DbContexts/Schedule/IDayDbContext.cs rename to Application/Interfaces/DbContexts/Schedule/IDisciplineDbContext.cs index f34d77a..6b30d92 100644 --- a/Application/Interfaces/DbContexts/Schedule/IDayDbContext.cs +++ b/Application/Interfaces/DbContexts/Schedule/IDisciplineDbContext.cs @@ -3,7 +3,7 @@ using Mirea.Api.DataAccess.Domain.Schedule; namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; -public interface IDayDbContext : IDbContextBase +public interface IDisciplineDbContext : IDbContextBase { - DbSet Days { get; set; } + DbSet Disciplines { get; set; } } \ No newline at end of file diff --git a/Application/Interfaces/DbContexts/Schedule/IProfessorToLessonDbContext.cs b/Application/Interfaces/DbContexts/Schedule/ILessonAssociationDbContext.cs similarity index 56% rename from Application/Interfaces/DbContexts/Schedule/IProfessorToLessonDbContext.cs rename to Application/Interfaces/DbContexts/Schedule/ILessonAssociationDbContext.cs index ba6aba5..2ec1af2 100644 --- a/Application/Interfaces/DbContexts/Schedule/IProfessorToLessonDbContext.cs +++ b/Application/Interfaces/DbContexts/Schedule/ILessonAssociationDbContext.cs @@ -3,7 +3,7 @@ using Mirea.Api.DataAccess.Domain.Schedule; namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; -public interface IProfessorToLessonDbContext : IDbContextBase +public interface ILessonAssociationDbContext : IDbContextBase { - DbSet ProfessorToLessons { get; set; } + DbSet LessonAssociations { get; set; } } \ No newline at end of file diff --git a/Application/Interfaces/DbContexts/Schedule/ILessonToTypeOfOccupationDbContext.cs b/Application/Interfaces/DbContexts/Schedule/ILessonToTypeOfOccupationDbContext.cs deleted file mode 100644 index 0dacc7e..0000000 --- a/Application/Interfaces/DbContexts/Schedule/ILessonToTypeOfOccupationDbContext.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Mirea.Api.DataAccess.Domain.Schedule; - -namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; - -public interface ILessonToTypeOfOccupationDbContext : IDbContextBase -{ - DbSet LessonToTypeOfOccupations { get; set; } -} \ No newline at end of file diff --git a/Domain/Schedule/Day.cs b/Domain/Schedule/Day.cs deleted file mode 100644 index 0da9657..0000000 --- a/Domain/Schedule/Day.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace Mirea.Api.DataAccess.Domain.Schedule; - -public class Day -{ - public int Id { get; set; } - public DayOfWeek Index { get; set; } - public int PairNumber { get; set; } - - public int LessonId { get; set; } - public Lesson? Lesson { get; set; } - public int GroupId { get; set; } - public Group? Group { get; set; } -} \ No newline at end of file diff --git a/Domain/Schedule/Discipline.cs b/Domain/Schedule/Discipline.cs new file mode 100644 index 0000000..1cdfec4 --- /dev/null +++ b/Domain/Schedule/Discipline.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Mirea.Api.DataAccess.Domain.Schedule; + +public class Discipline +{ + public int Id { get; set; } + public required string Name { get; set; } + + public List? Lessons { get; set; } +} \ No newline at end of file diff --git a/Domain/Schedule/Faculty.cs b/Domain/Schedule/Faculty.cs index 12dbcbe..cf87fa7 100644 --- a/Domain/Schedule/Faculty.cs +++ b/Domain/Schedule/Faculty.cs @@ -9,5 +9,6 @@ public class Faculty public int? CampusId { get; set; } public Campus? Campus { get; set; } + public List? Groups { get; set; } } \ No newline at end of file diff --git a/Domain/Schedule/Group.cs b/Domain/Schedule/Group.cs index 44c6b95..a27a819 100644 --- a/Domain/Schedule/Group.cs +++ b/Domain/Schedule/Group.cs @@ -9,5 +9,6 @@ public class Group public int? FacultyId { get; set; } public Faculty? Faculty { get; set; } - public List? Days { get; set; } + + public List? Lessons { get; set; } } \ No newline at end of file diff --git a/Domain/Schedule/LectureHall.cs b/Domain/Schedule/LectureHall.cs index 70b7249..855dc8c 100644 --- a/Domain/Schedule/LectureHall.cs +++ b/Domain/Schedule/LectureHall.cs @@ -7,7 +7,8 @@ public class LectureHall public int Id { get; set; } public required string Name { get; set; } - public List? ProfessorToLessons { get; set; } public int CampusId { get; set; } public Campus? Campus { get; set; } + + public List? LessonAssociations { get; set; } } \ No newline at end of file diff --git a/Domain/Schedule/Lesson.cs b/Domain/Schedule/Lesson.cs index 0851f0e..3ff5e52 100644 --- a/Domain/Schedule/Lesson.cs +++ b/Domain/Schedule/Lesson.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Mirea.Api.DataAccess.Domain.Schedule; @@ -6,9 +7,15 @@ public class Lesson { public int Id { get; set; } public bool IsEven { get; set; } - public required string Discipline { get; set; } + public DayOfWeek DayOfWeek { get; set; } + public int PairNumber { get; set; } - public List? TypeOfOccupations { get; set; } - public List? ProfessorToLesson { get; set; } - public Day? Day { get; set; } + public int GroupId { get; set; } + public Group? Group { get; set; } + public int TypeOfOccupationId { get; set; } + public TypeOfOccupation? TypeOfOccupation { get; set; } + public int DisciplineId { get; set; } + public Discipline? Discipline { get; set; } + + public List? LessonAssociations { get; set; } } \ No newline at end of file diff --git a/Domain/Schedule/ProfessorToLesson.cs b/Domain/Schedule/LessonAssociation.cs similarity index 92% rename from Domain/Schedule/ProfessorToLesson.cs rename to Domain/Schedule/LessonAssociation.cs index 17b287e..89b5651 100644 --- a/Domain/Schedule/ProfessorToLesson.cs +++ b/Domain/Schedule/LessonAssociation.cs @@ -1,11 +1,10 @@ namespace Mirea.Api.DataAccess.Domain.Schedule; -public class ProfessorToLesson +public class LessonAssociation { public int Id { get; set; } public string? LinkToMeet { get; set; } - public int LessonId { get; set; } public Lesson? Lesson { get; set; } public int? ProfessorId { get; set; } diff --git a/Domain/Schedule/LessonToTypeOfOccupation.cs b/Domain/Schedule/LessonToTypeOfOccupation.cs deleted file mode 100644 index c14e697..0000000 --- a/Domain/Schedule/LessonToTypeOfOccupation.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Mirea.Api.DataAccess.Domain.Schedule; - -public class LessonToTypeOfOccupation -{ - public int Id { get; set; } - - public int LessonId { get; set; } - public Lesson? Lesson { get; set; } - public int TypeOfOccupationId { get; set; } - public TypeOfOccupation? TypeOfOccupation { get; set; } -} \ No newline at end of file diff --git a/Domain/Schedule/Professor.cs b/Domain/Schedule/Professor.cs index 09309f8..0b0d710 100644 --- a/Domain/Schedule/Professor.cs +++ b/Domain/Schedule/Professor.cs @@ -8,5 +8,5 @@ public class Professor public required string Name { get; set; } public string? AltName { get; set; } - public List? ProfessorToLesson { get; set; } + public List? LessonAssociations { get; set; } } \ No newline at end of file diff --git a/Domain/Schedule/TypeOfOccupation.cs b/Domain/Schedule/TypeOfOccupation.cs index f7aeeb3..a2152a8 100644 --- a/Domain/Schedule/TypeOfOccupation.cs +++ b/Domain/Schedule/TypeOfOccupation.cs @@ -8,5 +8,5 @@ public class TypeOfOccupation public required string ShortName { get; set; } public string? FullName { get; set; } - public List? Lessons { get; set; } + public List? Lessons { get; set; } } \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/DayDbContext.cs b/Persistence/Contexts/Schedule/DisciplineDbContext.cs similarity index 61% rename from Persistence/Contexts/Schedule/DayDbContext.cs rename to Persistence/Contexts/Schedule/DisciplineDbContext.cs index 2edbb3a..d0a5612 100644 --- a/Persistence/Contexts/Schedule/DayDbContext.cs +++ b/Persistence/Contexts/Schedule/DisciplineDbContext.cs @@ -5,13 +5,13 @@ using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class DayDbContext(DbContextOptions options) : DbContext(options), IDayDbContext +public class DisciplineDbContext(DbContextOptions options) : DbContext(options), IDisciplineDbContext { - public DbSet Days { get; set; } = null!; + public DbSet Disciplines { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new DayConfiguration()); + modelBuilder.ApplyConfiguration(new DisciplineConfiguration()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/ProfessorToLessonDbContext.cs b/Persistence/Contexts/Schedule/LessonAssociationDbContext.cs similarity index 62% rename from Persistence/Contexts/Schedule/ProfessorToLessonDbContext.cs rename to Persistence/Contexts/Schedule/LessonAssociationDbContext.cs index 1673b68..773bc8a 100644 --- a/Persistence/Contexts/Schedule/ProfessorToLessonDbContext.cs +++ b/Persistence/Contexts/Schedule/LessonAssociationDbContext.cs @@ -5,13 +5,13 @@ using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class ProfessorToLessonDbContext(DbContextOptions options) : DbContext(options), IProfessorToLessonDbContext +public class LessonAssociationDbContext(DbContextOptions options) : DbContext(options), ILessonAssociationDbContext { - public DbSet ProfessorToLessons { get; set; } = null!; + public DbSet LessonAssociations { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new ProfessorToLessonConfiguration()); + modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/LessonToTypeOfOccupationDbContext.cs b/Persistence/Contexts/Schedule/LessonToTypeOfOccupationDbContext.cs deleted file mode 100644 index 1aada5e..0000000 --- a/Persistence/Contexts/Schedule/LessonToTypeOfOccupationDbContext.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; -using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; - -namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; - -public class LessonToTypeOfOccupationDbContext(DbContextOptions options) : DbContext(options), ILessonToTypeOfOccupationDbContext -{ - public DbSet LessonToTypeOfOccupations { get; set; } = null!; - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.ApplyConfiguration(new LessonToTypeOfOccupationConfiguration()); - base.OnModelCreating(modelBuilder); - } -} \ No newline at end of file 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/GroupConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/GroupConfiguration.cs index 0035390..5938bb3 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/GroupConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/GroupConfiguration.cs @@ -13,13 +13,13 @@ public class GroupConfiguration : IEntityTypeConfiguration builder.HasIndex(g => g.Id).IsUnique(); builder.Property(g => g.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); - builder.Property(g => g.FacultyId).HasColumnType("INTEGER").IsRequired(); + builder.Property(g => g.FacultyId).HasColumnType("INTEGER"); builder.Property(g => g.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(64); builder .HasOne(g => g.Faculty) .WithMany(u => u.Groups) .HasForeignKey(d => d.FacultyId) - .OnDelete(DeleteBehavior.Restrict); + .OnDelete(DeleteBehavior.SetNull); } } \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs index 592baa3..2d10805 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs @@ -20,6 +20,6 @@ public class LectureHallConfiguration : IEntityTypeConfiguration .HasOne(l => l.Campus) .WithMany(c => c.LectureHalls) .HasForeignKey(d => d.CampusId) - .OnDelete(DeleteBehavior.Cascade); + .OnDelete(DeleteBehavior.Restrict); } } \ No newline at end of file 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 diff --git a/Persistence/UberDbContext.cs b/Persistence/UberDbContext.cs index 17a4c52..699cc49 100644 --- a/Persistence/UberDbContext.cs +++ b/Persistence/UberDbContext.cs @@ -6,29 +6,27 @@ namespace Mirea.Api.DataAccess.Persistence; public class UberDbContext(DbContextOptions options) : DbContext(options) { - public DbSet Days { get; set; } = null!; + public DbSet Campuses { get; set; } = null!; + public DbSet Disciplines { get; set; } = null!; + public DbSet Faculties { get; set; } = null!; public DbSet Groups { get; set; } = null!; public DbSet LectureHalls { get; set; } = null!; + public DbSet LessonAssociations { get; set; } = null!; public DbSet Lessons { get; set; } = null!; public DbSet Professors { get; set; } = null!; public DbSet TypeOfOccupations { get; set; } = null!; - public DbSet Faculties { get; set; } = null!; - public DbSet Campuses { get; set; } = null!; - public DbSet ProfessorToLessons { get; set; } = null!; - public DbSet LessonToTypeOfOccupations { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new DayConfiguration()); + modelBuilder.ApplyConfiguration(new CampusConfiguration()); + modelBuilder.ApplyConfiguration(new DisciplineConfiguration()); + modelBuilder.ApplyConfiguration(new FacultyConfiguration()); modelBuilder.ApplyConfiguration(new GroupConfiguration()); modelBuilder.ApplyConfiguration(new LectureHallConfiguration()); modelBuilder.ApplyConfiguration(new LessonConfiguration()); modelBuilder.ApplyConfiguration(new ProfessorConfiguration()); + modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration()); modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration()); - modelBuilder.ApplyConfiguration(new FacultyConfiguration()); - modelBuilder.ApplyConfiguration(new CampusConfiguration()); - modelBuilder.ApplyConfiguration(new ProfessorToLessonConfiguration()); - modelBuilder.ApplyConfiguration(new LessonToTypeOfOccupationConfiguration()); base.OnModelCreating(modelBuilder); }