Перенёс опции сериализации json в global variables
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 5m54s
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 5m54s
This commit is contained in:
115
SfeduSchedule.Plugin.Abstractions/ModeusScheduleRequestDTO.cs
Normal file
115
SfeduSchedule.Plugin.Abstractions/ModeusScheduleRequestDTO.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SfeduSchedule.Plugin.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// DTO для запроса расписания в Modeus.
|
||||
/// </summary>
|
||||
public class ModeusScheduleRequest(
|
||||
int size,
|
||||
DateTime timeMin,
|
||||
DateTime timeMax,
|
||||
List<Guid>? roomId,
|
||||
List<Guid>? attendeePersonId,
|
||||
List<Guid>? courseUnitRealizationId,
|
||||
List<Guid>? cycleRealizationId,
|
||||
List<string>? specialtyCode,
|
||||
List<int>? learningStartYear,
|
||||
List<string>? profileName,
|
||||
List<Guid>? curriculumId,
|
||||
List<string>? typeId)
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество элементов в ответе.
|
||||
/// </summary>
|
||||
[DefaultValue(10)]
|
||||
public int Size { get; set; } = size;
|
||||
|
||||
/// <summary>
|
||||
/// Начальная дата и время.
|
||||
/// </summary>
|
||||
public DateTime TimeMin { get; set; } = timeMin;
|
||||
|
||||
/// <summary>
|
||||
/// Конечная дата и время.
|
||||
/// </summary>
|
||||
public DateTime TimeMax { get; set; } = timeMax;
|
||||
|
||||
/// <summary>
|
||||
/// Список идентификаторов аудиторий. (Guid)
|
||||
/// </summary>
|
||||
public List<Guid>? RoomId { get; set; } = roomId;
|
||||
|
||||
/// <summary>
|
||||
/// Список идентификаторов участников.
|
||||
/// </summary>
|
||||
public List<Guid>? AttendeePersonId { get; set; } = attendeePersonId;
|
||||
|
||||
public List<Guid>? CourseUnitRealizationId { get; set; } = courseUnitRealizationId;
|
||||
public List<Guid>? CycleRealizationId { get; set; } = cycleRealizationId;
|
||||
|
||||
/// <summary>
|
||||
/// Список кодов специальностей.
|
||||
/// </summary>
|
||||
[DefaultValue(new string[] { "09.03.04" })]
|
||||
public List<string>? SpecialtyCode { get; set; } = specialtyCode;
|
||||
|
||||
/// <summary>
|
||||
/// Список годов начала обучения.
|
||||
/// </summary>
|
||||
[DefaultValue(new int[] { 2022, 2023, 2024, 2025 })]
|
||||
public List<int>? LearningStartYear { get; set; } = learningStartYear;
|
||||
|
||||
/// <summary>
|
||||
/// Список названий профилей подготовки.
|
||||
/// </summary>
|
||||
[DefaultValue(new string[] { "Методы и средства разработки программного обеспечения" })]
|
||||
public List<string>? ProfileName { get; set; } = profileName;
|
||||
|
||||
/// <summary>
|
||||
/// Список идентификаторов учебных планов.
|
||||
/// </summary>
|
||||
public List<Guid>? CurriculumId { get; set; } = curriculumId;
|
||||
|
||||
/// <summary>
|
||||
/// Список типов мероприятий.
|
||||
/// </summary>
|
||||
[DefaultValue(new string[] { "MID_CHECK", "CONS", "LAB", "LECT", "SEMI", "EVENT_OTHER", "SELF", "CUR_CHECK" })]
|
||||
public List<string>? TypeId { get; set; } = typeId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DTO для поиска аудиторий.
|
||||
/// </summary>
|
||||
public class RoomSearchRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Название аудитории.
|
||||
/// </summary>
|
||||
[DefaultValue("")]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка.
|
||||
/// </summary>
|
||||
[DefaultValue("+building.name,+name")]
|
||||
public string Sort { get; set; } = "+building.name,+name";
|
||||
|
||||
/// <summary>
|
||||
/// Количество элементов в ответе.
|
||||
/// </summary>
|
||||
[DefaultValue(10)]
|
||||
public int Size { get; set; } = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Номер страницы. (пагинация)
|
||||
/// </summary>
|
||||
[DefaultValue(0)]
|
||||
public int Page { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Исключать архивные аудитории. false = да, true = нет
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Deleted { get; set; } = false;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SfeduSchedule
|
||||
{
|
||||
/// <summary>
|
||||
/// DTO для запроса расписания в Modeus.
|
||||
/// </summary>
|
||||
public class ModeusScheduleRequest(int size, DateTime timeMin, DateTime timeMax, List<Guid>? roomId, List<Guid>? attendeePersonId,
|
||||
List<Guid>? courseUnitRealizationId, List<Guid>? cycleRealizationId, List<string>? specialtyCode,
|
||||
List<int>? learningStartYear, List<string>? profileName, List<Guid>? curriculumId, List<string>? typeId)
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество элементов в ответе.
|
||||
/// </summary>
|
||||
[DefaultValue(10)]
|
||||
public int Size { get; set; } = size;
|
||||
|
||||
/// <summary>
|
||||
/// Начальная дата и время.
|
||||
/// </summary>
|
||||
public DateTime TimeMin { get; set; } = timeMin;
|
||||
|
||||
/// <summary>
|
||||
/// Конечная дата и время.
|
||||
/// </summary>
|
||||
public DateTime TimeMax { get; set; } = timeMax;
|
||||
|
||||
/// <summary>
|
||||
/// Список идентификаторов аудиторий. (Guid)
|
||||
/// </summary>
|
||||
public List<Guid>? RoomId { get; set; } = roomId;
|
||||
|
||||
/// <summary>
|
||||
/// Список идентификаторов участников.
|
||||
/// </summary>
|
||||
public List<Guid>? AttendeePersonId { get; set; } = attendeePersonId;
|
||||
|
||||
public List<Guid>? CourseUnitRealizationId { get; set; } = courseUnitRealizationId;
|
||||
public List<Guid>? CycleRealizationId { get; set; } = cycleRealizationId;
|
||||
|
||||
/// <summary>
|
||||
/// Список кодов специальностей.
|
||||
/// </summary>
|
||||
[DefaultValue(new string[] { "09.03.04" })]
|
||||
public List<string>? SpecialtyCode { get; set; } = specialtyCode;
|
||||
|
||||
/// <summary>
|
||||
/// Список годов начала обучения.
|
||||
/// </summary>
|
||||
[DefaultValue(new int[] { 2022, 2023, 2024, 2025 })]
|
||||
public List<int>? LearningStartYear { get; set; } = learningStartYear;
|
||||
|
||||
/// <summary>
|
||||
/// Список названий профилей подготовки.
|
||||
/// </summary>
|
||||
[DefaultValue(new string[] { "Методы и средства разработки программного обеспечения" })]
|
||||
public List<string>? ProfileName { get; set; } = profileName;
|
||||
|
||||
/// <summary>
|
||||
/// Список идентификаторов учебных планов.
|
||||
/// </summary>
|
||||
public List<Guid>? CurriculumId { get; set; } = curriculumId;
|
||||
|
||||
/// <summary>
|
||||
/// Список типов мероприятий.
|
||||
/// </summary>
|
||||
[DefaultValue(new string[] { "MID_CHECK","CONS","LAB","LECT","SEMI","EVENT_OTHER","SELF","CUR_CHECK" })]
|
||||
public List<string>? TypeId { get; set; } = typeId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DTO для поиска аудиторий.
|
||||
/// </summary>
|
||||
public class RoomSearchRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Название аудитории.
|
||||
/// </summary>
|
||||
[DefaultValue("")]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка.
|
||||
/// </summary>
|
||||
[DefaultValue("+building.name,+name")]
|
||||
public string Sort { get; set; } = "+building.name,+name";
|
||||
|
||||
/// <summary>
|
||||
/// Количество элементов в ответе.
|
||||
/// </summary>
|
||||
[DefaultValue(10)]
|
||||
public int Size { get; set; } = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Номер страницы. (пагинация)
|
||||
/// </summary>
|
||||
[DefaultValue(0)]
|
||||
public int Page { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Исключать архивные аудитории. false = да, true = нет
|
||||
/// </summary>
|
||||
[DefaultValue(false)]
|
||||
public bool Deleted { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
@@ -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<ModeusService> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ModeusService(HttpClient httpClient, ILogger<ModeusService> logger, IConfiguration configuration)
|
||||
{
|
||||
_options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
@@ -24,7 +23,7 @@ namespace SfeduSchedule.Services
|
||||
public async Task<string?> 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<string?> 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();
|
||||
|
||||
Reference in New Issue
Block a user