Compare commits
3 Commits
b2c22ab65c
...
a7f6d4de9f
| Author | SHA1 | Date | |
|---|---|---|---|
| a7f6d4de9f | |||
| e7526241d1 | |||
| 2ac561b46f |
63
SfeduSchedule.Abstractions/AttendeesDTO.cs
Normal file
63
SfeduSchedule.Abstractions/AttendeesDTO.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
#nullable enable
|
||||
#pragma warning disable CS8618
|
||||
#pragma warning disable CS8601
|
||||
#pragma warning disable CS8603
|
||||
|
||||
namespace SfeduSchedule.Abstractions;
|
||||
|
||||
public partial class Attendees
|
||||
{
|
||||
public static List<Attendees> FromJson(string json) => JsonSerializer.Deserialize<List<Attendees>>(json);
|
||||
}
|
||||
|
||||
public partial class Attendees
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[JsonPropertyName("roleId")]
|
||||
public string RoleId { get; set; }
|
||||
|
||||
[JsonPropertyName("roleName")]
|
||||
public string RoleName { get; set; }
|
||||
|
||||
[JsonPropertyName("roleNamePlural")]
|
||||
public string RoleNamePlural { get; set; }
|
||||
|
||||
[JsonPropertyName("roleDisplayOrder")]
|
||||
public long RoleDisplayOrder { get; set; }
|
||||
|
||||
[JsonPropertyName("personId")]
|
||||
public Guid PersonId { get; set; }
|
||||
|
||||
[JsonPropertyName("lastName")]
|
||||
public string LastName { get; set; }
|
||||
|
||||
[JsonPropertyName("firstName")]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[JsonPropertyName("middleName")]
|
||||
public string MiddleName { get; set; }
|
||||
|
||||
[JsonPropertyName("fullName")]
|
||||
public string FullName { get; set; }
|
||||
|
||||
[JsonPropertyName("studentId")]
|
||||
public Guid? StudentId { get; set; }
|
||||
|
||||
[JsonPropertyName("specialtyCode")]
|
||||
public string SpecialtyCode { get; set; }
|
||||
|
||||
[JsonPropertyName("specialtyName")]
|
||||
public string SpecialtyName { get; set; }
|
||||
|
||||
[JsonPropertyName("specialtyProfile")]
|
||||
public string SpecialtyProfile { get; set; }
|
||||
}
|
||||
|
||||
#pragma warning restore CS8618
|
||||
#pragma warning restore CS8601
|
||||
#pragma warning restore CS8603
|
||||
@@ -5,6 +5,6 @@ namespace SfeduSchedule
|
||||
public static class GlobalVariables
|
||||
{
|
||||
public static string JwtFilePath { get; set; } = "data/jwt.txt";
|
||||
public static readonly JsonSerializerOptions jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
public static readonly JsonSerializerOptions jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
|
||||
}
|
||||
}
|
||||
@@ -68,8 +68,11 @@ builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration)
|
||||
|
||||
// Загружаем плагины (изолированно), даём им зарегистрировать DI и подключаем контроллеры
|
||||
var loaded = PluginLoader.LoadPlugins(pluginsPath);
|
||||
Console.WriteLine("Plugins count: " + loaded.Count);
|
||||
foreach (var p in loaded)
|
||||
{
|
||||
Console.WriteLine("Loading plugin: " + p.Instance.Name);
|
||||
|
||||
// DI из плагина
|
||||
p.Instance.ConfigureServices(builder.Services);
|
||||
|
||||
|
||||
@@ -31,9 +31,37 @@ namespace SfeduSchedule.Services
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
_logger.LogInformation("GetScheduleAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||
response.EnsureSuccessStatusCode();
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("GetScheduleAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||
return null;
|
||||
}
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Attendees>> GetAttendeesAsync(Guid eventId)
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get,
|
||||
$"schedule-calendar-v2/api/calendar/events/{eventId}/attendees");
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
_logger.LogInformation("GetAttendeesAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("GetAttendeesAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||
return new List<Attendees>();
|
||||
}
|
||||
List<Attendees>? attendees;
|
||||
try
|
||||
{
|
||||
attendees = Attendees.FromJson(await response.Content.ReadAsStringAsync());
|
||||
return attendees;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "GetAttendeesAsync: Deserialization failed.");
|
||||
}
|
||||
return new List<Attendees>();
|
||||
}
|
||||
|
||||
public async Task<string?> SearchRoomsAsync(RoomSearchRequest requestDto)
|
||||
{
|
||||
@@ -43,7 +71,11 @@ namespace SfeduSchedule.Services
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
_logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||
response.EnsureSuccessStatusCode();
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("SearchRoomsAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||
return null;
|
||||
}
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
@@ -60,7 +92,11 @@ namespace SfeduSchedule.Services
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
|
||||
_logger.LogInformation("GetGuidAsync: Ответ получен: {StatusCode}", response.StatusCode);
|
||||
response.EnsureSuccessStatusCode();
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("GetGuidAsync: Ошибка при получении списка студентов: {StatusCode}", response.StatusCode);
|
||||
return null;
|
||||
}
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -84,12 +120,12 @@ namespace SfeduSchedule.Services
|
||||
return personId;
|
||||
}
|
||||
|
||||
public async Task<string?> GetIcsAsync(ModeusScheduleRequest msr)
|
||||
public async Task<Schedule?> GetScheduleJsonAsync(ModeusScheduleRequest msr)
|
||||
{
|
||||
var schedule = await GetScheduleAsync(msr);
|
||||
if (schedule == null)
|
||||
{
|
||||
_logger.LogError("GetIcsAsync: Schedule is null. Request: {@msr}", msr);
|
||||
_logger.LogError("GetScheduleJsonAsync: Schedule is null. Request: " + JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -97,25 +133,48 @@ namespace SfeduSchedule.Services
|
||||
try
|
||||
{
|
||||
scheduleJson = Schedule.FromJson(schedule);
|
||||
switch (scheduleJson)
|
||||
{
|
||||
case null:
|
||||
_logger.LogError(
|
||||
"GetScheduleJsonAsync: scheduleJson is null. Schedule: {Schedule}\n Request: {msr}",
|
||||
schedule, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
break;
|
||||
case { Embedded: null }:
|
||||
_logger.LogError(
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {msr}",
|
||||
scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
break;
|
||||
case { Embedded.Events: null }:
|
||||
_logger.LogError(
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {msr}",
|
||||
scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
break;
|
||||
case { Embedded.Events.Length: 0 }:
|
||||
_logger.LogWarning(
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is empty. Embedded: {@Embedded}\n Request: {msr}",
|
||||
scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
break;
|
||||
default:
|
||||
return scheduleJson;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "GetIcsAsync: Deserialization failed. Schedule: {Schedule}\n Request: {@msr}", schedule, msr);
|
||||
return null;
|
||||
_logger.LogError(ex,
|
||||
"GetScheduleJsonAsync: Deserialization failed. Schedule: {Schedule}\n Request: {msr}", schedule,
|
||||
JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
}
|
||||
|
||||
if (scheduleJson?.Embedded?.Events is not { Length: > 0 } events)
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<string?> GetIcsAsync(ModeusScheduleRequest msr)
|
||||
{
|
||||
Schedule? scheduleJson = await GetScheduleJsonAsync(msr);
|
||||
if (scheduleJson == null)
|
||||
{
|
||||
if (scheduleJson == null)
|
||||
_logger.LogError("GetIcsAsync: scheduleJson is null. Schedule: {Schedule}\n Request: {@msr}", schedule, msr);
|
||||
else if (scheduleJson.Embedded == null)
|
||||
_logger.LogError("GetIcsAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {@msr}", scheduleJson, msr);
|
||||
else if (scheduleJson.Embedded.Events == null)
|
||||
_logger.LogError("GetIcsAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {@msr}",
|
||||
scheduleJson.Embedded, msr);
|
||||
else
|
||||
_logger.LogWarning("GetIcsAsync: scheduleJson.Embedded.Events is empty. Embedded: {@Embedded}\n Request: {@msr}",
|
||||
scheduleJson.Embedded, msr);
|
||||
_logger.LogError("GetIcsAsync: scheduleJson is null after deserialization. Request: " + JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user