2024-02-19 11:20:49 +03:00
|
|
|
|
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;
|
|
|
|
|
|
2024-05-28 07:09:40 +03:00
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
public class ScheduleController(IMediator mediator) : BaseController
|
2024-02-19 11:20:49 +03:00
|
|
|
|
{
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2024-05-19 12:30:17 +03:00
|
|
|
|
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))
|
2024-02-19 11:20:49 +03:00
|
|
|
|
{
|
|
|
|
|
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,
|
2024-05-19 13:53:25 +03:00
|
|
|
|
IsExcludedWeeks = s.IsExcludedWeeks,
|
|
|
|
|
Weeks = s.Weeks,
|
2024-05-19 12:30:17 +03:00
|
|
|
|
TypeOfOccupations = s.TypeOfOccupations,
|
2024-02-19 11:20:49 +03:00
|
|
|
|
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>
|
2024-05-28 07:09:40 +03:00
|
|
|
|
[HttpGet("GetByGroup/{id:int}")]
|
2024-02-19 11:20:49 +03:00
|
|
|
|
[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,
|
2024-05-19 13:53:25 +03:00
|
|
|
|
IsExcludedWeeks = g.IsExcludedWeeks,
|
|
|
|
|
Weeks = g.Weeks,
|
2024-05-19 12:30:17 +03:00
|
|
|
|
TypeOfOccupations = g.TypeOfOccupations,
|
2024-02-19 11:20:49 +03:00
|
|
|
|
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>
|
2024-05-28 07:09:40 +03:00
|
|
|
|
[HttpGet("GetByProfessor/{id:int}")]
|
2024-02-19 11:20:49 +03:00
|
|
|
|
[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,
|
2024-05-19 13:53:25 +03:00
|
|
|
|
IsExcludedWeeks = p.IsExcludedWeeks,
|
|
|
|
|
Weeks = p.Weeks,
|
2024-05-19 12:30:17 +03:00
|
|
|
|
TypeOfOccupations = p.TypeOfOccupations,
|
2024-02-19 11:20:49 +03:00
|
|
|
|
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>
|
2024-05-28 07:09:40 +03:00
|
|
|
|
[HttpGet("GetByLectureHall/{id:int}")]
|
2024-02-19 11:20:49 +03:00
|
|
|
|
[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,
|
2024-05-19 13:53:25 +03:00
|
|
|
|
IsExcludedWeeks = l.IsExcludedWeeks,
|
|
|
|
|
Weeks = l.Weeks,
|
2024-05-19 12:30:17 +03:00
|
|
|
|
TypeOfOccupations = l.TypeOfOccupations,
|
2024-02-19 11:20:49 +03:00
|
|
|
|
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>
|
2024-05-28 07:09:40 +03:00
|
|
|
|
[HttpGet("GetByDiscipline/{id:int}")]
|
2024-02-19 11:20:49 +03:00
|
|
|
|
[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,
|
2024-05-19 12:30:17 +03:00
|
|
|
|
LectureHallIds = lectureHalls,
|
2024-02-19 11:20:49 +03:00
|
|
|
|
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,
|
2024-05-19 12:30:17 +03:00
|
|
|
|
TypeOfOccupation = d.TypeOfOccupations,
|
2024-02-19 11:20:49 +03:00
|
|
|
|
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
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|