refactor: move database-related projects to separate folder

This commit is contained in:
2024-05-29 07:49:42 +03:00
parent 081c814036
commit bf3a9d4b36
74 changed files with 5 additions and 43 deletions

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
/// <summary>
/// Represents basic information about a campus.
/// </summary>
public class CampusBasicInfoDto
{
/// <summary>
/// The unique identifier for the campus.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The code name associated with the campus.
/// </summary>
public required string CodeName { get; set; }
/// <summary>
/// The full name of the campus.
/// </summary>
public string? FullName { get; set; }
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
/// <summary>
/// Represents a view model containing basic information about multiple campuses.
/// </summary>
public class CampusBasicInfoVm
{
/// <summary>
/// The list of campus basic information.
/// </summary>
public IList<CampusBasicInfoDto> Campuses { get; set; } = new List<CampusBasicInfoDto>();
}

View File

@ -0,0 +1,5 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
public class GetCampusBasicInfoListQuery : IRequest<CampusBasicInfoVm>;

View File

@ -0,0 +1,26 @@
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.Campus.Queries.GetCampusBasicInfoList;
public class GetCampusBasicInfoListQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusBasicInfoListQuery, CampusBasicInfoVm>
{
public async Task<CampusBasicInfoVm> Handle(GetCampusBasicInfoListQuery request, CancellationToken cancellationToken)
{
var dtos = await dbContext.Campuses.Select(c => new CampusBasicInfoDto()
{
Id = c.Id,
CodeName = c.CodeName,
FullName = c.FullName
}).ToListAsync(cancellationToken);
return new CampusBasicInfoVm
{
Campuses = dtos
};
}
}

View File

@ -0,0 +1,27 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
/// <summary>
/// Represents a view model containing detailed information about a campus.
/// </summary>
public class CampusDetailsVm
{
/// <summary>
/// The unique identifier for the campus.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The code name associated with the campus.
/// </summary>
public required string CodeName { get; set; }
/// <summary>
/// The full name of the campus.
/// </summary>
public string? FullName { get; set; }
/// <summary>
/// The address of the campus.
/// </summary>
public string? Address { get; set; }
}

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
public class GetCampusDetailsQuery : IRequest<CampusDetailsVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,24 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
public class GetCampusDetailsQueryHandler(ICampusDbContext dbContext) : IRequestHandler<GetCampusDetailsQuery, CampusDetailsVm>
{
public async Task<CampusDetailsVm> Handle(GetCampusDetailsQuery request, CancellationToken cancellationToken)
{
var campus = await dbContext.Campuses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Campus), request.Id);
return new CampusDetailsVm()
{
Id = campus.Id,
CodeName = campus.CodeName,
FullName = campus.FullName,
Address = campus.Address
};
}
}

View File

@ -0,0 +1,17 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
/// <summary>
/// Represents disciplines.
/// </summary>
public class DisciplineInfoVm
{
/// <summary>
/// The unique identifier for the discipline.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the discipline.
/// </summary>
public required string Name { get; set; }
}

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
public class GetDisciplineInfoQuery : IRequest<DisciplineInfoVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,22 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
public class GetDisciplineInfoQueryHandler(IDisciplineDbContext dbContext) : IRequestHandler<GetDisciplineInfoQuery, DisciplineInfoVm>
{
public async Task<DisciplineInfoVm> Handle(GetDisciplineInfoQuery request, CancellationToken cancellationToken)
{
var discipline = await dbContext.Disciplines.FirstOrDefaultAsync(d => d.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Discipline), request.Id);
return new DisciplineInfoVm()
{
Id = discipline.Id,
Name = discipline.Name,
};
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
/// <summary>
/// Represents a view model containing multiple disciplines name.
/// </summary>
public class DisciplineListVm
{
/// <summary>
/// The list of disciplines.
/// </summary>
public IList<DisciplineLookupDto> Disciplines { get; set; } = new List<DisciplineLookupDto>();
}

View File

@ -0,0 +1,17 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
/// <summary>
/// Represents disciplines.
/// </summary>
public class DisciplineLookupDto
{
/// <summary>
/// The unique identifier for the discipline.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the discipline.
/// </summary>
public required string Name { get; set; }
}

View File

@ -0,0 +1,9 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
public class GetDisciplineListQuery : IRequest<DisciplineListVm>
{
public int? Page { get; set; }
public int? PageSize { get; set; }
}

View File

@ -0,0 +1,30 @@
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.Discipline.Queries.GetDisciplineList;
public class GetDisciplineListQueryHandler(IDisciplineDbContext dbContext) : IRequestHandler<GetDisciplineListQuery, DisciplineListVm>
{
public async Task<DisciplineListVm> Handle(GetDisciplineListQuery request, CancellationToken cancellationToken)
{
var dtos = dbContext.Disciplines.OrderBy(d => d.Id).Select(d => new DisciplineLookupDto()
{
Id = d.Id,
Name = d.Name,
});
if (request is { PageSize: not null, Page: not null })
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
var result = await dtos.ToListAsync(cancellationToken);
return new DisciplineListVm
{
Disciplines = result
};
}
}

View File

@ -0,0 +1,32 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
/// <summary>
/// Represents faculties.
/// </summary>
public class FacultyInfoVm
{
/// <summary>
/// The unique identifier for the faculty.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the faculty.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// ID indicating the faculty's affiliation to the campus.
/// </summary>
public int? CampusId { get; set; }
/// <summary>
/// Campus name indicating the faculty's affiliation to the campus.
/// </summary>
public string? CampusName { get; set; }
/// <summary>
/// Campus code indicating the faculty's affiliation to the campus.
/// </summary>
public string? CampusCode { get; set; }
}

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
public class GetFacultyInfoQuery : IRequest<FacultyInfoVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,27 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
public class GetFacultyInfoQueryHandler(IFacultyDbContext dbContext) : IRequestHandler<GetFacultyInfoQuery, FacultyInfoVm>
{
public async Task<FacultyInfoVm> Handle(GetFacultyInfoQuery request, CancellationToken cancellationToken)
{
var faculty = await dbContext.Faculties
.Include(f => f.Campus)
.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Faculty), request.Id);
return new FacultyInfoVm()
{
Id = faculty.Id,
Name = faculty.Name,
CampusId = faculty.CampusId,
CampusName = faculty.Campus?.FullName,
CampusCode = faculty.Campus?.CodeName
};
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
/// <summary>
/// Represents a view model containing multiple faculties.
/// </summary>
public class FacultyListVm
{
/// <summary>
/// The list of faculties.
/// </summary>
public IList<FacultyLookupDto> Faculties { get; set; } = new List<FacultyLookupDto>();
}

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
/// <summary>
/// Represents faculties.
/// </summary>
public class FacultyLookupDto
{
/// <summary>
/// The unique identifier for the faculty.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the faculty.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// ID indicating the faculty's affiliation to the campus.
/// </summary>
public int? CampusId { get; set; }
}

View File

@ -0,0 +1,9 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
public class GetFacultyListQuery : IRequest<FacultyListVm>
{
public int? Page { get; set; }
public int? PageSize { get; set; }
}

View File

@ -0,0 +1,31 @@
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.Faculty.Queries.GetFacultyList;
public class GetFacultyListQueryHandler(IFacultyDbContext dbContext) : IRequestHandler<GetFacultyListQuery, FacultyListVm>
{
public async Task<FacultyListVm> Handle(GetFacultyListQuery request, CancellationToken cancellationToken)
{
var dtos = dbContext.Faculties.OrderBy(f => f.Id).Select(f => new FacultyLookupDto()
{
Id = f.Id,
Name = f.Name,
CampusId = f.CampusId
});
if (request is { PageSize: not null, Page: not null })
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
var result = await dtos.ToListAsync(cancellationToken);
return new FacultyListVm
{
Faculties = result
};
}
}

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails;
public class GetGroupInfoQuery : IRequest<GroupInfoVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,28 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Group
.Queries.GetGroupDetails;
public class GetGroupInfoQueryHandler(IGroupDbContext dbContext) : IRequestHandler<GetGroupInfoQuery, GroupInfoVm>
{
public async Task<GroupInfoVm> Handle(GetGroupInfoQuery request, CancellationToken cancellationToken)
{
var discipline = await dbContext.Groups
.Include(g => g.Faculty)
.FirstOrDefaultAsync(g => g.Id == request.Id, cancellationToken)
?? throw new NotFoundException(typeof(Domain.Schedule.Group), request.Id);
return new GroupInfoVm()
{
Id = discipline.Id,
Name = discipline.Name,
Faculty = discipline.Faculty?.Name,
FacultyId = discipline.FacultyId
};
}
}

View File

@ -0,0 +1,27 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails;
/// <summary>
/// Represents groups.
/// </summary>
public class GroupInfoVm
{
/// <summary>
/// The unique identifier for the group.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the group.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// The faculty name for the group.
/// </summary>
public string? Faculty { get; set; }
/// <summary>
/// The faculty identifier for the group.
/// </summary>
public int? FacultyId { get; set; }
}

View File

@ -0,0 +1,9 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
public class GetGroupListQuery : IRequest<GroupListVm>
{
public int? Page { get; set; }
public int? PageSize { get; set; }
}

View File

@ -0,0 +1,31 @@
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.Group.Queries.GetGroupList;
public class GetGroupListQueryHandler(IGroupDbContext dbContext) : IRequestHandler<GetGroupListQuery, GroupListVm>
{
public async Task<GroupListVm> Handle(GetGroupListQuery request, CancellationToken cancellationToken)
{
var dtos = dbContext.Groups.OrderBy(g => g.Id).Select(g => new GroupLookupDto()
{
Id = g.Id,
Name = g.Name,
FacultyId = g.FacultyId
});
if (request is { PageSize: not null, Page: not null })
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
var result = await dtos.ToListAsync(cancellationToken);
return new GroupListVm
{
Groups = result
};
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
/// <summary>
/// Represents a view model containing multiple groups name.
/// </summary>
public class GroupListVm
{
/// <summary>
/// The list of groups.
/// </summary>
public IList<GroupLookupDto> Groups { get; set; } = new List<GroupLookupDto>();
}

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
/// <summary>
/// Represents groups.
/// </summary>
public class GroupLookupDto
{
/// <summary>
/// The unique identifier for the group.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the group.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// The faculty identifier for the group.
/// </summary>
public int? FacultyId { get; set; }
}

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
public class GetLectureHallInfoQuery : IRequest<LectureHallInfoVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,28 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
public class GetLectureHallInfoQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallInfoQuery, LectureHallInfoVm>
{
public async Task<LectureHallInfoVm> Handle(GetLectureHallInfoQuery request, CancellationToken cancellationToken)
{
var lectureHall = await dbContext.LectureHalls
.Include(l => l.Campus)
.FirstOrDefaultAsync(l => l.Id == request.Id, cancellationToken)
?? throw new NotFoundException(typeof(Domain.Schedule.LectureHall), request.Id);
return new LectureHallInfoVm()
{
Id = lectureHall.Id,
Name = lectureHall.Name,
CampusId = lectureHall.CampusId,
CampusCode = lectureHall.Campus?.CodeName,
CampusName = lectureHall.Campus?.FullName
};
}
}

View File

@ -0,0 +1,32 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
/// <summary>
/// Represents disciplines.
/// </summary>
public class LectureHallInfoVm
{
/// <summary>
/// The unique identifier for the lecture hall.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the lecture hall.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// ID indicating the lecture hall's affiliation to the campus.
/// </summary>
public int CampusId { get; set; }
/// <summary>
/// Campus name indicating the lecture hall's affiliation to the campus.
/// </summary>
public string? CampusName { get; set; }
/// <summary>
/// Campus code indicating the lecture hall's affiliation to the campus.
/// </summary>
public string? CampusCode { get; set; }
}

View File

@ -0,0 +1,9 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
public class GetLectureHallListQuery : IRequest<LectureHallListVm>
{
public int? Page { get; set; }
public int? PageSize { get; set; }
}

View File

@ -0,0 +1,31 @@
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.LectureHall.Queries.GetLectureHallList;
public class GetLectureHallListQueryHandler(ILectureHallDbContext dbContext) : IRequestHandler<GetLectureHallListQuery, LectureHallListVm>
{
public async Task<LectureHallListVm> Handle(GetLectureHallListQuery request, CancellationToken cancellationToken)
{
var dtos = dbContext.LectureHalls.OrderBy(l => l.Id).Select(l => new LectureHallLookupDto()
{
Id = l.Id,
Name = l.Name,
CampusId = l.CampusId
});
if (request is { PageSize: not null, Page: not null })
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
var result = await dtos.ToListAsync(cancellationToken);
return new LectureHallListVm
{
LectureHalls = result
};
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
/// <summary>
/// Represents a view model containing multiple disciplines name.
/// </summary>
public class LectureHallListVm
{
/// <summary>
/// The list of lecture hall.
/// </summary>
public IList<LectureHallLookupDto> LectureHalls { get; set; } = new List<LectureHallLookupDto>();
}

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
/// <summary>
/// Represents lecture halls.
/// </summary>
public class LectureHallLookupDto
{
/// <summary>
/// The unique identifier for the lecture hall.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the lecture hall.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// ID indicating the lecture hall's affiliation to the campus.
/// </summary>
public int CampusId { get; set; }
}

View File

@ -0,0 +1,8 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
public class GetProfessorInfoQuery : IRequest<ProfessorInfoVm>
{
public required int Id { get; set; }
}

View File

@ -0,0 +1,22 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Mirea.Api.DataAccess.Application.Common.Exceptions;
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
using System.Threading;
using System.Threading.Tasks;
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
public class GetProfessorInfoQueryHandler(IProfessorDbContext dbContext) : IRequestHandler<GetProfessorInfoQuery, ProfessorInfoVm>
{
public async Task<ProfessorInfoVm> Handle(GetProfessorInfoQuery request, CancellationToken cancellationToken)
{
var discipline = await dbContext.Professors.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Professor), request.Id);
return new ProfessorInfoVm()
{
Id = discipline.Id,
Name = discipline.Name,
};
}
}

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
/// <summary>
/// Represents professors.
/// </summary>
public class ProfessorInfoVm
{
/// <summary>
/// The unique identifier for the professor.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the professor.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// The alt name of the professor. Usually is full name.
/// </summary>
public string? AltName { get; set; }
}

View File

@ -0,0 +1,9 @@
using MediatR;
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
public class GetProfessorListQuery : IRequest<ProfessorListVm>
{
public int? Page { get; set; }
public int? PageSize { get; set; }
}

View File

@ -0,0 +1,31 @@
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.Professor.Queries.GetProfessorList;
public class GetProfessorListQueryHandler(IProfessorDbContext dbContext) : IRequestHandler<GetProfessorListQuery, ProfessorListVm>
{
public async Task<ProfessorListVm> Handle(GetProfessorListQuery request, CancellationToken cancellationToken)
{
var dtos = dbContext.Professors.OrderBy(p => p.Id).Select(p => new ProfessorLookupDto()
{
Id = p.Id,
Name = p.Name,
AltName = p.AltName
});
if (request is { PageSize: not null, Page: not null })
dtos = dtos.Skip(request.Page.Value * request.PageSize.Value).Take(request.PageSize.Value);
var result = await dtos.ToListAsync(cancellationToken);
return new ProfessorListVm
{
Professors = result
};
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
/// <summary>
/// Represents a view model containing multiple professors name.
/// </summary>
public class ProfessorListVm
{
/// <summary>
/// The list of professors.
/// </summary>
public IList<ProfessorLookupDto> Professors { get; set; } = new List<ProfessorLookupDto>();
}

View File

@ -0,0 +1,22 @@
namespace Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
/// <summary>
/// Represents professor.
/// </summary>
public class ProfessorLookupDto
{
/// <summary>
/// The unique identifier for the professor.
/// </summary>
public int Id { get; set; }
/// <summary>
/// The name of the professor.
/// </summary>
public required string Name { get; set; }
/// <summary>
/// The alt name of the professor. Usually is full name.
/// </summary>
public string? AltName { get; set; }
}

View File

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

View File

@ -0,0 +1,93 @@
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.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
.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,
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,
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
};
}
}

View File

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

View File

@ -0,0 +1,95 @@
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 ID of the discipline.
/// </summary>
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets exclude or include weeks for a specific discipline.
/// </summary>
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.
/// </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 type of occupation.
/// </summary>
public required IEnumerable<string> TypeOfOccupations { 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; }
}