From a90496bd0bb649a6e4ef9da9c4f7a2d259ba449b Mon Sep 17 00:00:00 2001 From: Correl Date: Thu, 28 Jul 2022 20:04:04 -0400 Subject: [PATCH] Use foil price if the card in collection is foil --- tutor/database.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tutor/database.py b/tutor/database.py index e7e8c54..291e710 100644 --- a/tutor/database.py +++ b/tutor/database.py @@ -183,13 +183,16 @@ async def advanced_search( ] if sort_by == "price": orderings = [ - "CAST(COALESCE(card_prices.usd, card_prices.usd_foil, 0) as decimal) DESC", + "CAST(COALESCE(CASE WHEN \"copies\".\"isFoil\" THEN card_prices.usd_foil ELSE card_prices.usd END, 0) as decimal) DESC", *orderings, ] params["last_update_key"] = "last_update" query = " ".join( [ - "SELECT cards.*, card_prices.* FROM cards", + "SELECT cards.*, card_prices.*", + ", CASE WHEN \"copies\".\"isFoil\" THEN card_prices.usd_foil", + " ELSE card_prices.usd END AS usd", + "FROM cards", " ".join(joins), "WHERE" if constraints else "", " AND ".join(constraints),