diff --git a/Endpoint/Controllers/BaseController.cs b/Endpoint/Controllers/BaseController.cs index 82c4c7a..53f02a1 100644 --- a/Endpoint/Controllers/BaseController.cs +++ b/Endpoint/Controllers/BaseController.cs @@ -2,6 +2,7 @@ namespace Mirea.Api.Endpoint.Controllers; +[Produces("application/json")] +[Route("api/v{version:apiVersion}/[controller]")] [ApiController] -[Route("api/[controller]/[action]")] public class BaseController : ControllerBase; \ No newline at end of file diff --git a/Endpoint/Controllers/V1/BaseControllerV1.cs b/Endpoint/Controllers/V1/BaseControllerV1.cs deleted file mode 100644 index 6ebe1f3..0000000 --- a/Endpoint/Controllers/V1/BaseControllerV1.cs +++ /dev/null @@ -1,8 +0,0 @@ -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; \ No newline at end of file diff --git a/Endpoint/Controllers/V1/CampusController.cs b/Endpoint/Controllers/V1/CampusController.cs index ae83834..4f4f101 100644 --- a/Endpoint/Controllers/V1/CampusController.cs +++ b/Endpoint/Controllers/V1/CampusController.cs @@ -9,53 +9,53 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Mirea.Api.Endpoint.Controllers.V1 +namespace Mirea.Api.Endpoint.Controllers.V1; + +[ApiVersion("1.0")] +public class CampusController(IMediator mediator) : BaseController { - public class CampusController(IMediator mediator) : BaseControllerV1 + /// + /// Gets basic information about campuses. + /// + /// Basic information about campuses. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task>> Get() { - /// - /// Gets basic information about campuses. - /// - /// Basic information about campuses. - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - public async Task>> Get() - { - var result = await mediator.Send(new GetCampusBasicInfoListQuery()); + var result = await mediator.Send(new GetCampusBasicInfoListQuery()); - return Ok(result.Campuses - .Select(c => new CampusBasicInfoResponse() - { - Id = c.Id, - CodeName = c.CodeName, - FullName = c.FullName - }) - ); - } - - /// - /// Gets details of a specific campus by ID. - /// - /// Campus ID. - /// Details of the specified campus. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task> GetDetails(int id) - { - var result = await mediator.Send(new GetCampusDetailsQuery() + return Ok(result.Campuses + .Select(c => new CampusBasicInfoResponse() { - Id = id - }); - - return Ok(new CampusDetailsResponse() - { - Id = result.Id, - CodeName = result.CodeName, - FullName = result.FullName, - Address = result.Address - }); - } + Id = c.Id, + CodeName = c.CodeName, + FullName = c.FullName + }) + ); } -} + + /// + /// Gets details of a specific campus by ID. + /// + /// Campus ID. + /// Details of the specified campus. + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> 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 + }); + } +} \ No newline at end of file diff --git a/Endpoint/Controllers/V1/DisciplineController.cs b/Endpoint/Controllers/V1/DisciplineController.cs index 056b208..1de1136 100644 --- a/Endpoint/Controllers/V1/DisciplineController.cs +++ b/Endpoint/Controllers/V1/DisciplineController.cs @@ -9,57 +9,57 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Mirea.Api.Endpoint.Controllers.V1 +namespace Mirea.Api.Endpoint.Controllers.V1; + +[ApiVersion("1.0")] +public class DisciplineController(IMediator mediator) : BaseController { - public class DisciplineController(IMediator mediator) : BaseControllerV1 + /// + /// Gets a paginated list of disciplines. + /// + /// Page number. Start from 0. + /// Number of items per page. + /// Paginated list of disciplines. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + public async Task>> Get([FromQuery] int? page, [FromQuery] int? pageSize) { - /// - /// Gets a paginated list of disciplines. - /// - /// Page number. Start from 0. - /// Number of items per page. - /// Paginated list of disciplines. - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - public async Task>> Get([FromQuery] int? page, [FromQuery] int? pageSize) + var result = await mediator.Send(new GetDisciplineListQuery() { - var result = await mediator.Send(new GetDisciplineListQuery() - { - Page = page, - PageSize = pageSize - }); + Page = page, + PageSize = pageSize + }); - return Ok(result.Disciplines - .Select(d => new DisciplineResponse() - { - Id = d.Id, - Name = d.Name - }) - ); - } - - /// - /// Gets details of a specific discipline by ID. - /// - /// Discipline ID. - /// Details of the specified discipline. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task> GetDetails(int id) - { - var result = await mediator.Send(new GetDisciplineInfoQuery() + return Ok(result.Disciplines + .Select(d => new DisciplineResponse() { - Id = id - }); - - return Ok(new DisciplineResponse() - { - Id = result.Id, - Name = result.Name - }); - } + Id = d.Id, + Name = d.Name + }) + ); } -} + + /// + /// Gets details of a specific discipline by ID. + /// + /// Discipline ID. + /// Details of the specified discipline. + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> GetDetails(int id) + { + var result = await mediator.Send(new GetDisciplineInfoQuery() + { + Id = id + }); + + return Ok(new DisciplineResponse() + { + Id = result.Id, + Name = result.Name + }); + } +} \ No newline at end of file diff --git a/Endpoint/Controllers/V1/FacultyController.cs b/Endpoint/Controllers/V1/FacultyController.cs index 3b4cd61..9652551 100644 --- a/Endpoint/Controllers/V1/FacultyController.cs +++ b/Endpoint/Controllers/V1/FacultyController.cs @@ -9,61 +9,61 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Mirea.Api.Endpoint.Controllers.V1 +namespace Mirea.Api.Endpoint.Controllers.V1; + +[ApiVersion("1.0")] +public class FacultyController(IMediator mediator) : BaseController { - public class FacultyController(IMediator mediator) : BaseControllerV1 + /// + /// Gets a paginated list of faculties. + /// + /// Page number. Start from 0. + /// Number of items per page. + /// Paginated list of faculties. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + public async Task>> Get([FromQuery] int? page, [FromQuery] int? pageSize) { - /// - /// Gets a paginated list of faculties. - /// - /// Page number. Start from 0. - /// Number of items per page. - /// Paginated list of faculties. - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - public async Task>> Get([FromQuery] int? page, [FromQuery] int? pageSize) + var result = await mediator.Send(new GetFacultyListQuery() { - var result = await mediator.Send(new GetFacultyListQuery() - { - Page = page, - PageSize = pageSize - }); + Page = page, + PageSize = pageSize + }); - return Ok(result.Faculties - .Select(f => new FacultyResponse() - { - Id = f.Id, - Name = f.Name, - CampusId = f.CampusId - }) - ); - } - - /// - /// Gets details of a specific faculty by ID. - /// - /// Faculty ID. - /// Details of the specified faculty. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task> GetDetails(int id) - { - var result = await mediator.Send(new GetFacultyInfoQuery() + return Ok(result.Faculties + .Select(f => new FacultyResponse() { - Id = id - }); - - return Ok(new FacultyDetailsResponse() - { - Id = result.Id, - Name = result.Name, - CampusId = result.CampusId, - CampusCode = result.CampusCode, - CampusName = result.CampusName - }); - } + Id = f.Id, + Name = f.Name, + CampusId = f.CampusId + }) + ); } -} + + /// + /// Gets details of a specific faculty by ID. + /// + /// Faculty ID. + /// Details of the specified faculty. + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> 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 + }); + } +} \ No newline at end of file diff --git a/Endpoint/Controllers/V1/GroupController.cs b/Endpoint/Controllers/V1/GroupController.cs index cead029..c12f3da 100644 --- a/Endpoint/Controllers/V1/GroupController.cs +++ b/Endpoint/Controllers/V1/GroupController.cs @@ -10,99 +10,99 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Mirea.Api.Endpoint.Controllers.V1 +namespace Mirea.Api.Endpoint.Controllers.V1; + +[ApiVersion("1.0")] +public class GroupController(IMediator mediator) : BaseController { - public class GroupController(IMediator mediator) : BaseControllerV1 + private static int GetCourseNumber(string groupName) { - 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; + 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; + // Convert a two-digit year to a four-digit one + yearOfGroup += current.Year / 100 * 100; - return current.Year - yearOfGroup + (current.Month < 9 ? 0 : 1); - } - - /// - /// Retrieves a list of groups. - /// - /// The page number for pagination (optional). - /// The page size for pagination (optional). - /// A list of groups. - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - public async Task>> 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) - }) - ); - } - - /// - /// Retrieves detailed information about a specific group. - /// - /// The ID of the group to retrieve. - /// Detailed information about the group. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task> 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) - }); - } - - /// - /// Retrieves a list of groups by faculty ID. - /// - /// The ID of the faculty. - /// A list of groups belonging to the specified faculty. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task>> 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 - })); - } + return current.Year - yearOfGroup + (current.Month < 9 ? 0 : 1); } -} + + /// + /// Retrieves a list of groups. + /// + /// The page number for pagination (optional). + /// The page size for pagination (optional). + /// A list of groups. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + public async Task>> 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) + }) + ); + } + + /// + /// Retrieves detailed information about a specific group. + /// + /// The ID of the group to retrieve. + /// Detailed information about the group. + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> 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) + }); + } + + /// + /// Retrieves a list of groups by faculty ID. + /// + /// The ID of the faculty. + /// A list of groups belonging to the specified faculty. + [HttpGet("GetByFaculty/{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task>> 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 + })); + } +} \ No newline at end of file diff --git a/Endpoint/Controllers/V1/LectureHallController.cs b/Endpoint/Controllers/V1/LectureHallController.cs index de2f21f..c6e67b8 100644 --- a/Endpoint/Controllers/V1/LectureHallController.cs +++ b/Endpoint/Controllers/V1/LectureHallController.cs @@ -9,76 +9,76 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Mirea.Api.Endpoint.Controllers.V1 +namespace Mirea.Api.Endpoint.Controllers.V1; + +[ApiVersion("1.0")] +public class LectureHallController(IMediator mediator) : BaseController { - public class LectureHallController(IMediator mediator) : BaseControllerV1 + /// + /// Retrieves a list of all lecture halls. + /// + /// A list of lecture halls. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task>> Get() { - /// - /// Retrieves a list of all lecture halls. - /// - /// A list of lecture halls. - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - public async Task>> Get() - { - var result = await mediator.Send(new GetLectureHallListQuery()); + var result = await mediator.Send(new GetLectureHallListQuery()); - return Ok(result.LectureHalls - .Select(l => new LectureHallResponse() - { - Id = l.Id, - Name = l.Name, - CampusId = l.CampusId - }) - ); - } - - /// - /// Retrieves details of a specific lecture hall by its ID. - /// - /// The ID of the lecture hall to retrieve. - /// The details of the specified lecture hall. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task> GetDetails(int id) - { - var result = await mediator.Send(new GetLectureHallInfoQuery() + return Ok(result.LectureHalls + .Select(l => new LectureHallResponse() { - Id = id - }); - - return Ok(new LectureHallDetailsResponse() - { - Id = result.Id, - Name = result.Name, - CampusId = result.CampusId, - CampusCode = result.CampusCode, - CampusName = result.CampusName - }); - } - - /// - /// Retrieves a list of lecture halls by campus ID. - /// - /// The ID of the campus. - /// A list of lecture halls in the specified campus. - [HttpGet("{id:int}")] - [ProducesResponseType(StatusCodes.Status200OK)] - [BadRequestResponse] - [NotFoundResponse] - public async Task>> 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 - })); - } + Id = l.Id, + Name = l.Name, + CampusId = l.CampusId + }) + ); } -} + + /// + /// Retrieves details of a specific lecture hall by its ID. + /// + /// The ID of the lecture hall to retrieve. + /// The details of the specified lecture hall. + [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task> 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 + }); + } + + /// + /// Retrieves a list of lecture halls by campus ID. + /// + /// The ID of the campus. + /// A list of lecture halls in the specified campus. + [HttpGet("GetByCampus/{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [BadRequestResponse] + [NotFoundResponse] + public async Task>> 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 + })); + } +} \ No newline at end of file diff --git a/Endpoint/Controllers/V1/ProfessorController.cs b/Endpoint/Controllers/V1/ProfessorController.cs index 5a9053a..3093a38 100644 --- a/Endpoint/Controllers/V1/ProfessorController.cs +++ b/Endpoint/Controllers/V1/ProfessorController.cs @@ -11,7 +11,8 @@ using System.Threading.Tasks; namespace Mirea.Api.Endpoint.Controllers.V1; -public class ProfessorController(IMediator mediator) : BaseControllerV1 +[ApiVersion("1.0")] +public class ProfessorController(IMediator mediator) : BaseController { /// /// Retrieves a list of professors. diff --git a/Endpoint/Controllers/V1/ScheduleController.cs b/Endpoint/Controllers/V1/ScheduleController.cs index 1500efa..a0d5b7b 100644 --- a/Endpoint/Controllers/V1/ScheduleController.cs +++ b/Endpoint/Controllers/V1/ScheduleController.cs @@ -12,7 +12,8 @@ using System.Threading.Tasks; namespace Mirea.Api.Endpoint.Controllers.V1; -public class ScheduleController(IMediator mediator) : BaseControllerV1 +[ApiVersion("1.0")] +public class ScheduleController(IMediator mediator) : BaseController { /// /// Retrieves schedules based on various filters. @@ -25,7 +26,6 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 [BadRequestResponse] [NotFoundResponse] public async Task>> Get([FromBody] ScheduleRequest request) - { if ((request.Groups == null || request.Groups.Length == 0) && (request.Disciplines == null || request.Disciplines.Length == 0) && @@ -85,7 +85,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 /// An array of professor IDs. /// An array of lecture hall IDs. /// A response containing schedules for the specified group. - [HttpGet("{id:int}")] + [HttpGet("GetByGroup/{id:int}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [BadRequestResponse] @@ -142,7 +142,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 /// An array of group IDs. /// An array of lecture hall IDs. /// A response containing schedules for the specified professor. - [HttpGet("{id:int}")] + [HttpGet("GetByProfessor/{id:int}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [BadRequestResponse] @@ -203,7 +203,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 /// An array of professor IDs. /// An array of group IDs. /// A response containing schedules for the specified lecture hall. - [HttpGet("{id:int}")] + [HttpGet("GetByLectureHall/{id:int}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [BadRequestResponse] @@ -264,7 +264,7 @@ public class ScheduleController(IMediator mediator) : BaseControllerV1 /// An array of professor IDs. /// An array of lecture hall IDs. /// A response containing schedules for the specified discipline. - [HttpGet("{id:int}")] + [HttpGet("GetByDiscipline/{id:int}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] [BadRequestResponse]