Add product features, Heleket crypto payments and order status icons.

This commit is contained in:
shop
2026-06-27 16:29:33 +03:00
parent 361d35e6b4
commit 98a0bb01e2
31 changed files with 1673 additions and 126 deletions
+49
View File
@@ -0,0 +1,49 @@
package repository
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
"shop/internal/models"
)
type PriceHistoryRepository struct {
pool *pgxpool.Pool
}
func NewPriceHistoryRepository(pool *pgxpool.Pool) *PriceHistoryRepository {
return &PriceHistoryRepository{pool: pool}
}
func (r *PriceHistoryRepository) Record(ctx context.Context, productID int, price, salePrice float64) error {
_, err := r.pool.Exec(ctx, `
INSERT INTO product_price_history (product_id, price, sale_price)
VALUES ($1, $2, NULLIF($3, 0))
`, productID, price, salePrice)
return err
}
func (r *PriceHistoryRepository) ByProduct(ctx context.Context, productID int, limit int) ([]models.PriceHistoryEntry, error) {
rows, err := r.pool.Query(ctx, `
SELECT id, product_id, price, COALESCE(sale_price, 0), recorded_at
FROM product_price_history
WHERE product_id = $1
ORDER BY recorded_at DESC
LIMIT $2
`, productID, limit)
if err != nil {
return nil, err
}
defer rows.Close()
var entries []models.PriceHistoryEntry
for rows.Next() {
var e models.PriceHistoryEntry
if err := rows.Scan(&e.ID, &e.ProductID, &e.Price, &e.SalePrice, &e.RecordedAt); err != nil {
return nil, err
}
entries = append(entries, e)
}
return entries, rows.Err()
}