Add controllers for the Get method #9
@ -0,0 +1,12 @@
|
||||
using MediatR;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Schedule.Queries.GetScheduleList;
|
||||
|
||||
public class GetScheduleListQuery : IRequest<ScheduleListVm>
|
||||
{
|
||||
public int[]? GroupIds { get; set; }
|
||||
public int[]? DisciplineIds { get; set; }
|
||||
public int[]? LectureHallIds { get; set; }
|
||||
public int[]? ProfessorIds { get; set; }
|
||||
public bool? IsEven { get; set; }
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Schedule.Queries.GetScheduleList;
|
||||
|
||||
public class GetScheduleListQueryHandler(ILessonDbContext dbContext) : IRequestHandler<GetScheduleListQuery, ScheduleListVm>
|
||||
{
|
||||
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();
|
||||
|
||||
if (request.IsEven != null)
|
||||
query = query.Where(l => l.IsEven == request.IsEven);
|
||||
|
||||
if (request.GroupIds != null && request.GroupIds.Length != 0)
|
||||
query = query.Where(l => request.GroupIds.Contains(l.GroupId));
|
||||
|
||||
if (request.DisciplineIds != null && request.DisciplineIds.Length != 0)
|
||||
query = query.Where(l => request.DisciplineIds.Contains(l.DisciplineId));
|
||||
|
||||
if (request.LectureHallIds != null && request.LectureHallIds.Length != 0)
|
||||
query = query.Where(l => l.LessonAssociations!.Any(la =>
|
||||
la.LectureHallId != null && request.LectureHallIds.Contains(la.LectureHallId.Value)));
|
||||
|
||||
if (request.ProfessorIds != null && request.ProfessorIds.Length != 0)
|
||||
query = query.Where(l =>
|
||||
l.LessonAssociations!.Any(la =>
|
||||
la.ProfessorId != null && request.ProfessorIds.Contains(la.ProfessorId.Value)));
|
||||
|
||||
var data = await query.ToArrayAsync(cancellationToken);
|
||||
|
||||
var result = data.Select(l => new ScheduleLookupDto()
|
||||
{
|
||||
DayOfWeek = l.DayOfWeek,
|
||||
PairNumber = l.PairNumber,
|
||||
IsEven = l.IsEven,
|
||||
Discipline = l.Discipline!.Name,
|
||||
TypeOfOccupation = l.TypeOfOccupation!.ShortName,
|
||||
|
||||
Group = l.Group!.Name,
|
||||
GroupId = l.GroupId,
|
||||
|
||||
LectureHalls = l.LessonAssociations!
|
||||
.Where(la => !string.IsNullOrEmpty(la.LectureHall?.Name))
|
||||
.Select(la => la.LectureHall?.Name),
|
||||
LectureHallsId = l.LessonAssociations!
|
||||
.Where(la => la.LectureHallId != null)
|
||||
.Select(la => la.LectureHallId),
|
||||
|
||||
Campus = l.LessonAssociations!
|
||||
.Where(la => !string.IsNullOrEmpty(la.LectureHall?.Campus?.CodeName))
|
||||
.Select(la => la.LectureHall?.Campus?.CodeName),
|
||||
CampusId = l.LessonAssociations!
|
||||
.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),
|
||||
ProfessorsId = l.LessonAssociations!
|
||||
.Where(la => la.ProfessorId != null)
|
||||
.Select(la => la.ProfessorId),
|
||||
|
||||
LinkToMeet = l.LessonAssociations!.Select(la => la.LinkToMeet)
|
||||
}).ToList();
|
||||
|
||||
return new ScheduleListVm
|
||||
{
|
||||
Schedules = result
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Schedule.Queries.GetScheduleList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model for a list of schedules.
|
||||
/// </summary>
|
||||
public class ScheduleListVm
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the list of schedules.
|
||||
/// </summary>
|
||||
public IList<ScheduleLookupDto> Schedules { get; set; } = new List<ScheduleLookupDto>();
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Mirea.Api.DataAccess.Application.Cqrs.Schedule.Queries.GetScheduleList;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a data transfer object for schedule lookup.
|
||||
/// </summary>
|
||||
public class ScheduleLookupDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the day of the week.
|
||||
/// </summary>
|
||||
public DayOfWeek DayOfWeek { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the pair number.
|
||||
/// </summary>
|
||||
public int PairNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the pair is on an even week.
|
||||
/// </summary>
|
||||
public bool IsEven { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the discipline.
|
||||
/// </summary>
|
||||
public required string Discipline { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of occupation.
|
||||
/// </summary>
|
||||
public required string TypeOfOccupation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the group.
|
||||
/// </summary>
|
||||
public required string Group { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ID of the group.
|
||||
/// </summary>
|
||||
public required int GroupId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the names of the lecture halls.
|
||||
/// </summary>
|
||||
public required IEnumerable<string?> LectureHalls { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IDs of the lecture halls.
|
||||
/// </summary>
|
||||
public required IEnumerable<int?> LectureHallsId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the names of the professors.
|
||||
/// </summary>
|
||||
public required IEnumerable<string?> Professors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IDs of the professors.
|
||||
/// </summary>
|
||||
public required IEnumerable<int?> ProfessorsId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the names of the campuses.
|
||||
/// </summary>
|
||||
public required IEnumerable<string?> Campus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the IDs of the campuses.
|
||||
/// </summary>
|
||||
public required IEnumerable<int?> CampusId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the links to online meetings.
|
||||
/// </summary>
|
||||
public required IEnumerable<string?> LinkToMeet { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user