-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabasequeries.py
More file actions
52 lines (42 loc) · 1.84 KB
/
Copy pathdatabasequeries.py
File metadata and controls
52 lines (42 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
49
50
51
52
from database import Restaurant, Customer, Items, Order, db
def create_user(email, firstname, lastname, address, password, zip):
customer = Customer(Email = email, First_Name = firstname, Last_Name = lastname,
Address = address,Zip=zip)
customer.set_pass(password)
db.session.add(customer)
db.session.commit()
return customer
def get_user(email):
return Customer.query.filter_by(Email = email).first()
def create_restaurant(name,email,address,password,image,description,delivery_radius,openinghrs):
restaurant = Restaurant(Name=name,Email=email,Address=address,image=image,Description=description,Delivery_radius=delivery_radius,Opening_hours=openinghrs)
restaurant.set_pass(password)
db.session.add(restaurant)
db.session.commit()
return restaurant
def get_restaurant(email):
return Restaurant.query.filter_by(Email=email).first()
def create_menu_item(Category,Name,Price,Description,Picture,total_price,R_id):
item = Items(Category=Category,Name=Name,Price=Price,Description=Description,
Picture=Picture,Total_price=total_price,R_id=R_id)
db.session.add(item)
db.session.commit()
return item
def create_order(State,Date,customer_id,restaurant_id):
order = Order(State=State,Date=Date,customer_id=customer_id,restaurant_id=restaurant_id)
db.session.add(order)
db.session.commit()
return order
def get_orders_of_customer(customer_id):
return Order.query.filter_by(customer_id=customer_id).all()
def get_orders_of_restaurant(restaurant_id):
return Order.query.filter_by(restaurant_id=restaurant_id).all()
def get_items(R_id):
return Items.query.filter_by(R_id=R_id).all()
def delete_item(I_id):
item = Items.query.get(I_id)
if item:
db.session.delete(item)
db.session.commit()
return True
return False