diff --git a/Pf2e/Web/Helpers/EntitySerialization.cs b/Pf2e/Web/Helpers/EntitySerialization.cs index 60ad3de..16697c9 100644 --- a/Pf2e/Web/Helpers/EntitySerialization.cs +++ b/Pf2e/Web/Helpers/EntitySerialization.cs @@ -52,16 +52,6 @@ public class EntitySerialization private static void RegisterBuilders() { - // Добавляем построитель для FullEntity - NewBuilder() - .AddGroup( - "Основная сущность", - builder => - { - builder.AddField(fe => fe.Entity).AddField(fe => fe.SubEntity); - } - ); - NewBuilder() .AddGroup( "Сущность", diff --git a/Pf2e/Web/Helpers/Serialization/SerializationResult.cs b/Pf2e/Web/Helpers/Serialization/SerializationResult.cs index 8e18074..024b7d7 100644 --- a/Pf2e/Web/Helpers/Serialization/SerializationResult.cs +++ b/Pf2e/Web/Helpers/Serialization/SerializationResult.cs @@ -9,6 +9,15 @@ public class SerializationResult /// Группы полей. /// public List Groups { get; set; } = []; + + /// + /// Расширяет текущий результат сериализации, добавляя группы из другого результата. + /// + /// Другой результат сериализации. + public void ExtendWith(SerializationResult other) + { + Groups.AddRange(other.Groups); + } } /// diff --git a/Pf2e/Web/Pages/Entity.cshtml.cs b/Pf2e/Web/Pages/Entity.cshtml.cs index a508e23..f068c68 100644 --- a/Pf2e/Web/Pages/Entity.cshtml.cs +++ b/Pf2e/Web/Pages/Entity.cshtml.cs @@ -12,6 +12,7 @@ using Pf2e.Database.Model.Base; using Pf2e.Database.Model.Enum; using Pf2e.Database.Model.Structure; using Pf2e.Web.Helpers; +using Pf2e.Web.Helpers.Serialization; namespace Pf2e.Web.Pages { @@ -21,24 +22,13 @@ namespace Pf2e.Web.Pages private readonly Pf2eDbContext _context = context; public FullEntity FullEntity { get; set; } = null!; - public Pf2e.Web.Helpers.Serialization.SerializationResult SerializationResult { get; set; } = null!; + public SerializationResult SerializationResult { get; set; } = null!; public IActionResult OnGet(string type, string slug) { - // Добавим отладочную информацию - System.Diagnostics.Debug.WriteLine( - $"Entity.OnGet called with type: {type}, slug: {slug}" - ); - - // Логируем в консоль для веб-сервера - Console.WriteLine($"Entity.OnGet called with type: {type}, slug: {slug}"); - try { - // Получаем тип сущности EntityType entityType = EntityTypeModel.Enum(type); - System.Diagnostics.Debug.WriteLine($"EntityType resolved to: {entityType}"); - Console.WriteLine($"EntityType resolved to: {entityType}"); // Находим сущность по slug и типу Database.Model.Base.Entity? entity = _context @@ -49,29 +39,22 @@ namespace Pf2e.Web.Pages if (entity == null) { - System.Diagnostics.Debug.WriteLine( - $"Entity not found: type={entityType}, slug={slug}" - ); - Console.WriteLine($"Entity not found: type={entityType}, slug={slug}"); return NotFound(); } - System.Diagnostics.Debug.WriteLine( - $"Entity found: {entity.Id} - {entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English]}" - ); - Console.WriteLine( - $"Entity found: {entity.Id} - {entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English]}" - ); - // Создаём FullEntity FullEntity = new(_context, entityType, entity.Id); // Сериализуем для отображения EntitySerialization serializer = new(); - SerializationResult = serializer.Serialize(FullEntity); + SerializationResult = serializer.Serialize(FullEntity.Entity); + if (FullEntity.SubEntity is not null) + { + SerializationResult.ExtendWith(serializer.Serialize(FullEntity.SubEntity)); + } // Set breadcrumbs - var typeName = Pf2e.Web.Helpers.PgNameHelper.GetPgName(entityType); + string typeName = PgNameHelper.GetPgName(entityType); ViewData["Breadcrumbs"] = new List<(string, string)> { ("Home", "/"),