diff --git a/src/mtgcoll/client/components/inventory.cljs b/src/mtgcoll/client/components/inventory.cljs index 97a8df7..1305a9f 100644 --- a/src/mtgcoll/client/components/inventory.cljs +++ b/src/mtgcoll/client/components/inventory.cljs @@ -32,7 +32,7 @@ (defvc inventory-management [card-id list-id] - (let [inventory (view-cursor :owned-card card-id) + (let [inventory (view-cursor :card-inventory card-id list-id (auth/get-username)) inventory (group-by :quality @inventory) colspan (if (can-modify-inventory?) 2 1) quantity-class (if (can-modify-inventory?) diff --git a/src/mtgcoll/views/core.clj b/src/mtgcoll/views/core.clj index 90f0b78..eb4d092 100644 --- a/src/mtgcoll/views/core.clj +++ b/src/mtgcoll/views/core.clj @@ -34,8 +34,8 @@ (view :simple-sets-list get-db #'sets/simple-sets-list) (view :sets-list get-db #'sets/sets-list) - (view :owned-card get-db #'collection/owned-card) - (view :total-owned-of-card get-db #'collection/total-owned-of-card) + (view :card-inventory get-db #'collection/card-inventory) + (view :total-card-inventory get-db #'collection/total-card-inventory) (view :card-pricing get-db #'prices/card-pricing) (view :pricing-sources get-db #'prices/pricing-sources) diff --git a/src/mtgcoll/views/functions/collection.clj b/src/mtgcoll/views/functions/collection.clj index 34bf8db..4245746 100644 --- a/src/mtgcoll/views/functions/collection.clj +++ b/src/mtgcoll/views/functions/collection.clj @@ -1,15 +1,25 @@ (ns mtgcoll.views.functions.collection) -(defn owned-card - [card-id] - ["select quality, quantity, foil - from collection - where card_id = ? AND list_id = 0" - card-id]) +(defn card-inventory + [card-id list-id user-id] + (let [list-id (int list-id) + public-only? (nil? user-id)] + ["select cl.quality, cl.quantity, cl.foil + from collection cl + join lists l on cl.list_id = l.id + where cl.card_id = ? + and cl.list_id = ? + and (l.is_public in (true, ?))" + card-id list-id public-only?])) -(defn total-owned-of-card - [card-id] - ["select count(*) - from collection - where card_id = ? AND list_id = 0" - card-id]) +(defn total-card-inventory + [card-id list-id user-id] + (let [list-id (int list-id) + public-only? (nil? user-id)] + ["select count(*) + from collection cl + join lists l on cl.list_id = l.id + where card_id = ? + and cl.list_id = ? + and (l.is_public in (true, ?))" + card-id list-id public-only?]))