Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/models/Drink_Orders.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
from models.Drinks import Drinks
from models.Customer import Customer
from __init__ import CONN, CURSOR

class DrinkOrder:

class Drink_Orders():
def __init__(self):
pass

def age_verification():
#Test for age requirements here, build on it later
if customer.age < drinks.age_requirement:
print("Can't Drink")
raise ValueError("Not Old Enough For Alcohol")
else:
print("Party On!")
@classmethod
def customer_drinks(cls):
sql = '''
customer_name TEXT,
customer_id INTEGER,
drink_name TEXT,
drink_id INTEGER,
PRIMARY KEY (customer_name, customer_id, drink_name, drink_id),
FOREIGN KEY (customer_name) REFERENCES customer(name),
FOREIGN KEY (customer_id) REFERENCES customer(id),
FOREIGN KEY (drink_name) REFERENCES drink(name),
FOREIGN KEY (drink_id) REFERENCES drinks(id);
'''
CURSOR.execute(sql)
CONN.commit()



31 changes: 31 additions & 0 deletions lib/models/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Drop the tables if they exist
cursor.execute('DROP TABLE IF EXISTS customer')
cursor.execute('DROP TABLE IF EXISTS drinks')
cursor.execute('DROP TABLE IF EXISTS drink_orders')

# Create tables
cursor.execute('''
Expand All @@ -26,6 +27,20 @@
)
''')

cursor.execute('''
CREATE TABLE IF NOT EXISTS drink_orders (
customer_name TEXT,
customer_id INTEGER,
drink_name TEXT,
drink_id INTEGER,
PRIMARY KEY (customer_name, customer_id, drink_name, drink_id),
FOREIGN KEY (customer_name) REFERENCES customer(name),
FOREIGN KEY (customer_id) REFERENCES customer(id),
FOREIGN KEY (drink_name) REFERENCES drink(name),
FOREIGN KEY (drink_id) REFERENCES drinks(id)
)
''')

# Function to insert data into the customer and drinks tables
def seed_db():
# Sample user data
Expand All @@ -44,6 +59,16 @@ def seed_db():
('Bees Knees',)
]

drink_orders = [
('Jay', 1, 'Cosmo', 1) # Jay ordered Cosmo
# (1, 3), # Jay ordered Tequila Sunrise
# (2, 2), # Victoria ordered Manhattan
# (3, 5), # Kerissa ordered Bees Knees
# (4, 4), # Madison ordered Rum Runner
# (5, 1), # Johnathan ordered Cosmo
# (5, 2) # Johnathan ordered Manhattan
]

# Insert sample customers into the database
cursor.executemany('''
INSERT INTO customer (name, age)
Expand All @@ -55,12 +80,18 @@ def seed_db():
INSERT INTO drinks (name)
VALUES (?)
''', drinks)

cursor.executemany('''
INSERT INTO drink_orders (customer_name, customer_id, drink_name, drink_id)
VALUES (?, ?, ?, ?)
''', drink_orders)

# Commit the transaction
conn.commit()

print(f"{len(customers)} customers added to the database.")
print(f"{len(drinks)} drinks added to the database.")
print(f"{len(customers)} customers, {len(drinks)} drinks, and {len(drink_orders)} drink-orders associations were added to the database.")

# Run the seed function
if __name__ == "__main__":
Expand Down