Compare commits

..

8 Commits

Author SHA1 Message Date
6716ee9cf0 Add specific weeks of disciplines (#10) from feat/improved-sugroup into release/v1.0.0
Reviewed-on: #10
2024-05-19 13:57:09 +03:00
0d3461b769 feat: add specific weeks
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 1m52s
2024-05-19 13:53:25 +03:00
22579038d3 fix: change BIT to BOOLEAN 2024-05-19 13:52:10 +03:00
d8f2f51cd7 fix: error CS1061
All checks were successful
.NET Test Pipeline / build-and-test (pull_request) Successful in 2m7s
2024-05-19 12:44:35 +03:00
ca18804a33 fix: error CS1061
Some checks failed
.NET Test Pipeline / build-and-test (pull_request) Failing after 1m50s
2024-05-19 12:30:17 +03:00
97d2fae79e feat: add specific week to persistence
Some checks failed
.NET Test Pipeline / build-and-test (pull_request) Failing after 3m13s
2024-05-19 11:52:56 +03:00
628faf7e68 feat: add interface for specific week 2024-05-19 11:52:08 +03:00
05dadff455 feat: add specific week 2024-05-19 11:49:03 +03:00
20 changed files with 226 additions and 43 deletions

View File

@ -31,7 +31,7 @@ public class DisciplineScheduleInfo
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
public required IEnumerable<string> TypeOfOccupation { get; set; }
/// <summary>
/// Gets or sets the names of the group for the schedule entry.

View File

@ -39,11 +39,34 @@ public class GroupScheduleInfo
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
public required IEnumerable<string> TypeOfOccupations { get; set; }
/// <summary>
/// Gets or sets the names of the lecture halls for the schedule entry.

View File

@ -39,11 +39,34 @@ public class LectureHallScheduleInfo
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
public required IEnumerable<string> TypeOfOccupations { get; set; }
/// <summary>
/// Gets or sets the names of the group for the schedule entry.

View File

@ -39,11 +39,34 @@ public class ProfessorScheduleInfo
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
public required IEnumerable<string> TypeOfOccupations { get; set; }
/// <summary>
/// Gets or sets the names of the group for the schedule entry.

View File

@ -39,11 +39,34 @@ public class ScheduleResponse
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
public required IEnumerable<string> TypeOfOccupations { get; set; }
/// <summary>
/// Gets or sets the name of the group for the schedule entry.

View File

@ -11,15 +11,7 @@ public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestH
{
public async Task<ScheduleListVm> 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.Group)
.Include(l => l.TypeOfOccupation)
.Include(l => l.Discipline)
.AsQueryable();
var query = dbContext.Lessons.AsQueryable();
if (request.IsEven != null)
query = query.Where(l => l.IsEven == request.IsEven);
@ -39,18 +31,33 @@ 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()
{
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,
IsExcludedWeeks = l.IsExcludedWeeks,
Weeks = l.SpecificWeeks?.Select(w => w.WeekNumber),
Group = l.Group!.Name,
GroupId = l.GroupId,
@ -68,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),

View File

@ -34,9 +34,14 @@ public class ScheduleLookupDto
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets the type of occupation.
/// Gets or sets exclude or include weeks for a specific discipline.
/// </summary>
public required string TypeOfOccupation { get; set; }
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// </summary>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the name of the group.
@ -48,6 +53,11 @@ public class ScheduleLookupDto
/// </summary>
public required int GroupId { get; set; }
/// <summary>
/// Gets or sets the type of occupation.
/// </summary>
public required IEnumerable<string> TypeOfOccupations { get; set; }
/// <summary>
/// Gets or sets the names of the lecture halls.
/// </summary>

View File

@ -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<SpecificWeek> SpecificWeeks { get; set; }
}

View File

@ -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<LessonAssociation>? LessonAssociations { get; set; }
public List<SpecificWeek>? SpecificWeeks { get; set; }
}

View File

@ -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; }

View File

@ -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; }
}

View File

@ -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<Lesson>? Lessons { get; set; }
public List<LessonAssociation>? Lessons { get; set; }
}

View File

@ -27,10 +27,10 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1
public async Task<ActionResult<List<ScheduleResponse>>> 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,9 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1
IsEven = s.IsEven,
Discipline = s.Discipline,
DisciplineId = s.DisciplineId,
TypeOfOccupation = s.TypeOfOccupation,
IsExcludedWeeks = s.IsExcludedWeeks,
Weeks = s.Weeks,
TypeOfOccupations = s.TypeOfOccupations,
Group = s.Group,
GroupId = s.GroupId,
LectureHalls = s.LectureHalls,
@ -117,7 +119,9 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1
IsEven = g.IsEven,
Discipline = g.Discipline,
DisciplineId = g.DisciplineId,
TypeOfOccupation = g.TypeOfOccupation,
IsExcludedWeeks = g.IsExcludedWeeks,
Weeks = g.Weeks,
TypeOfOccupations = g.TypeOfOccupations,
LectureHalls = g.LectureHalls,
LectureHallsId = g.LectureHallsId,
Professors = g.Professors,
@ -176,7 +180,9 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1
IsEven = p.IsEven,
Discipline = p.Discipline,
DisciplineId = p.DisciplineId,
TypeOfOccupation = p.TypeOfOccupation,
IsExcludedWeeks = p.IsExcludedWeeks,
Weeks = p.Weeks,
TypeOfOccupations = p.TypeOfOccupations,
Group = p.Group,
GroupId = p.GroupId,
LectureHalls = p.LectureHalls,
@ -235,7 +241,9 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1
IsEven = l.IsEven,
Discipline = l.Discipline,
DisciplineId = l.DisciplineId,
TypeOfOccupation = l.TypeOfOccupation,
IsExcludedWeeks = l.IsExcludedWeeks,
Weeks = l.Weeks,
TypeOfOccupations = l.TypeOfOccupations,
Group = l.Group,
GroupId = l.GroupId,
Professors = l.Professors,
@ -273,7 +281,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1
IsEven = isEven,
DisciplineIds = [id],
GroupIds = groups,
LectureHallIds = [id],
LectureHallIds = lectureHalls,
ProfessorIds = professors
})).Schedules;
@ -288,7 +296,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,

View File

@ -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<SpecificWeekDbContext> options) : DbContext(options), ISpecificWeekDbContext
{
public DbSet<SpecificWeek> SpecificWeeks { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new SpecificWeekConfiguration());
base.OnModelCreating(modelBuilder);
}
}

View File

@ -43,6 +43,7 @@ public static class DependencyInjection
services.AddDbContext<ProfessorDbContext>(dbConfig);
services.AddDbContext<LessonDbContext>(dbConfig);
services.AddDbContext<TypeOfOccupationDbContext>(dbConfig);
services.AddDbContext<SpecificWeekDbContext>(dbConfig);
services.AddDbContext<UberDbContext>(dbConfig);
}
@ -58,6 +59,7 @@ public static class DependencyInjection
services.AddScoped<IProfessorDbContext>(provider => provider.GetService<ProfessorDbContext>()!);
services.AddScoped<ILessonDbContext>(provider => provider.GetService<LessonDbContext>()!);
services.AddScoped<ITypeOfOccupationDbContext>(provider => provider.GetService<TypeOfOccupationDbContext>()!);
services.AddScoped<ISpecificWeekDbContext>(provider => provider.GetService<SpecificWeekDbContext>()!);
return services;
}

View File

@ -18,6 +18,8 @@ public class LessonAssociationConfiguration : IEntityTypeConfiguration<LessonAss
builder.Property(l => 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<LessonAss
.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);
}
}

View File

@ -13,27 +13,20 @@ public class LessonConfiguration : IEntityTypeConfiguration<Lesson>
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");
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)

View File

@ -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<SpecificWeek>
{
public void Configure(EntityTypeBuilder<SpecificWeek> 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);
}
}

View File

@ -14,6 +14,5 @@ public class TypeOfOccupationConfiguration : IEntityTypeConfiguration<TypeOfOccu
builder.Property(t => 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);
}
}

View File

@ -15,6 +15,7 @@ public class UberDbContext(DbContextOptions<UberDbContext> options) : DbContext(
public DbSet<Lesson> Lessons { get; set; } = null!;
public DbSet<Professor> Professors { get; set; } = null!;
public DbSet<TypeOfOccupation> TypeOfOccupations { get; set; } = null!;
public DbSet<SpecificWeek> SpecificWeeks { get; set; } = null!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@ -27,6 +28,7 @@ public class UberDbContext(DbContextOptions<UberDbContext> options) : DbContext(
modelBuilder.ApplyConfiguration(new ProfessorConfiguration());
modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration());
modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration());
modelBuilder.ApplyConfiguration(new SpecificWeekConfiguration());
base.OnModelCreating(modelBuilder);
}