From 05dadff455f3a3cf02239d016d00cab761d96457 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 11:49:03 +0300 Subject: [PATCH 1/7] feat: add specific week --- Domain/Schedule/Lesson.cs | 4 ++-- Domain/Schedule/LessonAssociation.cs | 2 ++ Domain/Schedule/SpecificWeek.cs | 10 ++++++++++ Domain/Schedule/TypeOfOccupation.cs | 3 +-- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 Domain/Schedule/SpecificWeek.cs diff --git a/Domain/Schedule/Lesson.cs b/Domain/Schedule/Lesson.cs index 3ff5e52..e854d3e 100644 --- a/Domain/Schedule/Lesson.cs +++ b/Domain/Schedule/Lesson.cs @@ -9,13 +9,13 @@ public class Lesson public bool IsEven { get; set; } public DayOfWeek DayOfWeek { get; set; } public int PairNumber { get; set; } + public bool? IsExcludedWeeks { 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; } + public List? SpecificWeeks { get; set; } } \ No newline at end of file diff --git a/Domain/Schedule/LessonAssociation.cs b/Domain/Schedule/LessonAssociation.cs index 89b5651..e101bdd 100644 --- a/Domain/Schedule/LessonAssociation.cs +++ b/Domain/Schedule/LessonAssociation.cs @@ -5,6 +5,8 @@ public class LessonAssociation public int Id { get; set; } public string? LinkToMeet { get; set; } + public int TypeOfOccupationId { get; set; } + public TypeOfOccupation? TypeOfOccupation { get; set; } public int LessonId { get; set; } public Lesson? Lesson { get; set; } public int? ProfessorId { get; set; } diff --git a/Domain/Schedule/SpecificWeek.cs b/Domain/Schedule/SpecificWeek.cs new file mode 100644 index 0000000..b0adf31 --- /dev/null +++ b/Domain/Schedule/SpecificWeek.cs @@ -0,0 +1,10 @@ +namespace Mirea.Api.DataAccess.Domain.Schedule; + +public class SpecificWeek +{ + public int Id { get; set; } + public int WeekNumber { get; set; } + + public int LessonId { get; set; } + public Lesson? Lesson { get; set; } +} \ No newline at end of file diff --git a/Domain/Schedule/TypeOfOccupation.cs b/Domain/Schedule/TypeOfOccupation.cs index a2152a8..4a52a4a 100644 --- a/Domain/Schedule/TypeOfOccupation.cs +++ b/Domain/Schedule/TypeOfOccupation.cs @@ -6,7 +6,6 @@ public class TypeOfOccupation { public int Id { get; set; } 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 From 628faf7e687058dddfff75aed74a8e82eda48f75 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 11:52:08 +0300 Subject: [PATCH 2/7] feat: add interface for specific week --- .../DbContexts/Schedule/ISpecificWeekDbContext.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Application/Interfaces/DbContexts/Schedule/ISpecificWeekDbContext.cs diff --git a/Application/Interfaces/DbContexts/Schedule/ISpecificWeekDbContext.cs b/Application/Interfaces/DbContexts/Schedule/ISpecificWeekDbContext.cs new file mode 100644 index 0000000..a58115c --- /dev/null +++ b/Application/Interfaces/DbContexts/Schedule/ISpecificWeekDbContext.cs @@ -0,0 +1,9 @@ +using Microsoft.EntityFrameworkCore; +using Mirea.Api.DataAccess.Domain.Schedule; + +namespace Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; + +public interface ISpecificWeekDbContext : IDbContextBase +{ + DbSet SpecificWeeks { get; set; } +} \ No newline at end of file From 97d2fae79e0f897b9aab87f3df8763a0259339f6 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 11:52:56 +0300 Subject: [PATCH 3/7] feat: add specific week to persistence --- .../Schedule/SpecificWeekDbContext.cs | 17 ++++++++++++ Persistence/DependencyInjection.cs | 2 ++ .../LessonAssociationConfiguration.cs | 8 ++++++ .../Schedule/LessonConfiguration.cs | 9 +------ .../Schedule/SpecificWeekConfiguration.cs | 26 +++++++++++++++++++ .../Schedule/TypeOfOccupationConfiguration.cs | 1 - Persistence/UberDbContext.cs | 2 ++ 7 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 Persistence/Contexts/Schedule/SpecificWeekDbContext.cs create mode 100644 Persistence/EntityTypeConfigurations/Schedule/SpecificWeekConfiguration.cs 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); } From ca18804a33076092caaae24e3132ff109dab74cf Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 12:30:17 +0300 Subject: [PATCH 4/7] fix: error CS1061 --- .../Schedule/DisciplineScheduleResponse.cs | 2 +- .../Schedule/GroupScheduleResponse.cs | 2 +- .../Schedule/LectureHallScheduleResponse.cs | 2 +- .../Schedule/ProfessorScheduleResponse.cs | 2 +- ApiDto/Responses/Schedule/ScheduleResponse.cs | 2 +- Endpoint/Controllers/V1/ScheduleController.cs | 20 +++++++++---------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ApiDto/Responses/Schedule/DisciplineScheduleResponse.cs b/ApiDto/Responses/Schedule/DisciplineScheduleResponse.cs index bf4a337..ffc5578 100644 --- a/ApiDto/Responses/Schedule/DisciplineScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/DisciplineScheduleResponse.cs @@ -31,7 +31,7 @@ public class DisciplineScheduleInfo /// Gets or sets the type of occupation for the schedule entry. /// [Required] - public required string TypeOfOccupation { get; set; } + public required IEnumerable TypeOfOccupation { get; set; } /// /// Gets or sets the names of the group for the schedule entry. diff --git a/ApiDto/Responses/Schedule/GroupScheduleResponse.cs b/ApiDto/Responses/Schedule/GroupScheduleResponse.cs index 7fa13d1..c85778c 100644 --- a/ApiDto/Responses/Schedule/GroupScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/GroupScheduleResponse.cs @@ -43,7 +43,7 @@ public class GroupScheduleInfo /// Gets or sets the type of occupation for the schedule entry. /// [Required] - public required string TypeOfOccupation { get; set; } + public required IEnumerable TypeOfOccupations { get; set; } /// /// Gets or sets the names of the lecture halls for the schedule entry. diff --git a/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs b/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs index 369a8f5..294876f 100644 --- a/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs @@ -43,7 +43,7 @@ public class LectureHallScheduleInfo /// Gets or sets the type of occupation for the schedule entry. /// [Required] - public required string TypeOfOccupation { get; set; } + public required IEnumerable TypeOfOccupations { get; set; } /// /// Gets or sets the names of the group for the schedule entry. diff --git a/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs b/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs index 3a53ebf..07a7471 100644 --- a/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs @@ -43,7 +43,7 @@ public class ProfessorScheduleInfo /// Gets or sets the type of occupation for the schedule entry. /// [Required] - public required string TypeOfOccupation { get; set; } + public required IEnumerable TypeOfOccupations { get; set; } /// /// Gets or sets the names of the group for the schedule entry. diff --git a/ApiDto/Responses/Schedule/ScheduleResponse.cs b/ApiDto/Responses/Schedule/ScheduleResponse.cs index 2a03178..8698ed7 100644 --- a/ApiDto/Responses/Schedule/ScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/ScheduleResponse.cs @@ -43,7 +43,7 @@ public class ScheduleResponse /// Gets or sets the type of occupation for the schedule entry. /// [Required] - public required string TypeOfOccupation { get; set; } + public required IEnumerable TypeOfOccupations { get; set; } /// /// Gets or sets the name of the group for the schedule entry. diff --git a/Endpoint/Controllers/V1/ScheduleController.cs b/Endpoint/Controllers/V1/ScheduleController.cs index 43b47ad..3e9a5ed 100644 --- a/Endpoint/Controllers/V1/ScheduleController.cs +++ b/Endpoint/Controllers/V1/ScheduleController.cs @@ -27,10 +27,10 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 public async Task>> Get([FromBody] ScheduleRequest request) { - if ((request.Groups == null || !request.Groups.Any()) && - (request.Disciplines == null || !request.Disciplines.Any()) && - (request.Professors == null || !request.Professors.Any()) && - (request.LectureHalls == null || !request.LectureHalls.Any())) + if ((request.Groups == null || request.Groups.Length == 0) && + (request.Disciplines == null || request.Disciplines.Length == 0) && + (request.Professors == null || request.Professors.Length == 0) && + (request.LectureHalls == null || request.LectureHalls.Length == 0)) { return BadRequest(new ErrorResponse() { @@ -60,7 +60,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = s.IsEven, Discipline = s.Discipline, DisciplineId = s.DisciplineId, - TypeOfOccupation = s.TypeOfOccupation, + TypeOfOccupations = s.TypeOfOccupations, Group = s.Group, GroupId = s.GroupId, LectureHalls = s.LectureHalls, @@ -117,7 +117,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = g.IsEven, Discipline = g.Discipline, DisciplineId = g.DisciplineId, - TypeOfOccupation = g.TypeOfOccupation, + TypeOfOccupations = g.TypeOfOccupations, LectureHalls = g.LectureHalls, LectureHallsId = g.LectureHallsId, Professors = g.Professors, @@ -176,7 +176,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = p.IsEven, Discipline = p.Discipline, DisciplineId = p.DisciplineId, - TypeOfOccupation = p.TypeOfOccupation, + TypeOfOccupations = p.TypeOfOccupations, Group = p.Group, GroupId = p.GroupId, LectureHalls = p.LectureHalls, @@ -235,7 +235,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = l.IsEven, Discipline = l.Discipline, DisciplineId = l.DisciplineId, - TypeOfOccupation = l.TypeOfOccupation, + TypeOfOccupations = l.TypeOfOccupations, Group = l.Group, GroupId = l.GroupId, Professors = l.Professors, @@ -273,7 +273,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = isEven, DisciplineIds = [id], GroupIds = groups, - LectureHallIds = [id], + LectureHallIds = lectureHalls, ProfessorIds = professors })).Schedules; @@ -288,7 +288,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 DayOfWeek = d.DayOfWeek, PairNumber = d.PairNumber, IsEven = d.IsEven, - TypeOfOccupation = d.TypeOfOccupation, + TypeOfOccupation = d.TypeOfOccupations, Group = d.Group, GroupId = d.GroupId, LectureHalls = d.LectureHalls, From d8f2f51cd713c96a62b1a23ce11ab88d3f84cb60 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 12:44:35 +0300 Subject: [PATCH 5/7] fix: error CS1061 --- .../GetScheduleList/GetScheduleListQueryHandler.cs | 10 +++++++--- .../Queries/GetScheduleList/ScheduleLookupDto.cs | 10 +++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs b/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs index ba08003..9c91c64 100644 --- a/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs +++ b/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs @@ -11,13 +11,15 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH { public async Task Handle(GetScheduleListQuery request, CancellationToken cancellationToken) { - var query = dbContext.Lessons.Include(l => l.LessonAssociations) + var query = dbContext.Lessons + .Include(l => l.LessonAssociations) .ThenInclude(la => la.LectureHall) .ThenInclude(lh => lh!.Campus) .Include(l => l.LessonAssociations) .ThenInclude(la => la.Professor) + .Include(l => l.LessonAssociations) + .ThenInclude(la => la.TypeOfOccupation) .Include(l => l.Group) - .Include(l => l.TypeOfOccupation) .Include(l => l.Discipline) .AsQueryable(); @@ -46,7 +48,9 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH DayOfWeek = l.DayOfWeek, PairNumber = l.PairNumber, IsEven = l.IsEven, - TypeOfOccupation = l.TypeOfOccupation!.ShortName, + TypeOfOccupations = l.LessonAssociations! + .Where(la => !string.IsNullOrEmpty(la.TypeOfOccupation?.ShortName)) + .Select(la => la.TypeOfOccupation!.ShortName), Discipline = l.Discipline!.Name, DisciplineId = l.DisciplineId, diff --git a/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs b/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs index bd3808f..6e8cc1f 100644 --- a/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs +++ b/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs @@ -33,11 +33,6 @@ public class ScheduleLookupDto /// public required int DisciplineId { get; set; } - /// - /// Gets or sets the type of occupation. - /// - public required string TypeOfOccupation { get; set; } - /// /// Gets or sets the name of the group. /// @@ -48,6 +43,11 @@ public class ScheduleLookupDto /// public required int GroupId { get; set; } + /// + /// Gets or sets the type of occupation. + /// + public required IEnumerable TypeOfOccupations { get; set; } + /// /// Gets or sets the names of the lecture halls. /// From 22579038d333270ec4aeac145ec2dab92e2cdc20 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 13:52:10 +0300 Subject: [PATCH 6/7] fix: change BIT to BOOLEAN --- .../EntityTypeConfigurations/Schedule/LessonConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs index 561df32..8d9c8cd 100644 --- a/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs +++ b/Persistence/EntityTypeConfigurations/Schedule/LessonConfiguration.cs @@ -13,7 +13,7 @@ public class LessonConfiguration : IEntityTypeConfiguration builder.HasIndex(l => l.Id).IsUnique(); builder.Property(l => l.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd(); - builder.Property(l => l.IsEven).HasColumnType("BIT").IsRequired(); + builder.Property(l => l.IsEven).HasColumnType("BOOLEAN").IsRequired(); builder.Property(l => l.DayOfWeek).HasColumnType("INTEGER").IsRequired(); builder.Property(l => l.PairNumber).HasColumnType("INTEGER").IsRequired(); builder.Property(l => l.IsExcludedWeeks).HasColumnType("BOOLEAN"); From 0d3461b76956fd9be18d87e6cd889a44c04264ce Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sun, 19 May 2024 13:53:25 +0300 Subject: [PATCH 7/7] feat: add specific weeks --- .../Schedule/GroupScheduleResponse.cs | 23 +++++++++++++++ .../Schedule/LectureHallScheduleResponse.cs | 23 +++++++++++++++ .../Schedule/ProfessorScheduleResponse.cs | 23 +++++++++++++++ ApiDto/Responses/Schedule/ScheduleResponse.cs | 23 +++++++++++++++ .../GetScheduleListQueryHandler.cs | 28 ++++++++++--------- .../GetScheduleList/ScheduleLookupDto.cs | 10 +++++++ Endpoint/Controllers/V1/ScheduleController.cs | 8 ++++++ 7 files changed, 125 insertions(+), 13 deletions(-) diff --git a/ApiDto/Responses/Schedule/GroupScheduleResponse.cs b/ApiDto/Responses/Schedule/GroupScheduleResponse.cs index c85778c..c0a7f42 100644 --- a/ApiDto/Responses/Schedule/GroupScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/GroupScheduleResponse.cs @@ -39,6 +39,29 @@ public class GroupScheduleInfo [Required] public required int DisciplineId { get; set; } + /// + /// Gets or sets exclude or include weeks for a specific discipline. + /// + /// + /// If is , then the values in show the weeks when there will be no discipline. + ///
+ /// If is , then the values in indicate the weeks during which a particular discipline will be studied. + ///
+ /// If is , then there are no specific + ///
+ /// + + public bool? IsExcludedWeeks { get; set; } + /// + /// The week numbers required for the correct display of the schedule. + ///
+ /// Whether there will be during the week or not depends on the property. + ///
+ /// + /// To get the current week's number, use other queries. + /// + public IEnumerable? Weeks { get; set; } + /// /// Gets or sets the type of occupation for the schedule entry. /// diff --git a/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs b/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs index 294876f..84adb3c 100644 --- a/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/LectureHallScheduleResponse.cs @@ -39,6 +39,29 @@ public class LectureHallScheduleInfo [Required] public required int DisciplineId { get; set; } + /// + /// Gets or sets exclude or include weeks for a specific discipline. + /// + /// + /// If is , then the values in show the weeks when there will be no discipline. + ///
+ /// If is , then the values in indicate the weeks during which a particular discipline will be studied. + ///
+ /// If is , then there are no specific + ///
+ /// + + public bool? IsExcludedWeeks { get; set; } + /// + /// The week numbers required for the correct display of the schedule. + ///
+ /// Whether there will be during the week or not depends on the property. + ///
+ /// + /// To get the current week's number, use other queries. + /// + public IEnumerable? Weeks { get; set; } + /// /// Gets or sets the type of occupation for the schedule entry. /// diff --git a/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs b/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs index 07a7471..b25711e 100644 --- a/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/ProfessorScheduleResponse.cs @@ -39,6 +39,29 @@ public class ProfessorScheduleInfo [Required] public required int DisciplineId { get; set; } + /// + /// Gets or sets exclude or include weeks for a specific discipline. + /// + /// + /// If is , then the values in show the weeks when there will be no discipline. + ///
+ /// If is , then the values in indicate the weeks during which a particular discipline will be studied. + ///
+ /// If is , then there are no specific + ///
+ /// + + public bool? IsExcludedWeeks { get; set; } + /// + /// The week numbers required for the correct display of the schedule. + ///
+ /// Whether there will be during the week or not depends on the property. + ///
+ /// + /// To get the current week's number, use other queries. + /// + public IEnumerable? Weeks { get; set; } + /// /// Gets or sets the type of occupation for the schedule entry. /// diff --git a/ApiDto/Responses/Schedule/ScheduleResponse.cs b/ApiDto/Responses/Schedule/ScheduleResponse.cs index 8698ed7..599cc3e 100644 --- a/ApiDto/Responses/Schedule/ScheduleResponse.cs +++ b/ApiDto/Responses/Schedule/ScheduleResponse.cs @@ -39,6 +39,29 @@ public class ScheduleResponse [Required] public required int DisciplineId { get; set; } + /// + /// Gets or sets exclude or include weeks for a specific discipline. + /// + /// + /// If is , then the values in show the weeks when there will be no discipline. + ///
+ /// If is , then the values in indicate the weeks during which a particular discipline will be studied. + ///
+ /// If is , then there are no specific + ///
+ /// + + public bool? IsExcludedWeeks { get; set; } + /// + /// The week numbers required for the correct display of the schedule. + ///
+ /// Whether there will be during the week or not depends on the property. + ///
+ /// + /// To get the current week's number, use other queries. + /// + public IEnumerable? Weeks { get; set; } + /// /// Gets or sets the type of occupation for the schedule entry. /// diff --git a/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs b/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs index 9c91c64..63a8a4d 100644 --- a/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs +++ b/Application/Cqrs/Schedule/Queries/GetScheduleList/GetScheduleListQueryHandler.cs @@ -11,17 +11,7 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH { public async Task Handle(GetScheduleListQuery request, CancellationToken cancellationToken) { - var query = dbContext.Lessons - .Include(l => l.LessonAssociations) - .ThenInclude(la => la.LectureHall) - .ThenInclude(lh => lh!.Campus) - .Include(l => l.LessonAssociations) - .ThenInclude(la => la.Professor) - .Include(l => l.LessonAssociations) - .ThenInclude(la => la.TypeOfOccupation) - .Include(l => l.Group) - .Include(l => l.Discipline) - .AsQueryable(); + var query = dbContext.Lessons.AsQueryable(); if (request.IsEven != null) query = query.Where(l => l.IsEven == request.IsEven); @@ -41,7 +31,17 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH l.LessonAssociations!.Any(la => la.ProfessorId != null && request.ProfessorIds.Contains(la.ProfessorId.Value))); - var data = await query.ToArrayAsync(cancellationToken); + var data = await query + .Include(lesson => lesson.Discipline!) + .Include(lesson => lesson.SpecificWeeks) + .Include(lesson => lesson.Group!) + .Include(lesson => lesson.LessonAssociations!) + .ThenInclude(lessonAssociation => lessonAssociation.TypeOfOccupation!) + .Include(lesson => lesson.LessonAssociations!) + .ThenInclude(lessonAssociation => lessonAssociation.Professor) + .Include(lesson => lesson.LessonAssociations!) + .ThenInclude(lessonAssociation => lessonAssociation.LectureHall) + .ThenInclude(lectureHall => lectureHall!.Campus).ToListAsync(cancellationToken); var result = data.Select(l => new ScheduleLookupDto() { @@ -55,6 +55,9 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH Discipline = l.Discipline!.Name, DisciplineId = l.DisciplineId, + IsExcludedWeeks = l.IsExcludedWeeks, + Weeks = l.SpecificWeeks?.Select(w => w.WeekNumber), + Group = l.Group!.Name, GroupId = l.GroupId, @@ -72,7 +75,6 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH .Where(la => la.LectureHall?.Campus != null) .Select(la => la.LectureHall?.CampusId), - Professors = l.LessonAssociations! .Where(la => !string.IsNullOrEmpty(la.Professor?.Name)) .Select(la => la.Professor?.Name), diff --git a/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs b/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs index 6e8cc1f..b7a3802 100644 --- a/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs +++ b/Application/Cqrs/Schedule/Queries/GetScheduleList/ScheduleLookupDto.cs @@ -33,6 +33,16 @@ public class ScheduleLookupDto /// public required int DisciplineId { get; set; } + /// + /// Gets or sets exclude or include weeks for a specific discipline. + /// + public bool? IsExcludedWeeks { get; set; } + + /// + /// The week numbers required for the correct display of the schedule. + /// + public IEnumerable? Weeks { get; set; } + /// /// Gets or sets the name of the group. /// diff --git a/Endpoint/Controllers/V1/ScheduleController.cs b/Endpoint/Controllers/V1/ScheduleController.cs index 3e9a5ed..1500efa 100644 --- a/Endpoint/Controllers/V1/ScheduleController.cs +++ b/Endpoint/Controllers/V1/ScheduleController.cs @@ -60,6 +60,8 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = s.IsEven, Discipline = s.Discipline, DisciplineId = s.DisciplineId, + IsExcludedWeeks = s.IsExcludedWeeks, + Weeks = s.Weeks, TypeOfOccupations = s.TypeOfOccupations, Group = s.Group, GroupId = s.GroupId, @@ -117,6 +119,8 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = g.IsEven, Discipline = g.Discipline, DisciplineId = g.DisciplineId, + IsExcludedWeeks = g.IsExcludedWeeks, + Weeks = g.Weeks, TypeOfOccupations = g.TypeOfOccupations, LectureHalls = g.LectureHalls, LectureHallsId = g.LectureHallsId, @@ -176,6 +180,8 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = p.IsEven, Discipline = p.Discipline, DisciplineId = p.DisciplineId, + IsExcludedWeeks = p.IsExcludedWeeks, + Weeks = p.Weeks, TypeOfOccupations = p.TypeOfOccupations, Group = p.Group, GroupId = p.GroupId, @@ -235,6 +241,8 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 IsEven = l.IsEven, Discipline = l.Discipline, DisciplineId = l.DisciplineId, + IsExcludedWeeks = l.IsExcludedWeeks, + Weeks = l.Weeks, TypeOfOccupations = l.TypeOfOccupations, Group = l.Group, GroupId = l.GroupId,