И ещё попытки поработать с билдером
This commit is contained in:
@@ -52,16 +52,6 @@ public class EntitySerialization
|
||||
|
||||
private static void RegisterBuilders()
|
||||
{
|
||||
// Добавляем построитель для FullEntity
|
||||
NewBuilder<FullEntity>()
|
||||
.AddGroup(
|
||||
"Основная сущность",
|
||||
builder =>
|
||||
{
|
||||
builder.AddField(fe => fe.Entity).AddField(fe => fe.SubEntity);
|
||||
}
|
||||
);
|
||||
|
||||
NewBuilder<Entity>()
|
||||
.AddGroup(
|
||||
"Сущность",
|
||||
|
||||
@@ -9,6 +9,15 @@ public class SerializationResult
|
||||
/// Группы полей.
|
||||
/// </summary>
|
||||
public List<SerializationGroup> Groups { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Расширяет текущий результат сериализации, добавляя группы из другого результата.
|
||||
/// </summary>
|
||||
/// <param name="other">Другой результат сериализации.</param>
|
||||
public void ExtendWith(SerializationResult other)
|
||||
{
|
||||
Groups.AddRange(other.Groups);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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<EntityType>(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", "/"),
|
||||
|
||||
Reference in New Issue
Block a user