Add external product prices (#47)

Co-authored-by: Niklas Fondberg <niklas.fondberg@photowall.se>
This commit is contained in:
Fredrik Ringqvist
2022-02-17 12:52:04 +01:00
committed by GitHub
co-authored by Niklas Fondberg
parent f0b18c6757
commit b1177a1e1c
5 changed files with 244 additions and 3 deletions
+46
View File
@@ -0,0 +1,46 @@
# coding=UTF-8
from api.extensions import db
from api.lib.utils import lru_with_ttl
@lru_with_ttl(ttl_seconds=300)
def get_all_external_print_products():
sql="select external_product_id, price_sek, group_id from external_print_products"
result = db.session.execute(sql)
rows = result.fetchall()
prices = {}
for row in rows:
external_id = row[0]
price = float(row[1])
group_id = row[2]
prices[external_id] = {"price": price, "group_id": group_id}
return prices
def get_external_print_product(id):
all = get_all_external_print_products()
if id not in all:
raise ValueError("Invalid external product id: {}".format(id))
external_product = all.get(id)
return external_product
def get_cheapest_canvas_product():
sql = "select external_product_id from external_print_products where group_id = 2 order by price_sek limit 1"
result = db.session.execute(sql)
external_id = result.first()[0]
return external_id
def get_cheapest_poster_product():
sql = "select external_product_id from external_print_products where group_id in (7,8) order by price_sek limit 1"
result = db.session.execute(sql)
external_id = result.first()[0]
return external_id