diff --git a/Backend.sln b/Backend.sln index f78e7d8..383bd42 100644 --- a/Backend.sln +++ b/Backend.sln @@ -17,7 +17,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elements of the solution", README.md = README.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}" + ProjectSection(ProjectDependencies) = postProject + {C27FB5CD-6A70-4FB2-847A-847B34806902} = {C27FB5CD-6A70-4FB2-847A-847B34806902} + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Persistence\Persistence.csproj", "{4C1E558F-633F-438E-AC3A-61CDDED917C5}" + ProjectSection(ProjectDependencies) = postProject + {E7F0A4D4-B032-4BB9-9526-1AF688F341A4} = {E7F0A4D4-B032-4BB9-9526-1AF688F341A4} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +41,14 @@ Global {F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.Build.0 = Debug|Any CPU {F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.ActiveCfg = Release|Any CPU {F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.Build.0 = Release|Any CPU + {E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Release|Any CPU.Build.0 = Release|Any CPU + {4C1E558F-633F-438E-AC3A-61CDDED917C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C1E558F-633F-438E-AC3A-61CDDED917C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C1E558F-633F-438E-AC3A-61CDDED917C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C1E558F-633F-438E-AC3A-61CDDED917C5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Persistence/Contexts/Schedule/CampusDbContext.cs b/Persistence/Contexts/Schedule/CampusDbContext.cs new file mode 100644 index 0000000..30a9d56 --- /dev/null +++ b/Persistence/Contexts/Schedule/CampusDbContext.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 CampusDbContext(DbContextOptions options) : DbContext(options), ICampusDbContext +{ + public DbSet Campuses { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new CampusConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/DayDbContext.cs b/Persistence/Contexts/Schedule/DayDbContext.cs new file mode 100644 index 0000000..2edbb3a --- /dev/null +++ b/Persistence/Contexts/Schedule/DayDbContext.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 DayDbContext(DbContextOptions options) : DbContext(options), IDayDbContext +{ + public DbSet Days { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new DayConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/FacultyDbContext.cs b/Persistence/Contexts/Schedule/FacultyDbContext.cs new file mode 100644 index 0000000..ab6a45c --- /dev/null +++ b/Persistence/Contexts/Schedule/FacultyDbContext.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 FacultyDbContext(DbContextOptions options) : DbContext(options), IFacultyDbContext +{ + public DbSet Faculties { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new FacultyConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/GroupDbContext.cs b/Persistence/Contexts/Schedule/GroupDbContext.cs new file mode 100644 index 0000000..5d61c70 --- /dev/null +++ b/Persistence/Contexts/Schedule/GroupDbContext.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 GroupDbContext(DbContextOptions options) : DbContext(options), IGroupDbContext +{ + public DbSet Groups { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new GroupConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/LectureHallDbContext.cs b/Persistence/Contexts/Schedule/LectureHallDbContext.cs new file mode 100644 index 0000000..67841a1 --- /dev/null +++ b/Persistence/Contexts/Schedule/LectureHallDbContext.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 LectureHallDbContext(DbContextOptions options) : DbContext(options), ILectureHallDbContext +{ + public DbSet LectureHalls { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new LectureHallConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/LessonDbContext.cs b/Persistence/Contexts/Schedule/LessonDbContext.cs new file mode 100644 index 0000000..d2dfcae --- /dev/null +++ b/Persistence/Contexts/Schedule/LessonDbContext.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 LessonDbContext(DbContextOptions options) : DbContext(options), ILessonDbContext +{ + public DbSet Lessons { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new LessonConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/LessonToTypeOfOccupationDbContext.cs b/Persistence/Contexts/Schedule/LessonToTypeOfOccupationDbContext.cs new file mode 100644 index 0000000..1aada5e --- /dev/null +++ b/Persistence/Contexts/Schedule/LessonToTypeOfOccupationDbContext.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 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/Contexts/Schedule/ProfessorDbContext.cs b/Persistence/Contexts/Schedule/ProfessorDbContext.cs new file mode 100644 index 0000000..fcd51c6 --- /dev/null +++ b/Persistence/Contexts/Schedule/ProfessorDbContext.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 ProfessorDbContext(DbContextOptions options) : DbContext(options), IProfessorDbContext +{ + public DbSet Professors { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new ProfessorConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/ProfessorToLessonDbContext.cs b/Persistence/Contexts/Schedule/ProfessorToLessonDbContext.cs new file mode 100644 index 0000000..1673b68 --- /dev/null +++ b/Persistence/Contexts/Schedule/ProfessorToLessonDbContext.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 ProfessorToLessonDbContext(DbContextOptions options) : DbContext(options), IProfessorToLessonDbContext +{ + public DbSet ProfessorToLessons { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new ProfessorToLessonConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs b/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs new file mode 100644 index 0000000..b47ac61 --- /dev/null +++ b/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.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 TypeOfOccupationDbContext(DbContextOptions options) : DbContext(options), ITypeOfOccupationDbContext +{ + public DbSet TypeOfOccupations { get; set; } = null!; + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration()); + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file 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 diff --git a/Persistence/Persistence.csproj b/Persistence/Persistence.csproj new file mode 100644 index 0000000..9cdfc62 --- /dev/null +++ b/Persistence/Persistence.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + disable + enable + Winsomnia + 1.0.0-a0 + 1.0.0.0 + 1.0.0.0 + Mirea.Api.DataAccess.Persistence + $(AssemblyName) + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Persistence/UberDbContext.cs b/Persistence/UberDbContext.cs new file mode 100644 index 0000000..17a4c52 --- /dev/null +++ b/Persistence/UberDbContext.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore; +using Mirea.Api.DataAccess.Domain.Schedule; +using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; + +namespace Mirea.Api.DataAccess.Persistence; + +public class UberDbContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Days { get; set; } = null!; + public DbSet Groups { get; set; } = null!; + public DbSet LectureHalls { 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 GroupConfiguration()); + modelBuilder.ApplyConfiguration(new LectureHallConfiguration()); + modelBuilder.ApplyConfiguration(new LessonConfiguration()); + modelBuilder.ApplyConfiguration(new ProfessorConfiguration()); + modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration()); + modelBuilder.ApplyConfiguration(new FacultyConfiguration()); + modelBuilder.ApplyConfiguration(new CampusConfiguration()); + modelBuilder.ApplyConfiguration(new ProfessorToLessonConfiguration()); + modelBuilder.ApplyConfiguration(new LessonToTypeOfOccupationConfiguration()); + + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file