diff --git a/Persistence/EntityTypeConfigurations/Schedule/CampusConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/CampusConfiguration.cs new file mode 100644 index 0000000..410d6c2 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/CampusConfiguration.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class CampusConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Campus)); + builder.HasKey(c => c.Id); + builder.HasIndex(c => c.Id).IsUnique(); + builder.Property(c => c.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(c => c.Address).HasColumnType("TEXT").HasMaxLength(512); + builder.Property(c => c.CodeName).HasColumnType("TEXT").IsRequired().HasMaxLength(16); + builder.Property(c => c.FullName).HasColumnType("TEXT").HasMaxLength(256); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs new file mode 100644 index 0000000..486013e --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/DayConfiguration.cs @@ -0,0 +1,32 @@ +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/FacultyConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/FacultyConfiguration.cs new file mode 100644 index 0000000..fccac7f --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/FacultyConfiguration.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class FacultyConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Faculty)); + builder.HasKey(f => f.Id); + builder.HasIndex(f => f.Id).IsUnique(); + builder.Property(f => f.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(f => f.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(256); + + builder + .HasOne(f => f.Campus) + .WithMany(c => c.Faculties) + .HasForeignKey(c => c.CampusId) + .OnDelete(DeleteBehavior.SetNull); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/GroupConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/GroupConfiguration.cs new file mode 100644 index 0000000..0035390 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/GroupConfiguration.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class GroupConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Group)); + builder.HasKey(g => g.Id); + 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.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(64); + + builder + .HasOne(g => g.Faculty) + .WithMany(u => u.Groups) + .HasForeignKey(d => d.FacultyId) + .OnDelete(DeleteBehavior.Restrict); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs new file mode 100644 index 0000000..592baa3 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/LectureHallConfiguration.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class LectureHallConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(LectureHall)); + builder.HasKey(l => l.Id); + builder.HasIndex(l => l.Id).IsUnique(); + builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(l => l.CampusId).HasColumnType("INTEGER").IsRequired(); + builder.Property(l => l.Name).HasColumnType("TEXT").IsRequired().HasMaxLength(64); + + builder + .HasOne(l => l.Campus) + .WithMany(c => c.LectureHalls) + .HasForeignKey(d => d.CampusId) + .OnDelete(DeleteBehavior.Cascade); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs new file mode 100644 index 0000000..82885d4 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class LessonConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Lesson)); + builder.HasKey(l => l.Id); + 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(); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs new file mode 100644 index 0000000..dfe7010 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonToTypeOfOccupationConfiguration.cs @@ -0,0 +1,31 @@ +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/ProfessorConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/ProfessorConfiguration.cs new file mode 100644 index 0000000..7b95ab8 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/ProfessorConfiguration.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class ProfessorConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Professor)); + builder.HasKey(p => p.Id); + builder.HasIndex(p => p.Id).IsUnique(); + builder.Property(p => p.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(p => p.Name).HasColumnType("TEXT").IsRequired(); + builder.Property(p => p.AltName).HasColumnType("TEXT"); + } +} \ No newline at end of file diff --git a/Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs new file mode 100644 index 0000000..02ab493 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/ProfessorToLessonConfiguration.cs @@ -0,0 +1,39 @@ +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 new file mode 100644 index 0000000..24f3b55 --- /dev/null +++ b/Persistence/EntityTypeConfigurations/Schedule/TypeOfOccupationConfiguration.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +public class TypeOfOccupationConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(TypeOfOccupation)); + builder.HasKey(t => t.Id); + builder.HasIndex(t => 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); + } +} \ No newline at end of file