refactor: provide single response for schedule

This commit is contained in:
Polianin Nikita 2024-06-10 21:59:34 +03:00
parent 993e66a084
commit 4222e4702f
6 changed files with 33 additions and 651 deletions

View File

@ -1,106 +0,0 @@
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 IEnumerable<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

@ -1,129 +0,0 @@
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 exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required IEnumerable<string> TypeOfOccupations { 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

@ -1,128 +0,0 @@
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 exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required IEnumerable<string> TypeOfOccupations { 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

@ -1,131 +0,0 @@
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 exclude or include weeks for a specific discipline.
/// </summary>
/// <remarks>
/// If is <see langword="true"/>, then the values in <see cref="Weeks"/> show the weeks when there will be no discipline.
/// <br/>
/// If is <see langword="false"/>, then the values in <see cref="Weeks"/> indicate the weeks during which a particular discipline will be studied.
/// <br/>
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>
/// Whether there will be <see cref="Discipline"/> during the week or not depends on the <see cref="IsExcludedWeeks"/> property.
/// </summary>
/// <remarks>
/// To get the current week's number, use other queries.
/// </remarks>
public IEnumerable<int>? Weeks { get; set; }
/// <summary>
/// Gets or sets the type of occupation for the schedule entry.
/// </summary>
[Required]
public required IEnumerable<string> TypeOfOccupations { 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

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Mirea.Api.Dto.Responses.Schedule;
namespace Mirea.Api.Dto.Responses;
/// <summary>
/// Represents a response object containing schedule information.
@ -50,8 +50,8 @@ public class ScheduleResponse
/// If is <see langword="null"/>, then there are no specific <see cref="Weeks"/>
/// </remarks>
///
public bool? IsExcludedWeeks { get; set; }
/// <summary>
/// The week numbers required for the correct display of the schedule.
/// <br/>

View File

@ -6,7 +6,6 @@ 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.Dto.Responses.Schedule;
using Mirea.Api.Endpoint.Common.Attributes;
using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration.General;
@ -53,7 +52,7 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
});
}
var result = (await mediator.Send(new GetScheduleListQuery()
var result = (await mediator.Send(new GetScheduleListQuery
{
IsEven = request.IsEven,
DisciplineIds = request.Disciplines,
@ -64,7 +63,7 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
if (result.Count == 0) NoContent();
return Ok(result.Select(s => new ScheduleResponse()
return Ok(result.Select(s => new ScheduleResponse
{
DayOfWeek = s.DayOfWeek,
PairNumber = s.PairNumber,
@ -84,7 +83,6 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
CampusId = s.CampusId,
LinkToMeet = s.LinkToMeet
}));
}
/// <summary>
@ -101,48 +99,19 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<GroupScheduleResponse>> GetByGroup(int id,
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)
[FromQuery] int[]? lectureHalls = null) =>
await Get(new ScheduleRequest
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
Disciplines = disciplines,
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,
IsExcludedWeeks = g.IsExcludedWeeks,
Weeks = g.Weeks,
TypeOfOccupations = g.TypeOfOccupations,
LectureHalls = g.LectureHalls,
LectureHallsId = g.LectureHallsId,
Professors = g.Professors,
ProfessorsId = g.ProfessorsId,
Campus = g.Campus,
CampusId = g.CampusId,
LinkToMeet = g.LinkToMeet
})
Groups = [id],
Professors = professors,
LectureHalls = lectureHalls
});
}
/// <summary>
/// Retrieves schedules for a specific professor based on various filters.
@ -158,52 +127,19 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<ProfessorScheduleResponse>> GetByProfessor(int id,
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)
[FromQuery] int[]? lectureHalls = null) =>
await Get(new ScheduleRequest
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
Disciplines = disciplines,
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,
IsExcludedWeeks = p.IsExcludedWeeks,
Weeks = p.Weeks,
TypeOfOccupations = p.TypeOfOccupations,
Group = p.Group,
GroupId = p.GroupId,
LectureHalls = p.LectureHalls,
LectureHallsId = p.LectureHallsId,
Campus = p.Campus,
CampusId = p.CampusId,
LinkToMeet = p.LinkToMeet
})
Groups = groups,
Professors = [id],
LectureHalls = lectureHalls
});
}
/// <summary>
/// Retrieves schedules for a specific lecture hall based on various filters.
@ -219,52 +155,19 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<LectureHallScheduleResponse>> GetByLectureHall(int id,
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)
[FromQuery] int[]? professors = null) =>
await Get(new ScheduleRequest
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
Disciplines = disciplines,
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,
IsExcludedWeeks = l.IsExcludedWeeks,
Weeks = l.Weeks,
TypeOfOccupations = l.TypeOfOccupations,
Group = l.Group,
GroupId = l.GroupId,
Professors = l.Professors,
ProfessorsId = l.ProfessorsId,
Campus = l.Campus,
CampusId = l.CampusId,
LinkToMeet = l.LinkToMeet
})
Groups = groups,
Professors = professors,
LectureHalls = [id]
});
}
/// <summary>
/// Retrieves schedules for a specific discipline based on various filters.
@ -280,44 +183,17 @@ public class ScheduleController(IMediator mediator, IOptionsSnapshot<GeneralConf
[ProducesResponseType(StatusCodes.Status204NoContent)]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<DisciplineScheduleResponse>> GetByDiscipline(int id,
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)
[FromQuery] int[]? lectureHalls = null) =>
await Get(new ScheduleRequest
{
var result = (await mediator.Send(new GetScheduleListQuery()
{
Disciplines = [id],
IsEven = isEven,
DisciplineIds = [id],
GroupIds = groups,
LectureHallIds = lectureHalls,
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.TypeOfOccupations,
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
})
Groups = groups,
Professors = professors,
LectureHalls = lectureHalls
});
}
}
}