diff --git a/internal/api/merch/repository.go b/internal/api/merch/repository.go index 7283fa9..dd21a46 100644 --- a/internal/api/merch/repository.go +++ b/internal/api/merch/repository.go @@ -342,9 +342,9 @@ func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) { if err := r.db.Raw(` WITH price_with_neighbors AS ( SELECT - p.id, p.created_at, p.merch_uuid, p.price, p.origins, m.name, - LAG(price) OVER (PARTITION BY p.merch_uuid, p.origins ORDER BY p.created_at, p.id) AS prev_price, - LEAD(price) OVER (PARTITION BY p.merch_uuid, p.origins ORDER BY p.created_at, p.id) AS next_price + p.id, p.created_at, p.merch_uuid, p.price, p.origin, m.name, + LAG(price) OVER (PARTITION BY p.merch_uuid, p.origin ORDER BY p.created_at, p.id) AS prev_price, + LEAD(price) OVER (PARTITION BY p.merch_uuid, p.origin ORDER BY p.created_at, p.id) AS next_price FROM prices AS p JOIN merch as m ON m.merch_uuid = p.merch_uuid WHERE p.deleted_at IS NULL @@ -352,7 +352,7 @@ func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) { AND m.user_uuid = ?) SELECT - id, created_at, merch_uuid, origins, name + id, created_at, merch_uuid, origin, name FROM price_with_neighbors WHERE price = 0 @@ -360,6 +360,7 @@ func (r *Repo) getZeroPrices(userUuid string) ([]ZeroPrice, error) { AND prev_price > 0 AND next_price IS NOT NULL AND next_price > 0; + ORDER BY created_at DESC `, userUuid).Scan(&priceList).Error; err != nil { return nil, err }