diff --git a/SfeduSchedule.Plugin.Abstractions/ModeusScheduleRequestDTO.cs b/SfeduSchedule.Plugin.Abstractions/ModeusScheduleRequestDTO.cs new file mode 100644 index 0000000..4f2b582 --- /dev/null +++ b/SfeduSchedule.Plugin.Abstractions/ModeusScheduleRequestDTO.cs @@ -0,0 +1,115 @@ +using System.ComponentModel; + +namespace SfeduSchedule.Plugin.Abstractions; + +/// +/// DTO для запроса расписания в Modeus. +/// +public class ModeusScheduleRequest( + int size, + DateTime timeMin, + DateTime timeMax, + List? roomId, + List? attendeePersonId, + List? courseUnitRealizationId, + List? cycleRealizationId, + List? specialtyCode, + List? learningStartYear, + List? profileName, + List? curriculumId, + List? typeId) +{ + /// + /// Количество элементов в ответе. + /// + [DefaultValue(10)] + public int Size { get; set; } = size; + + /// + /// Начальная дата и время. + /// + public DateTime TimeMin { get; set; } = timeMin; + + /// + /// Конечная дата и время. + /// + public DateTime TimeMax { get; set; } = timeMax; + + /// + /// Список идентификаторов аудиторий. (Guid) + /// + public List? RoomId { get; set; } = roomId; + + /// + /// Список идентификаторов участников. + /// + public List? AttendeePersonId { get; set; } = attendeePersonId; + + public List? CourseUnitRealizationId { get; set; } = courseUnitRealizationId; + public List? CycleRealizationId { get; set; } = cycleRealizationId; + + /// + /// Список кодов специальностей. + /// + [DefaultValue(new string[] { "09.03.04" })] + public List? SpecialtyCode { get; set; } = specialtyCode; + + /// + /// Список годов начала обучения. + /// + [DefaultValue(new int[] { 2022, 2023, 2024, 2025 })] + public List? LearningStartYear { get; set; } = learningStartYear; + + /// + /// Список названий профилей подготовки. + /// + [DefaultValue(new string[] { "Методы и средства разработки программного обеспечения" })] + public List? ProfileName { get; set; } = profileName; + + /// + /// Список идентификаторов учебных планов. + /// + public List? CurriculumId { get; set; } = curriculumId; + + /// + /// Список типов мероприятий. + /// + [DefaultValue(new string[] { "MID_CHECK", "CONS", "LAB", "LECT", "SEMI", "EVENT_OTHER", "SELF", "CUR_CHECK" })] + public List? TypeId { get; set; } = typeId; +} + +/// +/// DTO для поиска аудиторий. +/// +public class RoomSearchRequest +{ + /// + /// Название аудитории. + /// + [DefaultValue("")] + public string Name { get; set; } = ""; + + /// + /// Сортировка. + /// + [DefaultValue("+building.name,+name")] + public string Sort { get; set; } = "+building.name,+name"; + + /// + /// Количество элементов в ответе. + /// + [DefaultValue(10)] + public int Size { get; set; } = 10; + + /// + /// Номер страницы. (пагинация) + /// + [DefaultValue(0)] + public int Page { get; set; } = 0; + + /// + /// Исключать архивные аудитории. false = да, true = нет + /// + [DefaultValue(false)] + public bool Deleted { get; set; } = false; +} \ No newline at end of file diff --git a/SfeduSchedule/Controllers/ScheduleController.cs b/SfeduSchedule/Controllers/ScheduleController.cs index 94ef03f..a02d05d 100644 --- a/SfeduSchedule/Controllers/ScheduleController.cs +++ b/SfeduSchedule/Controllers/ScheduleController.cs @@ -3,6 +3,7 @@ using System.Text.Json; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.RateLimiting; +using SfeduSchedule.Plugin.Abstractions; using SfeduSchedule.Services; namespace SfeduSchedule.Controllers @@ -30,8 +31,8 @@ namespace SfeduSchedule.Controllers } catch (HttpRequestException e) { - logger.LogError("Ошибка при получении расписания\n\n" + e.Message + "\n\n" + e.StackTrace + "\n\n JSON: " + JsonSerializer.Serialize(request)); - return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), e.Message); + logger.LogError("Ошибка при получении расписания\n\n" + e.Message + "\n\n" + e.StackTrace + "\n\n JSON: " + JsonSerializer.Serialize(request, GlobalVariables.jsonSerializerOptions)); + return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), "Proxied Modeus: " + e.Message); } return Ok(schedule); } @@ -54,10 +55,10 @@ namespace SfeduSchedule.Controllers } catch (HttpRequestException e) { - logger.LogError("Ошибка при поиске аудиторий\n\n" + e.Message + "\n\n" + e.StackTrace + "\n\n JSON: " + JsonSerializer.Serialize(request)); - return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), e.Message); + logger.LogError("Ошибка при поиске аудиторий\n\n" + e.Message + "\n\n" + e.StackTrace + "\n\n JSON: " + JsonSerializer.Serialize(request, GlobalVariables.jsonSerializerOptions)); + return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), "Proxied Modeus: " + e.Message); } - return Ok(rooms); + return Ok(rooms); } /// diff --git a/SfeduSchedule/DTO/ModeusScheduleRequestDTO.cs b/SfeduSchedule/DTO/ModeusScheduleRequestDTO.cs deleted file mode 100644 index 292cc71..0000000 --- a/SfeduSchedule/DTO/ModeusScheduleRequestDTO.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System.ComponentModel; - -namespace SfeduSchedule -{ - /// - /// DTO для запроса расписания в Modeus. - /// - public class ModeusScheduleRequest(int size, DateTime timeMin, DateTime timeMax, List? roomId, List? attendeePersonId, - List? courseUnitRealizationId, List? cycleRealizationId, List? specialtyCode, - List? learningStartYear, List? profileName, List? curriculumId, List? typeId) - { - /// - /// Количество элементов в ответе. - /// - [DefaultValue(10)] - public int Size { get; set; } = size; - - /// - /// Начальная дата и время. - /// - public DateTime TimeMin { get; set; } = timeMin; - - /// - /// Конечная дата и время. - /// - public DateTime TimeMax { get; set; } = timeMax; - - /// - /// Список идентификаторов аудиторий. (Guid) - /// - public List? RoomId { get; set; } = roomId; - - /// - /// Список идентификаторов участников. - /// - public List? AttendeePersonId { get; set; } = attendeePersonId; - - public List? CourseUnitRealizationId { get; set; } = courseUnitRealizationId; - public List? CycleRealizationId { get; set; } = cycleRealizationId; - - /// - /// Список кодов специальностей. - /// - [DefaultValue(new string[] { "09.03.04" })] - public List? SpecialtyCode { get; set; } = specialtyCode; - - /// - /// Список годов начала обучения. - /// - [DefaultValue(new int[] { 2022, 2023, 2024, 2025 })] - public List? LearningStartYear { get; set; } = learningStartYear; - - /// - /// Список названий профилей подготовки. - /// - [DefaultValue(new string[] { "Методы и средства разработки программного обеспечения" })] - public List? ProfileName { get; set; } = profileName; - - /// - /// Список идентификаторов учебных планов. - /// - public List? CurriculumId { get; set; } = curriculumId; - - /// - /// Список типов мероприятий. - /// - [DefaultValue(new string[] { "MID_CHECK","CONS","LAB","LECT","SEMI","EVENT_OTHER","SELF","CUR_CHECK" })] - public List? TypeId { get; set; } = typeId; - } - - /// - /// DTO для поиска аудиторий. - /// - public class RoomSearchRequest - { - /// - /// Название аудитории. - /// - [DefaultValue("")] - public string Name { get; set; } = ""; - - /// - /// Сортировка. - /// - [DefaultValue("+building.name,+name")] - public string Sort { get; set; } = "+building.name,+name"; - - /// - /// Количество элементов в ответе. - /// - [DefaultValue(10)] - public int Size { get; set; } = 10; - - /// - /// Номер страницы. (пагинация) - /// - [DefaultValue(0)] - public int Page { get; set; } = 0; - - /// - /// Исключать архивные аудитории. false = да, true = нет - /// - [DefaultValue(false)] - public bool Deleted { get; set; } = false; - } -} diff --git a/SfeduSchedule/GlobalVariables.cs b/SfeduSchedule/GlobalVariables.cs index 8c64349..101ef29 100644 --- a/SfeduSchedule/GlobalVariables.cs +++ b/SfeduSchedule/GlobalVariables.cs @@ -1,7 +1,10 @@ +using System.Text.Json; + namespace SfeduSchedule { public static class GlobalVariables { public static string JwtFilePath { get; set; } = "data/jwt.txt"; + public static readonly JsonSerializerOptions jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; } } \ No newline at end of file diff --git a/SfeduSchedule/Services/ModeusService.cs b/SfeduSchedule/Services/ModeusService.cs index 1152fb2..91e55b3 100644 --- a/SfeduSchedule/Services/ModeusService.cs +++ b/SfeduSchedule/Services/ModeusService.cs @@ -1,18 +1,17 @@ using System.Text.Json; using Microsoft.Net.Http.Headers; +using SfeduSchedule.Plugin.Abstractions; namespace SfeduSchedule.Services { public class ModeusService { private readonly HttpClient _httpClient; - private readonly JsonSerializerOptions _options = new(); private readonly ILogger _logger; private readonly IConfiguration _configuration; public ModeusService(HttpClient httpClient, ILogger logger, IConfiguration configuration) { - _options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; _httpClient = httpClient; _logger = logger; _configuration = configuration; @@ -24,7 +23,7 @@ namespace SfeduSchedule.Services public async Task GetScheduleAsync(ModeusScheduleRequest msr, string TZ = "Europe/Moscow") { var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/calendar/events/search?tz={TZ}"); - request.Content = new StringContent(JsonSerializer.Serialize(msr, _options), System.Text.Encoding.UTF8, "application/json"); + request.Content = new StringContent(JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions), System.Text.Encoding.UTF8, "application/json"); var response = await _httpClient.SendAsync(request); _logger.LogInformation("GetScheduleAsync: Ответ получен: {StatusCode}", response.StatusCode); response.EnsureSuccessStatusCode(); @@ -34,7 +33,7 @@ namespace SfeduSchedule.Services public async Task SearchRoomsAsync(RoomSearchRequest requestDto) { var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/campus/rooms/search"); - request.Content = new StringContent(JsonSerializer.Serialize(requestDto, _options), System.Text.Encoding.UTF8, "application/json"); + request.Content = new StringContent(JsonSerializer.Serialize(requestDto, GlobalVariables.jsonSerializerOptions), System.Text.Encoding.UTF8, "application/json"); var response = await _httpClient.SendAsync(request); _logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode); response.EnsureSuccessStatusCode();