From ba54deab11540392548905cbc751503070e23229 Mon Sep 17 00:00:00 2001 From: Sergey Karmanov Date: Tue, 20 Jan 2026 06:33:02 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8F=20EventRooms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Обновил DTO и логику десериализации, чтобы корректно парсить `event-rooms`, которое может быть как одним объектом, так и массивом ссылок. Это исправило проблемы при извлечении ID комнат мероприятий. --- .../DTO/ScheduleDTO.CS | 51 ++++++++++++++++++- SfeduSchedule/Services/ModeusService.cs | 11 ++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/ModeusSchedule.Abstractions/DTO/ScheduleDTO.CS b/ModeusSchedule.Abstractions/DTO/ScheduleDTO.CS index e2a0d9d..8f432dc 100644 --- a/ModeusSchedule.Abstractions/DTO/ScheduleDTO.CS +++ b/ModeusSchedule.Abstractions/DTO/ScheduleDTO.CS @@ -188,7 +188,7 @@ public partial class EventLocationLinks [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("event-rooms")] - public Self EventRooms { get; set; } + public EventRooms? EventRooms { get; set; } } public partial class EventOrganizer @@ -408,6 +408,15 @@ public partial struct EventAttendees public static implicit operator EventAttendees(Self[] SelfArray) => new EventAttendees { SelfArray = SelfArray }; } +public partial struct EventRooms +{ + public Self Self; + public Self[] SelfArray; + + public static implicit operator EventRooms(Self Self) => new EventRooms { Self = Self }; + public static implicit operator EventRooms(Self[] SelfArray) => new EventRooms { SelfArray = SelfArray }; +} + public partial class Schedule { public static Schedule FromJson(string json) => @@ -426,6 +435,7 @@ internal static class Converter Converters = { EventAttendeesConverter.Singleton, + EventRoomsConverter.Singleton, new DateOnlyConverter(), new TimeOnlyConverter(), IsoDateTimeOffsetConverter.Singleton @@ -472,6 +482,45 @@ internal class EventAttendeesConverter : JsonConverter public static readonly EventAttendeesConverter Singleton = new EventAttendeesConverter(); } +internal class EventRoomsConverter : JsonConverter +{ + public override bool CanConvert(Type t) => t == typeof(EventRooms); + + public override EventRooms Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case JsonTokenType.StartObject: + var objectValue = JsonSerializer.Deserialize(ref reader, options); + return new EventRooms { Self = objectValue }; + case JsonTokenType.StartArray: + var arrayValue = JsonSerializer.Deserialize(ref reader, options); + return new EventRooms { SelfArray = arrayValue }; + } + + throw new Exception("Cannot unmarshal type EventRooms"); + } + + public override void Write(Utf8JsonWriter writer, EventRooms value, JsonSerializerOptions options) + { + if (value.SelfArray != null) + { + JsonSerializer.Serialize(writer, value.SelfArray, options); + return; + } + + if (value.Self != null) + { + JsonSerializer.Serialize(writer, value.Self, options); + return; + } + + throw new Exception("Cannot marshal type EventRooms"); + } + + public static readonly EventRoomsConverter Singleton = new EventRoomsConverter(); +} + public class DateOnlyConverter : JsonConverter { private readonly string serializationFormat; diff --git a/SfeduSchedule/Services/ModeusService.cs b/SfeduSchedule/Services/ModeusService.cs index 3542425..dc330db 100644 --- a/SfeduSchedule/Services/ModeusService.cs +++ b/SfeduSchedule/Services/ModeusService.cs @@ -87,10 +87,15 @@ public class ModeusService var eventLocation = scheduleJson.Embedded.EventLocations.FirstOrDefault(el => el.EventId == e.Id); if (eventLocation != null && eventLocation.Links != null - && eventLocation.Links.EventRooms != null - && eventLocation.Links.EventRooms.Href != null) + && eventLocation.Links.EventRooms != null) { - var eventRoomId = eventLocation.Links.EventRooms.Href.Split('/').Last(); + var eventRoomsLink = eventLocation.Links.EventRooms.Value; + var eventRoomsHref = eventRoomsLink.Self?.Href + ?? eventRoomsLink.SelfArray?.FirstOrDefault()?.Href; + if (string.IsNullOrWhiteSpace(eventRoomsHref)) + continue; + + var eventRoomId = eventRoomsHref.Split('/').Last(); var EventRoom = scheduleJson.Embedded.EventRooms.FirstOrDefault(er => er.Id.ToString().ToLower() == eventRoomId);