Skip to content

Commit

Permalink
fix(styles): exclude soft-deleted reviews in cards
Browse files Browse the repository at this point in the history
Thank you, @a0eoc, for reporting this issue.
  • Loading branch information
vednoc committed Sep 25, 2023
1 parent 0fb12bb commit bf86cec
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/storage/style_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf86cec

Please sign in to comment.