This commit is contained in:
greeneclipse committed 2026-10-16 13:48:51 +02:00
1 parent feebf7d3c1
commit 486502852e
41 files changed
+1311 -259

No files matched your search

+13 -8
View File
@@ -94,7 +94,7 @@ func (s *Service) ListCategories(ctx context.Context, companyID uuid.UUID, f Lis
off := len(args)
rows, err := s.Pool.Query(ctx, fmt.Sprintf(`
SELECT id, name, unique_id, parent_unique_id, path, level, position, is_active, description,
title_template, description_template,
title_template, description_template, COALESCE(localized_fields,'{}'::jsonb) AS localized_fields,
(title_template IS NOT NULL AND jsonb_typeof(title_template) = 'object'
AND COALESCE(jsonb_array_length(title_template->'elements'), 0) > 0) AS has_title_formula,
(description_template IS NOT NULL AND jsonb_typeof(description_template) = 'object'
@@ -113,12 +113,13 @@ func (s *Service) ListCategories(ctx context.Context, companyID uuid.UUID, f Lis
defer rows.Close()
items, err := scanMaps(rows, []string{
"id", "name", "unique_id", "parent_unique_id", "path", "level", "position", "is_active", "description",
"title_template", "description_template", "has_title_formula", "has_description_formula", "has_prompt",
"title_template", "description_template", "localized_fields", "has_title_formula", "has_description_formula", "has_prompt",
"created_at", "updated_at",
})
if err != nil {
return nil, 0, err
}
localizeCatalogImportNames(ctx, items)
if total, ok := exactTotalFromPage(f.Offset, f.Limit, len(items)); ok {
return items, total, nil
}
@@ -186,15 +187,16 @@ func (s *Service) GetCategory(ctx context.Context, companyID, id uuid.UUID) (map
SELECT 1 FROM jsonb_each_text(COALESCE(prompt, '{}'::jsonb)) kv
WHERE length(trim(kv.value)) > 0
)) AS has_prompt,
title_template, description_template, created_at, updated_at
title_template, description_template, COALESCE(localized_fields,'{}'::jsonb), created_at, updated_at
FROM categories WHERE id = $1 AND company_id = $2`, id, companyID)
item, err := scanMap(row, []string{
"id", "name", "unique_id", "parent_unique_id", "path", "level", "position", "is_active", "description",
"prompts", "has_prompt", "title_template", "description_template", "created_at", "updated_at",
"prompts", "has_prompt", "title_template", "description_template", "localized_fields", "created_at", "updated_at",
})
if err != nil {
return nil, err
}
localizeCatalogImportNames(ctx, []map[string]any{item})
return enrichCategoryPrompts(ctx, s.Pool, companyID, item)
}
@@ -377,8 +379,8 @@ func (s *Service) ListAttributes(ctx context.Context, companyID uuid.UUID, f Lis
args := []any{companyID}
where := []string{"a.company_id = $1"}
from := "attributes a"
selectCols := "a.id, a.attribute_key, a.name, a.value_type, a.unit, a.example, a.parent_key, a.created_at, a.updated_at"
scanCols := []string{"id", "attribute_key", "name", "value_type", "unit", "example", "parent_key", "created_at", "updated_at"}
selectCols := "a.id, a.attribute_key, a.name, a.value_type, a.unit, a.example, a.parent_key, COALESCE(a.localized_fields,'{}'::jsonb), a.created_at, a.updated_at"
scanCols := []string{"id", "attribute_key", "name", "value_type", "unit", "example", "parent_key", "localized_fields", "created_at", "updated_at"}
if f.Category != "" {
from = `attributes a
INNER JOIN category_attributes ca
@@ -417,6 +419,7 @@ func (s *Service) ListAttributes(ctx context.Context, companyID uuid.UUID, f Lis
if err != nil {
return nil, 0, err
}
localizeCatalogImportNames(ctx, items)
if total, ok := exactTotalFromPage(f.Offset, f.Limit, len(items)); ok {
return items, total, nil
}
@@ -1324,6 +1327,7 @@ func (s *Service) GetProcessedProduct(ctx context.Context, companyID, id uuid.UU
`+processedHasProcessedAttributesSQL+` AS has_processed_attributes,
`+processedHasEprelSQL+` AS has_eprel,
COALESCE(p.localized_content, '{}'::jsonb) AS localized_content,
COALESCE(r.source_localizations, '{}'::jsonb) || COALESCE(p.source_localizations, '{}'::jsonb) AS source_localizations,
p.created_at, p.updated_at
FROM processed_products p
LEFT JOIN raw_products r ON r.id = p.raw_product_id
@@ -1338,7 +1342,7 @@ func (s *Service) GetProcessedProduct(ctx context.Context, companyID, id uuid.UU
"feed_id", "feed_name", "feed_last_synced_at", "raw_updated_at",
"has_processed_name", "has_processed_description", "has_attributes", "has_processed_attributes",
"has_eprel",
"localized_content",
"localized_content", "source_localizations",
"created_at", "updated_at",
})
if err != nil {
@@ -1384,6 +1388,7 @@ func (s *Service) GetRawProduct(ctx context.Context, companyID, id uuid.UUID) (m
false AS has_processed_attributes,
`+strings.ReplaceAll(processedHasEprelSQL, "r.mapped_data", "rp.mapped_data")+` AS has_eprel,
'{}'::jsonb AS localized_content,
COALESCE(rp.source_localizations, '{}'::jsonb) AS source_localizations,
rp.created_at, rp.updated_at,
(COALESCE(NULLIF(trim(rp.mapped_data->>'name'), ''), NULLIF(trim(rp.mapped_data->>'title'), ''), '') <> '') AS has_name,
(COALESCE(NULLIF(trim(rp.mapped_data->>'description'), ''), '') <> '') AS has_description,
@@ -1399,7 +1404,7 @@ func (s *Service) GetRawProduct(ctx context.Context, companyID, id uuid.UUID) (m
"feed_id", "feed_name", "feed_last_synced_at", "raw_updated_at",
"has_processed_name", "has_processed_description", "has_attributes", "has_processed_attributes",
"has_eprel",
"localized_content",
"localized_content", "source_localizations",
"created_at", "updated_at",
"has_name", "has_description", "has_category",
"is_processed", "processing_status",