From 04b66871815f75fd1e342f3bee05dbfe427b7a9f Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 1 Jun 2024 05:39:02 +0300 Subject: [PATCH] feat: add mysql configurations --- .../Mysql/Schedule/CampusConfiguration.cs | 20 ++++++++ .../Mysql/Schedule/DisciplineConfiguration.cs | 18 +++++++ .../Mysql/Schedule/FacultyConfiguration.cs | 26 ++++++++++ .../Mysql/Schedule/GroupConfiguration.cs | 25 ++++++++++ .../Schedule/LectureHallConfiguration.cs | 25 ++++++++++ .../LessonAssociationConfiguration.cs | 48 +++++++++++++++++++ .../Mysql/Schedule/LessonConfiguration.cs | 36 ++++++++++++++ .../Mysql/Schedule/ProfessorConfiguration.cs | 19 ++++++++ .../Schedule/SpecificWeekConfiguration.cs | 26 ++++++++++ .../Schedule/TypeOfOccupationConfiguration.cs | 18 +++++++ 10 files changed, 261 insertions(+) create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/CampusConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/DisciplineConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/FacultyConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/GroupConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LectureHallConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonAssociationConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/ProfessorConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/SpecificWeekConfiguration.cs create mode 100644 SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/TypeOfOccupationConfiguration.cs diff --git a/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/CampusConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/CampusConfiguration.cs new file mode 100644 index 0000000..a6a961d --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/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.Mysql.Schedule; + +public sealed 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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(c => c.Address).HasColumnType("VARCHAR(512)").HasMaxLength(512); + builder.Property(c => c.CodeName).HasColumnType("VARCHAR(16)").IsRequired().HasMaxLength(16); + builder.Property(c => c.FullName).HasColumnType("VARCHAR(256)").HasMaxLength(256); + } +} \ No newline at end of file diff --git a/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/DisciplineConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/DisciplineConfiguration.cs new file mode 100644 index 0000000..ababf1f --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(d => d.Name).HasColumnType("VARCHAR(256)").HasMaxLength(256).IsRequired(); + } +} \ No newline at end of file diff --git a/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/FacultyConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/FacultyConfiguration.cs new file mode 100644 index 0000000..3e2e24d --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/FacultyConfiguration.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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(f => f.Name).HasColumnType("VARCHAR(256)").IsRequired().HasMaxLength(256); + + builder.Property(f => f.CampusId).HasColumnType("INT"); + + 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/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/GroupConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/GroupConfiguration.cs new file mode 100644 index 0000000..a0e1645 --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(g => g.FacultyId).HasColumnType("INT"); + builder.Property(g => g.Name).HasColumnType("VARCHAR(64)").IsRequired().HasMaxLength(64); + + builder + .HasOne(g => g.Faculty) + .WithMany(u => u.Groups) + .HasForeignKey(d => d.FacultyId) + .OnDelete(DeleteBehavior.SetNull); + } +} \ No newline at end of file diff --git a/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LectureHallConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LectureHallConfiguration.cs new file mode 100644 index 0000000..ec9ab8c --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(l => l.CampusId).HasColumnType("INT").IsRequired(); + builder.Property(l => l.Name).HasColumnType("VARCHAR(64)").IsRequired().HasMaxLength(64); + + builder + .HasOne(l => l.Campus) + .WithMany(c => c.LectureHalls) + .HasForeignKey(d => d.CampusId) + .OnDelete(DeleteBehavior.Restrict); + } +} \ No newline at end of file diff --git a/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonAssociationConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonAssociationConfiguration.cs new file mode 100644 index 0000000..f35317d --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonAssociationConfiguration.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(l => l.LinkToMeet).HasColumnType("VARCHAR(512)").HasMaxLength(512); + + builder.Property(l => l.LessonId).HasColumnType("INT").IsRequired(); + builder.Property(l => l.ProfessorId).HasColumnType("INT"); + builder.Property(l => l.LectureHallId).HasColumnType("INT"); + builder.Property(l => l.TypeOfOccupationId).HasColumnType("INT").IsRequired(); + + + 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); + + 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/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonConfiguration.cs new file mode 100644 index 0000000..66e76d8 --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/LessonConfiguration.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(l => l.IsEven).HasColumnType("BIT(1)").IsRequired(); + builder.Property(l => l.DayOfWeek).HasColumnType("INT").IsRequired(); + builder.Property(l => l.PairNumber).HasColumnType("INT").IsRequired(); + builder.Property(l => l.IsExcludedWeeks).HasColumnType("BIT(1)"); + + builder.Property(l => l.GroupId).HasColumnType("INT").IsRequired(); + builder.Property(l => l.DisciplineId).HasColumnType("INT").IsRequired(); + + builder + .HasOne(l => l.Group) + .WithMany(g => g.Lessons) + .HasForeignKey(d => d.GroupId) + .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/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/ProfessorConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/ProfessorConfiguration.cs new file mode 100644 index 0000000..a7e8f02 --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(p => p.Name).HasColumnType("VARCHAR").IsRequired(); + builder.Property(p => p.AltName).HasColumnType("VARCHAR"); + } +} \ No newline at end of file diff --git a/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/SpecificWeekConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/SpecificWeekConfiguration.cs new file mode 100644 index 0000000..e7b0529 --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(s => s.WeekNumber).HasColumnType("INT").IsRequired(); + + builder.Property(s => s.LessonId).HasColumnType("INT").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/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/TypeOfOccupationConfiguration.cs b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/TypeOfOccupationConfiguration.cs new file mode 100644 index 0000000..90e92e5 --- /dev/null +++ b/SqlData/Persistence/EntityTypeConfigurations/Mysql/Schedule/TypeOfOccupationConfiguration.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.Mysql.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("INT").IsRequired().ValueGeneratedOnAdd(); + + builder.Property(t => t.ShortName).HasColumnType("VARCHAR").IsRequired().HasMaxLength(16); + } +} \ No newline at end of file