fix: синхронизации лекций
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m3s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 25s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 7s

This commit is contained in:
2026-05-12 00:44:27 +03:00
parent 9b28a09253
commit 860964e3c2
4 changed files with 272 additions and 19 deletions
@@ -1,4 +1,5 @@
using System.Net.Http.Json;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using UniVerse.Application.DTOs.Sync;
@@ -21,11 +22,30 @@ public class ModeusApiClient : IModeusApiClient
public async Task<ModeusEventsResponse> SearchEventsAsync(SyncScheduleRequest request)
{
var body = new { specialtyCode = request.SpecialtyCode, timeMin = request.TimeMin, timeMax = request.TimeMax, typeId = request.TypeId };
const int pageSize = 900;
var specialtyCodes = string.IsNullOrWhiteSpace(request.SpecialtyCode)
? []
: request.SpecialtyCode
.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
var typeIds = request.TypeId ?? [];
var body = new Dictionary<string, object?>
{
["size"] = pageSize,
["timeMin"] = request.TimeMin,
["timeMax"] = request.TimeMax,
["specialtyCode"] = specialtyCodes
};
if (typeIds.Count > 0)
body["typeId"] = typeIds;
var response = await _http.PostAsJsonAsync("/api/proxy/events/search", body);
var requestJson = JsonSerializer.Serialize(body);
await EnsureSuccessAsync(response, "Modeus events search",
$"specialtyCode={request.SpecialtyCode ?? "<empty>"}, timeMin={request.TimeMin:O}, timeMax={request.TimeMax:O}, typeId=[{string.Join(", ", request.TypeId ?? [])}]");
return await response.Content.ReadFromJsonAsync<ModeusEventsResponse>() ?? new(new());
BuildEventsRequestSummary(pageSize, specialtyCodes, request.TimeMin, request.TimeMax, typeIds, requestJson));
return await ReadJsonAsync<ModeusEventsResponse>(response, "Modeus events search",
BuildEventsRequestSummary(pageSize, specialtyCodes, request.TimeMin, request.TimeMax, typeIds, requestJson))
?? new ModeusEventsResponse();
}
public async Task<ModeusRoomsResponse> SearchRoomsAsync()
@@ -50,7 +70,9 @@ public class ModeusApiClient : IModeusApiClient
await EnsureSuccessAsync(response, "Modeus rooms search",
$"name=<empty>, sort=+building.name,+name, size={pageSize}, page={page}, deleted=false");
var payload = await response.Content.ReadFromJsonAsync<ModeusRoomsResponse>() ?? new ModeusRoomsResponse();
var payload = await ReadJsonAsync<ModeusRoomsResponse>(response, "Modeus rooms search",
$"name=<empty>, sort=+building.name,+name, size={pageSize}, page={page}, deleted=false")
?? new ModeusRoomsResponse();
allRooms.AddRange(payload.RoomItems);
totalPages = payload.Page?.TotalPages ?? page + 1;
@@ -66,15 +88,54 @@ public class ModeusApiClient : IModeusApiClient
if (response.IsSuccessStatusCode) return;
var responseBody = await response.Content.ReadAsStringAsync();
if (responseBody.Length > 2000)
responseBody = string.Concat(responseBody.AsSpan(0, 2000), "...<truncated>");
throw new HttpRequestException(
$"{operation} failed with HTTP {(int)response.StatusCode} {response.ReasonPhrase}. Request: {requestSummary}. Response body: {responseBody}",
$"{operation} failed with HTTP {(int)response.StatusCode} {response.ReasonPhrase}. Request: {requestSummary}. Response body: {Truncate(responseBody)}",
null,
response.StatusCode);
}
private static string BuildEventsRequestSummary(
int size,
IReadOnlyList<string> specialtyCodes,
DateTime? timeMin,
DateTime? timeMax,
IReadOnlyList<string> typeIds,
string requestJson)
{
var typeFilter = typeIds.Count > 0 ? $"typeId=[{string.Join(", ", typeIds)}]" : "typeId=<omitted>";
return $"size={size}, specialtyCode=[{string.Join(", ", specialtyCodes)}], timeMin={timeMin:O}, timeMax={timeMax:O}, {typeFilter}. Request JSON: {requestJson}";
}
private static async Task<T?> ReadJsonAsync<T>(HttpResponseMessage response, string operation, string requestSummary)
{
var responseBody = await response.Content.ReadAsStringAsync();
var contentType = response.Content.Headers.ContentType?.ToString() ?? "<empty>";
var contentLength = response.Content.Headers.ContentLength?.ToString() ?? "<unknown>";
if (string.IsNullOrWhiteSpace(responseBody))
{
throw new HttpRequestException(
$"{operation} returned HTTP {(int)response.StatusCode} {response.ReasonPhrase} with an empty response body. Request: {requestSummary}. Content-Type: {contentType}. Content-Length: {contentLength}.",
null,
response.StatusCode);
}
try
{
return JsonSerializer.Deserialize<T>(responseBody, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
}
catch (JsonException ex)
{
throw new InvalidOperationException(
$"{operation} returned invalid JSON. Request: {requestSummary}. Content-Type: {contentType}. Response body: {Truncate(responseBody)}",
ex);
}
}
private static string Truncate(string value) =>
value.Length > 2000 ? string.Concat(value.AsSpan(0, 2000), "...<truncated>") : value;
public async Task<List<ModeusEmployee>> SearchEmployeeAsync(string fullname)
{
var response = await _http.GetFromJsonAsync<List<ModeusEmployee>>(