diff --git a/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs b/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs new file mode 100644 index 0000000..b3601bd --- /dev/null +++ b/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs @@ -0,0 +1,17 @@ +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 SpecificWeekDbContext(DbContextOptions options) : DbContext(options), ISpecificWeekDbContext +{ + public DbSet SpecificWeeks { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new SpecificWeekConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/DependencyInjection.cs b/Persistence/DependencyInjection.cs index 9ec71f1..ed6f554 100644 --- a/Persistence/DependencyInjection.cs +++ b/Persistence/DependencyInjection.cs @@ -43,6 +43,7 @@ public static class DependencyInjection services.AddDbContext(dbConfig); services.AddDbContext(dbConfig); services.AddDbContext(dbConfig); + services.AddDbContext(dbConfig); services.AddDbContext(dbConfig); } @@ -58,6 +59,7 @@ public static class DependencyInjection services.AddScoped(provider => provider.GetService()!); services.AddScoped(provider => provider.GetService()!); services.AddScoped(provider => provider.GetService()!); + services.AddScoped(provider => provider.GetService()!); return services; } diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs index 44152dd..c9ecb8c 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonAssociationConfiguration.cs @@ -18,6 +18,8 @@ public class LessonAssociationConfiguration : IEntityTypeConfiguration l.LessonId).HasColumnType("INTEGER").IsRequired(); builder.Property(l => l.ProfessorId).HasColumnType("INTEGER"); builder.Property(l => l.LectureHallId).HasColumnType("INTEGER"); + builder.Property(l => l.TypeOfOccupationId).HasColumnType("INTEGER").IsRequired(); + builder .HasOne(l => l.Lesson) @@ -36,5 +38,11 @@ public class LessonAssociationConfiguration : IEntityTypeConfiguration l.LessonAssociations) .HasForeignKey(l => l.LectureHallId) .OnDelete(DeleteBehavior.SetNull); + + builder + .HasOne(l => l.TypeOfOccupation) + .WithMany(t => t.Lessons) + .HasForeignKey(d => d.TypeOfOccupationId) + .OnDelete(DeleteBehavior.Cascade); } } \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs index a3e878a..561df32 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs @@ -16,24 +16,17 @@ public class LessonConfiguration : IEntityTypeConfiguration 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.IsExcludedWeeks).HasColumnType("BOOLEAN"); 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) diff --git a/Persistence/EntityTypeConfigurations/Schedule/SpecificWeekConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/SpecificWeekConfiguration.cs new file mode 100644 index 0000000..f4fc8a3 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/SpecificWeekConfiguration.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class SpecificWeekConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(SpecificWeek)); + builder.HasKey(s => s.Id); + builder.HasIndex(s => s.Id).IsUnique(); + builder.Property(s => s.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(s => s.WeekNumber).HasColumnType("INTEGER").IsRequired(); + + builder.Property(s => s.LessonId).HasColumnType("INTEGER").IsRequired(); + + builder + .HasOne(s => s.Lesson) + .WithMany(l => l.SpecificWeeks) + .HasForeignKey(s => s.LessonId) + .OnDelete(DeleteBehavior.Cascade); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs index 82c0b61..5341a5a 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs @@ -14,6 +14,5 @@ public class TypeOfOccupationConfiguration : IEntityTypeConfiguration t.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); 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 699cc49..ccd1877 100644 --- a/Persistence/UberDbContext.cs +++ b/Persistence/UberDbContext.cs @@ -15,6 +15,7 @@ public class UberDbContext(DbContextOptions options) : DbContext( public DbSet Lessons { get; set; } = null!; public DbSet Professors { get; set; } = null!; public DbSet TypeOfOccupations { get; set; } = null!; + public DbSet SpecificWeeks { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -27,6 +28,7 @@ public class UberDbContext(DbContextOptions options) : DbContext( modelBuilder.ApplyConfiguration(new ProfessorConfiguration()); modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration()); modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration()); + modelBuilder.ApplyConfiguration(new SpecificWeekConfiguration()); base.OnModelCreating(modelBuilder); }