feat: add course information
Some checks failed
.NET Test Pipeline / build-and-test (pull_request) Failing after 1m34s
Some checks failed
.NET Test Pipeline / build-and-test (pull_request) Failing after 1m34s
This commit is contained in:
parent
5cfc07ab7d
commit
84872a5d6d
@ -15,6 +15,11 @@ public class GroupDetailsResponse
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the course number of the group.
|
||||
/// </summary>
|
||||
public int CourseNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the faculty to which the group belongs (optional).
|
||||
/// </summary>
|
||||
|
@ -15,6 +15,11 @@ public class GroupResponse
|
||||
/// </summary>
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the course number of the group.
|
||||
/// </summary>
|
||||
public int CourseNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the faculty to which the group belongs (optional).
|
||||
/// </summary>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a list of groups.
|
||||
/// </summary>
|
||||
@ -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)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user