From 84872a5d6d0c100445ba69ccf2d22c1d3d85828c Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 17 Feb 2024 01:49:37 +0300 Subject: [PATCH] feat: add course information --- ApiDto/Responses/GroupDetailsResponse.cs | 5 +++++ ApiDto/Responses/GroupResponse.cs | 5 +++++ Endpoint/Controllers/V1/GroupController.cs | 20 ++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ApiDto/Responses/GroupDetailsResponse.cs b/ApiDto/Responses/GroupDetailsResponse.cs index 35c665b..d4f5cae 100644 --- a/ApiDto/Responses/GroupDetailsResponse.cs +++ b/ApiDto/Responses/GroupDetailsResponse.cs @@ -15,6 +15,11 @@ public class GroupDetailsResponse /// public required string Name { get; set; } + /// + /// Gets or sets the course number of the group. + /// + public int CourseNumber { get; set; } + /// /// Gets or sets the unique identifier of the faculty to which the group belongs (optional). /// diff --git a/ApiDto/Responses/GroupResponse.cs b/ApiDto/Responses/GroupResponse.cs index 4526e72..63b91b3 100644 --- a/ApiDto/Responses/GroupResponse.cs +++ b/ApiDto/Responses/GroupResponse.cs @@ -15,6 +15,11 @@ public class GroupResponse /// public required string Name { get; set; } + /// + /// Gets or sets the course number of the group. + /// + public int CourseNumber { get; set; } + /// /// Gets or sets the unique identifier of the faculty to which the group belongs (optional). /// diff --git a/Endpoint/Controllers/V1/GroupController.cs b/Endpoint/Controllers/V1/GroupController.cs index 970bc66..3dc7966 100644 --- a/Endpoint/Controllers/V1/GroupController.cs +++ b/Endpoint/Controllers/V1/GroupController.cs @@ -5,6 +5,7 @@ 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; @@ -13,6 +14,19 @@ 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); + } + /// /// Retrieves a list of groups. /// @@ -35,7 +49,8 @@ namespace Mirea.Api.Endpoint.Controllers.V1 { Id = g.Id, Name = g.Name, - FacultyId = g.FacultyId + FacultyId = g.FacultyId, + CourseNumber = GetCourseNumber(g.Name) }) ); } @@ -61,7 +76,8 @@ namespace Mirea.Api.Endpoint.Controllers.V1 Id = result.Id, Name = result.Name, FacultyId = result.FacultyId, - FacultyName = result.Faculty + FacultyName = result.Faculty, + CourseNumber = GetCourseNumber(result.Name) }); } }