Add controllers for the Get method (#9)

Reviewed-on: #9
This commit is contained in:
Polianin Nikita 2024-02-19 12:06:30 +03:00
commit ed0143cda1
38 changed files with 1894 additions and 4 deletions

23
ApiDto/ApiDto.csproj Normal file
View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Company>Winsomnia</Company>
<Version>1.0.0-a0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<AssemblyName>Mirea.Api.Dto</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<DocumentationFile>ApiDtoDocs.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Update="ApiDtoDocs.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,37 @@
namespace Mirea.Api.Dto.Requests;
/// <summary>
/// Represents a request object for retrieving schedules based on various filters.
/// </summary>
public class ScheduleRequest
{
/// <summary>
/// Gets or sets an array of group IDs.
/// </summary>
/// <remarks>This array can contain null values.</remarks>
public int[]? Groups { get; set; } = null;
/// <summary>
/// Gets or sets a value indicating whether to retrieve schedules for even weeks.
/// </summary>
/// <remarks>This property can contain null.</remarks>
public bool? IsEven { get; set; } = null;
/// <summary>
/// Gets or sets an array of discipline IDs.
/// </summary>
/// <remarks>This array can contain null values.</remarks>
public int[]? Disciplines { get; set; } = null;
/// <summary>
/// Gets or sets an array of professor IDs.
/// </summary>
/// <remarks>This array can contain null values.</remarks>
public int[]? Professors { get; set; } = null;
/// <summary>
/// Gets or sets an array of lecture hall IDs.
/// </summary>
/// <remarks>This array can contain null values.</remarks>
public int[]? LectureHalls { get; set; } = null;
}

View File

@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents basic information about a campus.
/// </summary>
public class CampusBasicInfoResponse
{
/// <summary>
/// Gets or sets the unique identifier of the campus.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the code name of the campus.
/// </summary>
[Required]
public required string CodeName { get; set; }
/// <summary>
/// Gets or sets the full name of the campus (optional).
/// </summary>
public string? FullName { get; set; }
}

View File

@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents detailed information about a campus.
/// </summary>
public class CampusDetailsResponse
{
/// <summary>
/// Gets or sets the unique identifier of the campus.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the code name of the campus.
/// </summary>
[Required]
public required string CodeName { get; set; }
/// <summary>
/// Gets or sets the full name of the campus (optional).
/// </summary>
public string? FullName { get; set; }
/// <summary>
/// Gets or sets the address of the campus (optional).
/// </summary>
public string? Address { get; set; }
}

View File

@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents information about a discipline.
/// </summary>
public class DisciplineResponse
{
/// <summary>
/// Gets or sets the unique identifier of the discipline.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the discipline.
/// </summary>
[Required]
public required string Name { get; set; }
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// A class for providing information about an error
/// </summary>
public class ErrorResponse
{
/// <summary>
/// The text or translation code of the error. This field may not contain information in specific scenarios.
/// For example, it might be empty for HTTP 204 responses where no content is returned or if the validation texts have not been configured.
/// </summary>
[Required]
public required string Error { get; set; }
/// <summary>
/// In addition to returning the response code in the header, it is also duplicated in this field.
/// Represents the HTTP response code.
/// </summary>
[Required]
public required int Code { get; set; }
}

View File

@ -0,0 +1,36 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents detailed information about a faculty.
/// </summary>
public class FacultyDetailsResponse
{
/// <summary>
/// Gets or sets the unique identifier of the faculty.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the faculty.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the campus to which the faculty belongs (optional).
/// </summary>
public int? CampusId { get; set; }
/// <summary>
/// Gets or sets the name of the campus to which the faculty belongs (optional).
/// </summary>
public string? CampusName { get; set; }
/// <summary>
/// Gets or sets the code name of the campus to which the faculty belongs (optional).
/// </summary>
public string? CampusCode { get; set; }
}

View File

@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents basic information about a faculty.
/// </summary>
public class FacultyResponse
{
/// <summary>
/// Gets or sets the unique identifier of the faculty.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the faculty.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the campus to which the faculty belongs (optional).
/// </summary>
public int? CampusId { get; set; }
}

View File

@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents detailed information about a group.
/// </summary>
public class GroupDetailsResponse
{
/// <summary>
/// Gets or sets the unique identifier of the group.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the group.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the course number of the group.
/// </summary>
[Required]
public int CourseNumber { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the faculty to which the group belongs (optional).
/// </summary>
public int? FacultyId { get; set; }
/// <summary>
/// Gets or sets the name of the faculty to which the group belongs (optional).
/// </summary>
public string? FacultyName { get; set; }
}

View File

@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents basic information about a group.
/// </summary>
public class GroupResponse
{
/// <summary>
/// Gets or sets the unique identifier of the group.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the group.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the course number of the group.
/// </summary>
[Required]
public int CourseNumber { get; set; }
/// <summary>
/// Gets or sets the unique identifier of the faculty to which the group belongs (optional).
/// </summary>
public int? FacultyId { get; set; }
}

View File

@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents the detailed response model for a lecture hall.
/// </summary>
public class LectureHallDetailsResponse
{
/// <summary>
/// Gets or sets the ID of the lecture hall.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the lecture hall.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the ID of the campus to which the lecture hall belongs.
/// </summary>
[Required]
public int CampusId { get; set; }
/// <summary>
/// Gets or sets the name of the campus.
/// </summary>
public string? CampusName { get; set; }
/// <summary>
/// Gets or sets the code of the campus.
/// </summary>
public string? CampusCode { get; set; }
}

View File

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents the response model for a lecture hall.
/// </summary>
public class LectureHallResponse
{
/// <summary>
/// Gets or sets the ID of the lecture hall.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the lecture hall.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the ID of the campus to which the lecture hall belongs.
/// </summary>
[Required]
public int CampusId { get; set; }
}

View File

@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents information about a professor.
/// </summary>
public class ProfessorResponse
{
/// <summary>
/// Gets or sets the unique identifier of the professor.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Gets or sets the name of the professor.
/// </summary>
[Required]
public required string Name { get; set; }
/// <summary>
/// Gets or sets the alternate name of the professor (optional).
/// </summary>
public string? AltName { get; set; }
}

View File

@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses.Schedule;
/// <summary>
/// Represents information about a specific schedule entry for a professor.
/// </summary>
public class DisciplineScheduleInfo
{
/// <summary>
/// Gets or sets the day of the week for the schedule entry.
/// </summary>
[Required]
public DayOfWeek DayOfWeek { get; set; }
/// <summary>
/// Gets or sets the pair number for the schedule entry.
/// </summary>
[Required]
public int PairNumber { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the pair is on an even week.
/// </summary>
[Required]
public bool IsEven { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
/// <summary>
/// Gets or sets the names of the group for the schedule entry.
/// </summary>
[Required]
public required string Group { get; set; }
/// <summary>
/// Gets or sets the IDs of the group for the schedule entry.
/// </summary>
[Required]
public required int GroupId { get; set; }
/// <summary>
/// Gets or sets the names of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<string?> LectureHalls { get; set; }
/// <summary>
/// Gets or sets the IDs of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<int?> LectureHallsId { get; set; }
/// <summary>
/// Gets or sets the names of the professors for the schedule entry.
/// </summary>
public required IEnumerable<string?> Professors { get; set; }
/// <summary>
/// Gets or sets the IDs of the professors for the schedule entry.
/// </summary>
public required IEnumerable<int?> ProfessorsId { get; set; }
/// <summary>
/// Gets or sets the names of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<string?> Campus { get; set; }
/// <summary>
/// Gets or sets the IDs of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<int?> CampusId { get; set; }
/// <summary>
/// Gets or sets the links to online meetings for the schedule entry.
/// </summary>
public required IEnumerable<string?> LinkToMeet { get; set; }
}
/// <summary>
/// Represents a response containing schedule information for a professor.
/// </summary>
public class DisciplineScheduleResponse
{
/// <summary>
/// Gets or sets the name of the discipline.
/// </summary>
[Required]
public required string Discipline { get; set; }
/// <summary>
/// Gets or sets the ID of the discipline.
/// </summary>
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets the schedules for the professor.
/// </summary>
[Required]
public required IEnumerable<DisciplineScheduleInfo> Schedules { get; set; }
}

View File

@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses.Schedule;
/// <summary>
/// Represents information about a specific schedule entry for a group.
/// </summary>
public class GroupScheduleInfo
{
/// <summary>
/// Gets or sets the day of the week for the schedule entry.
/// </summary>
[Required]
public DayOfWeek DayOfWeek { get; set; }
/// <summary>
/// Gets or sets the pair number for the schedule entry.
/// </summary>
[Required]
public int PairNumber { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the pair is on an even week.
/// </summary>
[Required]
public bool IsEven { get; set; }
/// <summary>
/// Gets or sets the name of the discipline for the schedule entry.
/// </summary>
[Required]
public required string Discipline { get; set; }
/// <summary>
/// Gets or sets the ID of the discipline for the schedule entry.
/// </summary>
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
/// <summary>
/// Gets or sets the names of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<string?> LectureHalls { get; set; }
/// <summary>
/// Gets or sets the IDs of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<int?> LectureHallsId { get; set; }
/// <summary>
/// Gets or sets the names of the professors for the schedule entry.
/// </summary>
public required IEnumerable<string?> Professors { get; set; }
/// <summary>
/// Gets or sets the IDs of the professors for the schedule entry.
/// </summary>
public required IEnumerable<int?> ProfessorsId { get; set; }
/// <summary>
/// Gets or sets the names of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<string?> Campus { get; set; }
/// <summary>
/// Gets or sets the IDs of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<int?> CampusId { get; set; }
/// <summary>
/// Gets or sets the links to online meetings for the schedule entry.
/// </summary>
public required IEnumerable<string?> LinkToMeet { get; set; }
}
/// <summary>
/// Represents a response containing schedule information for a group.
/// </summary>
public class GroupScheduleResponse
{
/// <summary>
/// Gets or sets the name of the group.
/// </summary>
[Required]
public required string Group { get; set; }
/// <summary>
/// Gets or sets the ID of the group.
/// </summary>
[Required]
public required int GroupId { get; set; }
/// <summary>
/// Gets or sets the schedules for the group.
/// </summary>
[Required]
public required IEnumerable<GroupScheduleInfo> Schedules { get; set; }
}

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses.Schedule;
/// <summary>
/// Represents information about a specific schedule entry for a lecture hall.
/// </summary>
public class LectureHallScheduleInfo
{
/// <summary>
/// Gets or sets the day of the week for the schedule entry.
/// </summary>
[Required]
public DayOfWeek DayOfWeek { get; set; }
/// <summary>
/// Gets or sets the pair number for the schedule entry.
/// </summary>
[Required]
public int PairNumber { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the pair is on an even week.
/// </summary>
[Required]
public bool IsEven { get; set; }
/// <summary>
/// Gets or sets the name of the discipline for the schedule entry.
/// </summary>
[Required]
public required string Discipline { get; set; }
/// <summary>
/// Gets or sets the ID of the discipline for the schedule entry.
/// </summary>
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
/// <summary>
/// Gets or sets the names of the group for the schedule entry.
/// </summary>
[Required]
public required string Group { get; set; }
/// <summary>
/// Gets or sets the IDs of the group for the schedule entry.
/// </summary>
[Required]
public required int GroupId { get; set; }
/// <summary>
/// Gets or sets the names of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<string?> Campus { get; set; }
/// <summary>
/// Gets or sets the IDs of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<int?> CampusId { get; set; }
/// <summary>
/// Gets or sets the names of the professors for the schedule entry.
/// </summary>
public required IEnumerable<string?> Professors { get; set; }
/// <summary>
/// Gets or sets the IDs of the professors for the schedule entry.
/// </summary>
public required IEnumerable<int?> ProfessorsId { get; set; }
/// <summary>
/// Gets or sets the links to online meetings for the schedule entry.
/// </summary>
public required IEnumerable<string?> LinkToMeet { get; set; }
}
/// <summary>
/// Represents a response containing schedule information for a lecture hall.
/// </summary>
public class LectureHallScheduleResponse
{
/// <summary>
/// Gets or sets the names of the lecture halls.
/// </summary>
public required string LectureHalls { get; set; }
/// <summary>
/// Gets or sets the IDs of the lecture halls.
/// </summary>
public required int LectureHallsId { get; set; }
/// <summary>
/// Gets or sets the schedules for the lecture hall.
/// </summary>
[Required]
public required IEnumerable<LectureHallScheduleInfo> Schedules { get; set; }
}

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses.Schedule;
/// <summary>
/// Represents information about a specific schedule entry for a professor.
/// </summary>
public class ProfessorScheduleInfo
{
/// <summary>
/// Gets or sets the day of the week for the schedule entry.
/// </summary>
[Required]
public DayOfWeek DayOfWeek { get; set; }
/// <summary>
/// Gets or sets the pair number for the schedule entry.
/// </summary>
[Required]
public int PairNumber { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the pair is on an even week.
/// </summary>
[Required]
public bool IsEven { get; set; }
/// <summary>
/// Gets or sets the name of the discipline for the schedule entry.
/// </summary>
[Required]
public required string Discipline { get; set; }
/// <summary>
/// Gets or sets the ID of the discipline for the schedule entry.
/// </summary>
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
/// <summary>
/// Gets or sets the names of the group for the schedule entry.
/// </summary>
[Required]
public required string Group { get; set; }
/// <summary>
/// Gets or sets the IDs of the group for the schedule entry.
/// </summary>
[Required]
public required int GroupId { get; set; }
/// <summary>
/// Gets or sets the names of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<string?> LectureHalls { get; set; }
/// <summary>
/// Gets or sets the IDs of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<int?> LectureHallsId { get; set; }
/// <summary>
/// Gets or sets the names of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<string?> Campus { get; set; }
/// <summary>
/// Gets or sets the IDs of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<int?> CampusId { get; set; }
/// <summary>
/// Gets or sets the links to online meetings for the schedule entry.
/// </summary>
public required IEnumerable<string?> LinkToMeet { get; set; }
}
/// <summary>
/// Represents a response containing schedule information for a professor.
/// </summary>
public class ProfessorScheduleResponse
{
/// <summary>
/// Gets or sets the name of the professor.
/// </summary>
[Required]
public required string Professor { get; set; }
/// <summary>
/// Gets or sets the ID of the professor.
/// </summary>
[Required]
public required int ProfessorId { get; set; }
/// <summary>
/// Gets or sets the schedules for the professor.
/// </summary>
[Required]
public required IEnumerable<ProfessorScheduleInfo> Schedules { get; set; }
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses.Schedule;
/// <summary>
/// Represents a response object containing schedule information.
/// </summary>
public class ScheduleResponse
{
/// <summary>
/// Gets or sets the day of the week for the schedule entry.
/// </summary>
[Required]
public DayOfWeek DayOfWeek { get; set; }
/// <summary>
/// Gets or sets the pair number for the schedule entry.
/// </summary>
[Required]
public int PairNumber { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the pair is on an even week.
/// </summary>
[Required]
public bool IsEven { get; set; }
/// <summary>
/// Gets or sets the name of the discipline for the schedule entry.
/// </summary>
[Required]
public required string Discipline { get; set; }
/// <summary>
/// Gets or sets the ID of the discipline for the schedule entry.
/// </summary>
[Required]
public required int DisciplineId { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required string TypeOfOccupation { get; set; }
/// <summary>
/// Gets or sets the name of the group for the schedule entry.
/// </summary>
[Required]
public required string Group { get; set; }
/// <summary>
/// Gets or sets the ID of the group for the schedule entry.
/// </summary>
[Required]
public required int GroupId { get; set; }
/// <summary>
/// Gets or sets the names of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<string?> LectureHalls { get; set; }
/// <summary>
/// Gets or sets the IDs of the lecture halls for the schedule entry.
/// </summary>
public required IEnumerable<int?> LectureHallsId { get; set; }
/// <summary>
/// Gets or sets the names of the professors for the schedule entry.
/// </summary>
public required IEnumerable<string?> Professors { get; set; }
/// <summary>
/// Gets or sets the IDs of the professors for the schedule entry.
/// </summary>
public required IEnumerable<int?> ProfessorsId { get; set; }
/// <summary>
/// Gets or sets the names of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<string?> Campus { get; set; }
/// <summary>
/// Gets or sets the IDs of the campuses for the schedule entry.
/// </summary>
public required IEnumerable<int?> CampusId { get; set; }
/// <summary>
/// Gets or sets the links to online meetings for the schedule entry.
/// </summary>
public required IEnumerable<string?> LinkToMeet { 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,87 @@
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,
TypeOfOccupation = l.TypeOfOccupation!.ShortName,
Discipline = l.Discipline!.Name,
DisciplineId = l.DisciplineId,
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,85 @@
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 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; }
}

View File

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.Dto.Responses;
using System;
namespace Mirea.Api.Endpoint.Common.Attributes;
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public class BadRequestResponseAttribute() : ProducesResponseTypeAttribute(typeof(ErrorResponse), StatusCodes.Status400BadRequest);

View File

@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.Dto.Responses;
using System;
namespace Mirea.Api.Endpoint.Common.Attributes;
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public class NotFoundResponseAttribute() : ProducesResponseTypeAttribute(typeof(ErrorResponse), StatusCodes.Status404NotFound);

View File

@ -5,7 +5,7 @@ using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using System; using System;
namespace Mirea.Api.Endpoint; namespace Mirea.Api.Endpoint.Configuration;
public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions> public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions>
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using System.IO; using System.IO;
namespace Mirea.Api.Endpoint; namespace Mirea.Api.Endpoint.Configuration;
internal static class EnvironmentManager internal static class EnvironmentManager
{ {

View File

@ -6,7 +6,7 @@ using System;
using System.Linq; using System.Linq;
using System.Text.Json; using System.Text.Json;
namespace Mirea.Api.Endpoint; namespace Mirea.Api.Endpoint.Configuration;
public class SwaggerDefaultValues : IOperationFilter public class SwaggerDefaultValues : IOperationFilter
{ {
@ -38,7 +38,7 @@ public class SwaggerDefaultValues : IOperationFilter
{ {
var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name); var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
parameter.Description ??= description.ModelMetadata?.Description; parameter.Description ??= description.ModelMetadata.Description;
if (parameter.Schema.Default == null && if (parameter.Schema.Default == null &&
description.DefaultValue != null && description.DefaultValue != null &&

View File

@ -0,0 +1,7 @@
using Microsoft.AspNetCore.Mvc;
namespace Mirea.Api.Endpoint.Controllers;
[ApiController]
[Route("api/[controller]/[action]")]
public class BaseController : ControllerBase;

View File

@ -0,0 +1,8 @@
using Microsoft.AspNetCore.Mvc;
namespace Mirea.Api.Endpoint.Controllers.V1;
[ApiVersion("1.0")]
[Produces("application/json")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
public class BaseControllerV1 : BaseController;

View File

@ -0,0 +1,61 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusBasicInfoList;
using Mirea.Api.DataAccess.Application.Cqrs.Campus.Queries.GetCampusDetails;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1
{
public class CampusController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Gets basic information about campuses.
/// </summary>
/// <returns>Basic information about campuses.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<List<CampusBasicInfoResponse>>> Get()
{
var result = await mediator.Send(new GetCampusBasicInfoListQuery());
return Ok(result.Campuses
.Select(c => new CampusBasicInfoResponse()
{
Id = c.Id,
CodeName = c.CodeName,
FullName = c.FullName
})
);
}
/// <summary>
/// Gets details of a specific campus by ID.
/// </summary>
/// <param name="id">Campus ID.</param>
/// <returns>Details of the specified campus.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<CampusDetailsResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetCampusDetailsQuery()
{
Id = id
});
return Ok(new CampusDetailsResponse()
{
Id = result.Id,
CodeName = result.CodeName,
FullName = result.FullName,
Address = result.Address
});
}
}
}

View File

@ -0,0 +1,65 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineDetails;
using Mirea.Api.DataAccess.Application.Cqrs.Discipline.Queries.GetDisciplineList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1
{
public class DisciplineController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Gets a paginated list of disciplines.
/// </summary>
/// <param name="page">Page number. Start from 0.</param>
/// <param name="pageSize">Number of items per page.</param>
/// <returns>Paginated list of disciplines.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
public async Task<ActionResult<List<DisciplineResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
{
var result = await mediator.Send(new GetDisciplineListQuery()
{
Page = page,
PageSize = pageSize
});
return Ok(result.Disciplines
.Select(d => new DisciplineResponse()
{
Id = d.Id,
Name = d.Name
})
);
}
/// <summary>
/// Gets details of a specific discipline by ID.
/// </summary>
/// <param name="id">Discipline ID.</param>
/// <returns>Details of the specified discipline.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<DisciplineResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetDisciplineInfoQuery()
{
Id = id
});
return Ok(new DisciplineResponse()
{
Id = result.Id,
Name = result.Name
});
}
}
}

View File

@ -0,0 +1,69 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyDetails;
using Mirea.Api.DataAccess.Application.Cqrs.Faculty.Queries.GetFacultyList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1
{
public class FacultyController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Gets a paginated list of faculties.
/// </summary>
/// <param name="page">Page number. Start from 0.</param>
/// <param name="pageSize">Number of items per page.</param>
/// <returns>Paginated list of faculties.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
public async Task<ActionResult<List<FacultyResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
{
var result = await mediator.Send(new GetFacultyListQuery()
{
Page = page,
PageSize = pageSize
});
return Ok(result.Faculties
.Select(f => new FacultyResponse()
{
Id = f.Id,
Name = f.Name,
CampusId = f.CampusId
})
);
}
/// <summary>
/// Gets details of a specific faculty by ID.
/// </summary>
/// <param name="id">Faculty ID.</param>
/// <returns>Details of the specified faculty.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<FacultyDetailsResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetFacultyInfoQuery()
{
Id = id
});
return Ok(new FacultyDetailsResponse()
{
Id = result.Id,
Name = result.Name,
CampusId = result.CampusId,
CampusCode = result.CampusCode,
CampusName = result.CampusName
});
}
}
}

View File

@ -0,0 +1,108 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupDetails;
using Mirea.Api.DataAccess.Application.Cqrs.Group.Queries.GetGroupList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1
{
public class GroupController(IMediator mediator) : BaseControllerV1
{
private static int GetCourseNumber(string groupName)
{
var current = DateTime.Now;
if (!int.TryParse(groupName[2..], out var yearOfGroup)
&& !int.TryParse(groupName.Split('-')[^1][..2], out yearOfGroup))
return -1;
// Convert a two-digit year to a four-digit one
yearOfGroup += current.Year / 100 * 100;
return current.Year - yearOfGroup + (current.Month < 9 ? 0 : 1);
}
/// <summary>
/// Retrieves a list of groups.
/// </summary>
/// <param name="page">The page number for pagination (optional).</param>
/// <param name="pageSize">The page size for pagination (optional).</param>
/// <returns>A list of groups.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
public async Task<ActionResult<List<GroupResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
{
var result = await mediator.Send(new GetGroupListQuery()
{
Page = page,
PageSize = pageSize
});
return Ok(result.Groups
.Select(g => new GroupResponse()
{
Id = g.Id,
Name = g.Name,
FacultyId = g.FacultyId,
CourseNumber = GetCourseNumber(g.Name)
})
);
}
/// <summary>
/// Retrieves detailed information about a specific group.
/// </summary>
/// <param name="id">The ID of the group to retrieve.</param>
/// <returns>Detailed information about the group.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<GroupDetailsResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetGroupInfoQuery()
{
Id = id
});
return Ok(new GroupDetailsResponse()
{
Id = result.Id,
Name = result.Name,
FacultyId = result.FacultyId,
FacultyName = result.Faculty,
CourseNumber = GetCourseNumber(result.Name)
});
}
/// <summary>
/// Retrieves a list of groups by faculty ID.
/// </summary>
/// <param name="id">The ID of the faculty.</param>
/// <returns>A list of groups belonging to the specified faculty.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<List<GroupResponse>>> GetByFaculty(int id)
{
var result = await mediator.Send(new GetGroupListQuery());
return Ok(result.Groups
.Where(g => g.FacultyId == id)
.Select(g => new GroupResponse()
{
Id = g.Id,
Name = g.Name,
CourseNumber = GetCourseNumber(g.Name),
FacultyId = g.FacultyId
}));
}
}
}

View File

@ -0,0 +1,84 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallDetails;
using Mirea.Api.DataAccess.Application.Cqrs.LectureHall.Queries.GetLectureHallList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1
{
public class LectureHallController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Retrieves a list of all lecture halls.
/// </summary>
/// <returns>A list of lecture halls.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<List<LectureHallResponse>>> Get()
{
var result = await mediator.Send(new GetLectureHallListQuery());
return Ok(result.LectureHalls
.Select(l => new LectureHallResponse()
{
Id = l.Id,
Name = l.Name,
CampusId = l.CampusId
})
);
}
/// <summary>
/// Retrieves details of a specific lecture hall by its ID.
/// </summary>
/// <param name="id">The ID of the lecture hall to retrieve.</param>
/// <returns>The details of the specified lecture hall.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<LectureHallDetailsResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetLectureHallInfoQuery()
{
Id = id
});
return Ok(new LectureHallDetailsResponse()
{
Id = result.Id,
Name = result.Name,
CampusId = result.CampusId,
CampusCode = result.CampusCode,
CampusName = result.CampusName
});
}
/// <summary>
/// Retrieves a list of lecture halls by campus ID.
/// </summary>
/// <param name="id">The ID of the campus.</param>
/// <returns>A list of lecture halls in the specified campus.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<List<LectureHallResponse>>> GetByCampus(int id)
{
var result = await mediator.Send(new GetLectureHallListQuery());
return Ok(result.LectureHalls.Where(l => l.CampusId == id)
.Select(l => new LectureHallResponse()
{
Id = l.Id,
Name = l.Name,
CampusId = l.CampusId
}));
}
}
}

View File

@ -0,0 +1,66 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetails;
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1;
public class ProfessorController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Retrieves a list of professors.
/// </summary>
/// <param name="page">The page number for pagination (optional).</param>
/// <param name="pageSize">The page size for pagination (optional).</param>
/// <returns>A list of professors.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
public async Task<ActionResult<List<ProfessorResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
{
var result = await mediator.Send(new GetProfessorListQuery()
{
Page = page,
PageSize = pageSize
});
return Ok(result.Professors
.Select(p => new ProfessorResponse()
{
Id = p.Id,
Name = p.Name,
AltName = p.AltName
})
);
}
/// <summary>
/// Retrieves detailed information about a specific professor.
/// </summary>
/// <param name="id">The ID of the professor to retrieve.</param>
/// <returns>Detailed information about the professor.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<ProfessorResponse>> GetDetails(int id)
{
var result = await mediator.Send(new GetProfessorInfoQuery()
{
Id = id
});
return Ok(new ProfessorResponse()
{
Id = result.Id,
Name = result.Name,
AltName = result.AltName
});
}
}

View File

@ -0,0 +1,304 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Mirea.Api.DataAccess.Application.Cqrs.Schedule.Queries.GetScheduleList;
using Mirea.Api.Dto.Requests;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Dto.Responses.Schedule;
using Mirea.Api.Endpoint.Common.Attributes;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mirea.Api.Endpoint.Controllers.V1;
public class ScheduleController(IMediator mediator) : BaseControllerV1
{
/// <summary>
/// Retrieves schedules based on various filters.
/// </summary>
/// <param name="request">The request object containing filter criteria.</param>
/// <returns>A list of schedules matching the filter criteria.</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
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()))
{
return BadRequest(new ErrorResponse()
{
Error = "At least one of the arguments must be selected."
+ (request.IsEven.HasValue
? $" \"{nameof(request.IsEven)}\" is not a strong argument"
: string.Empty),
Code = StatusCodes.Status400BadRequest
});
}
var result = (await mediator.Send(new GetScheduleListQuery()
{
IsEven = request.IsEven,
DisciplineIds = request.Disciplines,
GroupIds = request.Groups,
LectureHallIds = request.LectureHalls,
ProfessorIds = request.Professors
})).Schedules;
if (result.Count == 0) NoContent();
return Ok(result.Select(s => new ScheduleResponse()
{
DayOfWeek = s.DayOfWeek,
PairNumber = s.PairNumber,
IsEven = s.IsEven,
Discipline = s.Discipline,
DisciplineId = s.DisciplineId,
TypeOfOccupation = s.TypeOfOccupation,
Group = s.Group,
GroupId = s.GroupId,
LectureHalls = s.LectureHalls,
LectureHallsId = s.LectureHallsId,
Professors = s.Professors,
ProfessorsId = s.ProfessorsId,
Campus = s.Campus,
CampusId = s.CampusId,
LinkToMeet = s.LinkToMeet
}));
}
/// <summary>
/// Retrieves schedules for a specific group based on various filters.
/// </summary>
/// <param name="id">The ID of the group.</param>
/// <param name="isEven">A value indicating whether to retrieve schedules for even weeks.</param>
/// <param name="disciplines">An array of discipline IDs.</param>
/// <param name="professors">An array of professor IDs.</param>
/// <param name="lectureHalls">An array of lecture hall IDs.</param>
/// <returns>A response containing schedules for the specified group.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<GroupScheduleResponse>> GetByGroup(int id,
[FromQuery] bool? isEven = null,
[FromQuery] int[]? disciplines = null,
[FromQuery] int[]? professors = null,
[FromQuery] int[]? lectureHalls = null)
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
IsEven = isEven,
DisciplineIds = disciplines,
GroupIds = [id],
LectureHallIds = lectureHalls,
ProfessorIds = professors
})).Schedules;
if (result.Count == 0) NoContent();
return Ok(new GroupScheduleResponse()
{
Group = result[0].Group,
GroupId = result[0].GroupId,
Schedules = result.Select(g => new GroupScheduleInfo()
{
DayOfWeek = g.DayOfWeek,
PairNumber = g.PairNumber,
IsEven = g.IsEven,
Discipline = g.Discipline,
DisciplineId = g.DisciplineId,
TypeOfOccupation = g.TypeOfOccupation,
LectureHalls = g.LectureHalls,
LectureHallsId = g.LectureHallsId,
Professors = g.Professors,
ProfessorsId = g.ProfessorsId,
Campus = g.Campus,
CampusId = g.CampusId,
LinkToMeet = g.LinkToMeet
})
});
}
/// <summary>
/// Retrieves schedules for a specific professor based on various filters.
/// </summary>
/// <param name="id">The ID of the professor.</param>
/// <param name="isEven">A value indicating whether to retrieve schedules for even weeks.</param>
/// <param name="disciplines">An array of discipline IDs.</param>
/// <param name="groups">An array of group IDs.</param>
/// <param name="lectureHalls">An array of lecture hall IDs.</param>
/// <returns>A response containing schedules for the specified professor.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<ProfessorScheduleResponse>> GetByProfessor(int id,
[FromQuery] bool? isEven = null,
[FromQuery] int[]? disciplines = null,
[FromQuery] int[]? groups = null,
[FromQuery] int[]? lectureHalls = null)
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
IsEven = isEven,
DisciplineIds = disciplines,
GroupIds = groups,
LectureHallIds = lectureHalls,
ProfessorIds = [id]
})).Schedules;
if (result.Count == 0) NoContent();
return Ok(new ProfessorScheduleResponse()
{
Professor = result.Select(professor =>
professor.Professors.FirstOrDefault(x => !string.IsNullOrEmpty(x))
).First()!,
ProfessorId = result.Select(professor =>
professor.ProfessorsId.FirstOrDefault(x => x != null)
).First()!.Value,
Schedules = result.Select(p => new ProfessorScheduleInfo()
{
DayOfWeek = p.DayOfWeek,
PairNumber = p.PairNumber,
IsEven = p.IsEven,
Discipline = p.Discipline,
DisciplineId = p.DisciplineId,
TypeOfOccupation = p.TypeOfOccupation,
Group = p.Group,
GroupId = p.GroupId,
LectureHalls = p.LectureHalls,
LectureHallsId = p.LectureHallsId,
Campus = p.Campus,
CampusId = p.CampusId,
LinkToMeet = p.LinkToMeet
})
});
}
/// <summary>
/// Retrieves schedules for a specific lecture hall based on various filters.
/// </summary>
/// <param name="id">The ID of the lecture hall.</param>
/// <param name="isEven">A value indicating whether to retrieve schedules for even weeks.</param>
/// <param name="disciplines">An array of discipline IDs.</param>
/// <param name="professors">An array of professor IDs.</param>
/// <param name="groups">An array of group IDs.</param>
/// <returns>A response containing schedules for the specified lecture hall.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<LectureHallScheduleResponse>> GetByLectureHall(int id,
[FromQuery] bool? isEven = null,
[FromQuery] int[]? disciplines = null,
[FromQuery] int[]? groups = null,
[FromQuery] int[]? professors = null)
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
IsEven = isEven,
DisciplineIds = disciplines,
GroupIds = groups,
LectureHallIds = [id],
ProfessorIds = professors
})).Schedules;
if (result.Count == 0) NoContent();
return Ok(new LectureHallScheduleResponse()
{
LectureHalls = result.Select(lectureHall =>
lectureHall.LectureHalls.FirstOrDefault(x => !string.IsNullOrEmpty(x))
).First()!,
LectureHallsId = result.Select(lectureHall =>
lectureHall.LectureHallsId.FirstOrDefault(x => x != null)
).First()!.Value,
Schedules = result.Select(l => new LectureHallScheduleInfo()
{
DayOfWeek = l.DayOfWeek,
PairNumber = l.PairNumber,
IsEven = l.IsEven,
Discipline = l.Discipline,
DisciplineId = l.DisciplineId,
TypeOfOccupation = l.TypeOfOccupation,
Group = l.Group,
GroupId = l.GroupId,
Professors = l.Professors,
ProfessorsId = l.ProfessorsId,
Campus = l.Campus,
CampusId = l.CampusId,
LinkToMeet = l.LinkToMeet
})
});
}
/// <summary>
/// Retrieves schedules for a specific discipline based on various filters.
/// </summary>
/// <param name="id">The ID of the discipline.</param>
/// <param name="isEven">A value indicating whether to retrieve schedules for even weeks.</param>
/// <param name="groups">An array of group IDs.</param>
/// <param name="professors">An array of professor IDs.</param>
/// <param name="lectureHalls">An array of lecture hall IDs.</param>
/// <returns>A response containing schedules for the specified discipline.</returns>
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<DisciplineScheduleResponse>> GetByDiscipline(int id,
[FromQuery] bool? isEven = null,
[FromQuery] int[]? groups = null,
[FromQuery] int[]? professors = null,
[FromQuery] int[]? lectureHalls = null)
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
IsEven = isEven,
DisciplineIds = [id],
GroupIds = groups,
LectureHallIds = [id],
ProfessorIds = professors
})).Schedules;
if (result.Count == 0) NoContent();
return Ok(new DisciplineScheduleResponse()
{
Discipline = result[0].Discipline,
DisciplineId = result[0].DisciplineId,
Schedules = result.Select(d => new DisciplineScheduleInfo()
{
DayOfWeek = d.DayOfWeek,
PairNumber = d.PairNumber,
IsEven = d.IsEven,
TypeOfOccupation = d.TypeOfOccupation,
Group = d.Group,
GroupId = d.GroupId,
LectureHalls = d.LectureHalls,
LectureHallsId = d.LectureHallsId,
Professors = d.Professors,
ProfessorsId = d.ProfessorsId,
Campus = d.Campus,
CampusId = d.CampusId,
LinkToMeet = d.LinkToMeet
})
});
}
}

View File

@ -28,6 +28,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ApiDto\ApiDto.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" /> <ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Persistence\Persistence.csproj" /> <ProjectReference Include="..\Persistence\Persistence.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Mirea.Api.DataAccess.Application; using Mirea.Api.DataAccess.Application;
using Mirea.Api.DataAccess.Persistence; using Mirea.Api.DataAccess.Persistence;
using Mirea.Api.Endpoint.Configuration;
using Mirea.Api.Endpoint.Properties; using Mirea.Api.Endpoint.Properties;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using System; using System;