using TakeoutSaaS.Application.Dictionary.Models;
using TakeoutSaaS.Domain.Dictionary.Entities;
namespace TakeoutSaaS.Application.Dictionary.Services;
///
/// 字典实体映射辅助。
///
internal static class DictionaryMapper
{
internal static DictionaryGroupDto ToGroupDto(DictionaryGroup group, IReadOnlyList? items = null)
{
return new DictionaryGroupDto
{
Id = group.Id,
TenantId = group.TenantId,
Code = group.Code,
Name = group.Name,
Scope = group.Scope,
AllowOverride = group.AllowOverride,
Description = group.Description,
IsEnabled = group.IsEnabled,
CreatedAt = group.CreatedAt,
UpdatedAt = group.UpdatedAt,
RowVersion = group.RowVersion,
Items = items ?? Array.Empty()
};
}
internal static DictionaryItemDto ToItemDto(DictionaryItem item)
{
return new DictionaryItemDto
{
Id = item.Id,
GroupId = item.GroupId,
Key = item.Key,
Value = DictionaryValueConverter.Deserialize(item.Value),
IsDefault = item.IsDefault,
IsEnabled = item.IsEnabled,
SortOrder = item.SortOrder,
Description = item.Description,
Source = item.TenantId == 0 ? "system" : "tenant",
RowVersion = item.RowVersion
};
}
}