feat: Улучшил обработку поля EventRooms
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 1m17s
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 1m17s
Обновил DTO и логику десериализации, чтобы корректно парсить `event-rooms`, которое может быть как одним объектом, так и массивом ссылок. Это исправило проблемы при извлечении ID комнат мероприятий.
This commit is contained in:
@@ -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<EventAttendees>
|
||||
public static readonly EventAttendeesConverter Singleton = new EventAttendeesConverter();
|
||||
}
|
||||
|
||||
internal class EventRoomsConverter : JsonConverter<EventRooms>
|
||||
{
|
||||
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<Self>(ref reader, options);
|
||||
return new EventRooms { Self = objectValue };
|
||||
case JsonTokenType.StartArray:
|
||||
var arrayValue = JsonSerializer.Deserialize<Self[]>(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<DateOnly>
|
||||
{
|
||||
private readonly string serializationFormat;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user