From eddd89cd09c486f614e72ff1f8217ba3364790fb Mon Sep 17 00:00:00 2001 From: nquidox Date: Sat, 20 Dec 2025 14:52:53 +0300 Subject: [PATCH] order desc added to query --- internal/api/merch/repository.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 }