rename card inventory views and add list id / user id parameters

This commit is contained in:
Gered 2016-08-01 14:51:35 -04:00
parent 1abbcf1302
commit 90a5a26c95
3 changed files with 25 additions and 15 deletions

View file

@ -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?)

View file

@ -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)

View file

@ -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]
(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
where card_id = ? AND list_id = 0"
card-id])
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?]))