-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromotions.py
More file actions
48 lines (44 loc) · 1.84 KB
/
promotions.py
File metadata and controls
48 lines (44 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from db import conn
from util import buildResponse
def getRestaurantPromotions(id_restaurant,headers):
try:
with conn.cursor() as cur:
sql_string = "SELECT * FROM promocion WHERE id_establecimiento = %s"
cur.execute(sql_string, (id_restaurant))
promos = cur.fetchall()
# Construir una lista de diccionarios en el formato deseado
promos_json = []
for promo in promos:
promo_dict = {
"establishment_id": promo[0],
"promotion_id": promo[1],
"promotion_name": promo[2],
"promotion_image" : promo[3],
"promotion_descriptive_text" : promo[4],
"promotion_price" : promo[5]
}
promos_json.append(promo_dict)
return buildResponse(200, headers, promos_json)
except Exception as e:
return buildResponse(500, headers,{'error': str(e)})
def getPromotions(headers):
try:
with conn.cursor() as cur:
sql_string = "SELECT * FROM promocion"
cur.execute(sql_string, )
promos = cur.fetchall()
# Construir una lista de diccionarios en el formato deseado
promos_json = []
for promo in promos:
promo_dict = {
"establishment_id": promo[0],
"promotion_id": promo[1],
"promotion_name": promo[2],
"promotion_image" : promo[3],
"promotion_descriptive_text" : promo[4],
"promotion_price" : promo[5]
}
promos_json.append(promo_dict)
return buildResponse(200, headers, promos_json)
except Exception as e:
return buildResponse(500, headers,{'error': str(e)})