dana-medical-site/internal/storage/price_sections.go
2026-10-14 13:33:13 +00:00

33 lines
961 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package storage
import (
"context"
"dana/internal/domain"
)
// PriceSectionsBrief отдаёт опубликованные разделы прайса со счётчиком позиций.
// Нужен меню в шапке: полный прайс — это 2400+ позиций, тянуть их туда незачем.
func (s *Storage) PriceSectionsBrief(ctx context.Context) ([]domain.PriceSectionBrief, error) {
rows, err := s.pool.Query(ctx, `
SELECT ps.id, ps.slug, ps.name,
(SELECT count(*) FROM price_items pi WHERE pi.section_id = ps.id AND pi.published)
FROM price_sections ps
WHERE ps.published
ORDER BY ps.sort, ps.name`)
if err != nil {
return nil, err
}
defer rows.Close()
out := []domain.PriceSectionBrief{}
for rows.Next() {
var b domain.PriceSectionBrief
if err := rows.Scan(&b.ID, &b.Slug, &b.Name, &b.Count); err != nil {
return nil, err
}
out = append(out, b)
}
return out, rows.Err()
}