-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfood_list_service.py
55 lines (43 loc) · 1.49 KB
/
food_list_service.py
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
49
50
51
52
53
54
55
from src.config.database import Conexao
db = Conexao()
def get_food_list():
datas = []
query = "SELECT * FROM public.food_list where status is not false order by created_at desc"
lista = db.consultar(query)
for item in lista:
data = {
"id": item[0],
"name": item[1],
"type": item[2],
"amount": item[3],
"created_at": item[5]
}
datas.append(data)
return datas
def add_to_food_list(item):
if item['food_type'] not in ['Proteina', 'Carboidrato', 'Gordura']:
return "Tipo alimento invalido."
else:
query = f"INSERT INTO public.food_list (nome, tipo, quantidade, created_at, updated_at) VALUES('{item['food_name']}', '{item['food_type']}', {item['food_amount']}, now(), now());"
data = db.manipular(query)
return data
def delete_item_to_food_list(id):
query = f"UPDATE public.food_list SET status=false, updated_at='now()' WHERE id={id};"
if db.manipular(query):
return f"ID: {id} removido com sucesso!"
else:
return f"Erro ao remover ID: {id}!"
def get_list_by_date_to_food_list(date):
datas = []
query = f"select * from food_list where created_at <= '{date}'"
list = db.consultar(query)
for item in list:
data = {
"id": item[0],
"name": item[1],
"type": item[2],
"amount": item[3],
"created_at": item[5]
}
datas.append(data)
return datas