204 lines
8.3 KiB
C#
204 lines
8.3 KiB
C#
using Asp.Versioning;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
using Mirea.Api.DataAccess.Application.Cqrs.Schedule.Queries.GetScheduleList;
|
|
using Mirea.Api.Dto.Common;
|
|
using Mirea.Api.Dto.Requests;
|
|
using Mirea.Api.Dto.Responses;
|
|
using Mirea.Api.Endpoint.Common.Attributes;
|
|
using Mirea.Api.Endpoint.Common.Services;
|
|
using Mirea.Api.Endpoint.Common.Settings;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mirea.Api.Endpoint.Controllers.V1;
|
|
|
|
[ApiVersion("1.0")]
|
|
[CacheMaxAge(true)]
|
|
public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConfig> config) : BaseController
|
|
{
|
|
[CacheMaxAge(1, 0)]
|
|
[HttpGet("StartTerm")]
|
|
[Produces("text/plain")]
|
|
public ActionResult<DateOnly> GetStartTerm() => config.Value.ScheduleSettings!.StartTerm;
|
|
|
|
[CacheMaxAge(1, 0)]
|
|
[HttpGet("PairPeriod")]
|
|
public ActionResult<Dictionary<int, PairPeriodTime>> GetPairPeriod() => config.Value.ScheduleSettings!.PairPeriod.ConvertToDto();
|
|
|
|
/// <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.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()
|
|
{
|
|
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,
|
|
IsExcludedWeeks = s.IsExcludedWeeks,
|
|
Weeks = s.Weeks,
|
|
TypeOfOccupations = s.TypeOfOccupations,
|
|
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("GetByGroup/{id:int}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[BadRequestResponse]
|
|
[NotFoundResponse]
|
|
public async Task<ActionResult<List<ScheduleResponse>>> GetByGroup(int id,
|
|
[FromQuery] bool? isEven = null,
|
|
[FromQuery] int[]? disciplines = null,
|
|
[FromQuery] int[]? professors = null,
|
|
[FromQuery] int[]? lectureHalls = null) =>
|
|
await Get(new ScheduleRequest
|
|
{
|
|
Disciplines = disciplines,
|
|
IsEven = isEven,
|
|
Groups = [id],
|
|
Professors = professors,
|
|
LectureHalls = lectureHalls
|
|
});
|
|
|
|
/// <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("GetByProfessor/{id:int}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[BadRequestResponse]
|
|
[NotFoundResponse]
|
|
public async Task<ActionResult<List<ScheduleResponse>>> GetByProfessor(int id,
|
|
[FromQuery] bool? isEven = null,
|
|
[FromQuery] int[]? disciplines = null,
|
|
[FromQuery] int[]? groups = null,
|
|
[FromQuery] int[]? lectureHalls = null) =>
|
|
await Get(new ScheduleRequest
|
|
{
|
|
Disciplines = disciplines,
|
|
IsEven = isEven,
|
|
Groups = groups,
|
|
Professors = [id],
|
|
LectureHalls = lectureHalls
|
|
});
|
|
|
|
/// <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("GetByLectureHall/{id:int}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[BadRequestResponse]
|
|
[NotFoundResponse]
|
|
public async Task<ActionResult<List<ScheduleResponse>>> GetByLectureHall(int id,
|
|
[FromQuery] bool? isEven = null,
|
|
[FromQuery] int[]? disciplines = null,
|
|
[FromQuery] int[]? groups = null,
|
|
[FromQuery] int[]? professors = null) =>
|
|
await Get(new ScheduleRequest
|
|
{
|
|
Disciplines = disciplines,
|
|
IsEven = isEven,
|
|
Groups = groups,
|
|
Professors = professors,
|
|
LectureHalls = [id]
|
|
});
|
|
|
|
/// <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("GetByDiscipline/{id:int}")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[BadRequestResponse]
|
|
[NotFoundResponse]
|
|
public async Task<ActionResult<List<ScheduleResponse>>> GetByDiscipline(int id,
|
|
[FromQuery] bool? isEven = null,
|
|
[FromQuery] int[]? groups = null,
|
|
[FromQuery] int[]? professors = null,
|
|
[FromQuery] int[]? lectureHalls = null) =>
|
|
await Get(new ScheduleRequest
|
|
{
|
|
Disciplines = [id],
|
|
IsEven = isEven,
|
|
Groups = groups,
|
|
Professors = professors,
|
|
LectureHalls = lectureHalls
|
|
});
|
|
} |