From bf86cec0a82d123ad7f9f43a0c32b99248c74a1e Mon Sep 17 00:00:00 2001 From: vednoc Date: Mon, 25 Sep 2023 20:35:02 +0200 Subject: [PATCH] fix(styles): exclude soft-deleted reviews in cards Thank you, @a0eoc, for reporting this issue. --- modules/storage/style_card.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/storage/style_card.go b/modules/storage/style_card.go index 79904a95..840c3f17 100644 --- a/modules/storage/style_card.go +++ b/modules/storage/style_card.go @@ -161,7 +161,7 @@ func FindStyleCardsPaginated(page, size int, order string) ([]StyleCard, error) case strings.HasPrefix(order, "installs"): stmt = "id, (SELECT total_installs FROM histories h WHERE h.style_id = styles.id ORDER BY id DESC LIMIT 1) AS installs" case strings.HasPrefix(order, "rating"): - stmt = "id, (SELECT ROUND(AVG(rating), 1) FROM reviews r WHERE r.style_id = styles.id) AS rating" + stmt = "id, (SELECT ROUND(AVG(rating), 1) FROM reviews r WHERE r.style_id = styles.id AND r.deleted_at IS NULL) AS rating" } var nums []struct{ ID int } @@ -197,7 +197,7 @@ func FindStyleCardsPaginatedForUserID(page, size int, order string, id uint) ([] case strings.HasPrefix(order, "installs"): stmt = "id, (SELECT total_installs FROM histories h WHERE h.style_id = styles.id ORDER BY id DESC LIMIT 1) AS installs" case strings.HasPrefix(order, "rating"): - stmt = "id, (SELECT ROUND(AVG(rating), 1) FROM reviews r WHERE r.style_id = styles.id) AS rating" + stmt = "id, (SELECT ROUND(AVG(rating), 1) FROM reviews r WHERE r.style_id = styles.id AND r.deleted_at IS NULL) AS rating" } offset := (page - 1) * size