fix: /api/categories возвращал display_order=0 для всех категорий
Коды брались из локальных компонентов, но display_order не проставлялся — поэтому categoryOrderMap на фронте был пустым и порядок в итоговой конфигурации не соблюдался. Теперь display_order берётся из DefaultCategories. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,6 +90,12 @@ func (h *ComponentHandler) Get(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ComponentHandler) GetCategories(c *gin.Context) {
|
func (h *ComponentHandler) GetCategories(c *gin.Context) {
|
||||||
|
// Build display_order lookup from the canonical list.
|
||||||
|
orderMap := make(map[string]int, len(models.DefaultCategories))
|
||||||
|
for _, cat := range models.DefaultCategories {
|
||||||
|
orderMap[strings.ToUpper(cat.Code)] = cat.DisplayOrder
|
||||||
|
}
|
||||||
|
|
||||||
codes, err := h.localDB.GetLocalComponentCategories()
|
codes, err := h.localDB.GetLocalComponentCategories()
|
||||||
if err == nil && len(codes) > 0 {
|
if err == nil && len(codes) > 0 {
|
||||||
categories := make([]models.Category, 0, len(codes))
|
categories := make([]models.Category, 0, len(codes))
|
||||||
@@ -98,7 +104,15 @@ func (h *ComponentHandler) GetCategories(c *gin.Context) {
|
|||||||
if trimmed == "" {
|
if trimmed == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
categories = append(categories, models.Category{Code: trimmed, Name: trimmed})
|
order := orderMap[strings.ToUpper(trimmed)]
|
||||||
|
if order == 0 {
|
||||||
|
order = models.MaxKnownDisplayOrder + 1
|
||||||
|
}
|
||||||
|
categories = append(categories, models.Category{
|
||||||
|
Code: trimmed,
|
||||||
|
Name: trimmed,
|
||||||
|
DisplayOrder: order,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, categories)
|
c.JSON(http.StatusOK, categories)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user