diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..172541d --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# SQLite database +/Backend/testData.db +*.db + +#Log files for some reason lol +*.log +logs/ diff --git a/Backend/Dockerfile b/Backend/Dockerfile new file mode 100644 index 0000000..d085169 --- /dev/null +++ b/Backend/Dockerfile @@ -0,0 +1,30 @@ +# Use Python as the base image +FROM python:3.8-slim-buster + +# Install pip and Python dependencies +RUN apt-get update && apt-get install -y python3 python3-pip + +# Keeps Python from generating .pyc files in the container +ENV PYTHONDONTWRITEBYTECODE=1 + +# Turns off buffering for easier container logging +ENV PYTHONUNBUFFERED=1 + + +# Set the working directory in the container +WORKDIR /app + + +# Install pip requirements +COPY /requirements.txt . +RUN python3 -m pip install -r requirements.txt + +# Copy main application file +COPY generateData.py . + +# Set the port for the application +ENV PORT=5000 +EXPOSE 5000 + +# Command to run the application +CMD ["python3", "generateData.py"] \ No newline at end of file diff --git a/Backend/everythingData.py b/Backend/everythingData.py new file mode 100644 index 0000000..32b0c3f --- /dev/null +++ b/Backend/everythingData.py @@ -0,0 +1,44 @@ +from contextlib import closing +import sqlite3 + +def connect_db(): + """Establish a connection to the SQLite database.""" + return sqlite3.connect('/home/sus98/2102/proj/cse2102-fall24-Team51/Backend/testData.db') #this might change + +def insert_user(name, age, marital_status, pet_preference): + """Insert a new user into the users table.""" + with closing(connect_db()) as conn, conn: + cursor = conn.cursor() + cursor.execute( + '''INSERT INTO users (name, age, marital_status, pet_preference) + VALUES (?, ?, ?, ?)''', + (name, age, marital_status, pet_preference) + ) + conn.commit() + return cursor.lastrowid + +def insert_pet(name, age, gender, breed, type, location, picture=None): + """Insert a new pet into the pets table.""" + with closing(connect_db()) as conn, conn: + cursor = conn.cursor() + cursor.execute( + '''INSERT INTO pets (name, age, gender, breed, type, location, picture) + VALUES (?, ?, ?, ?, ?, ?, ?)''', + (name, age, gender, breed, type, location, picture) + ) + conn.commit() + return cursor.lastrowid + +def fetch_all_pets(): + """Retrieve all pets from the pets table.""" + with closing(connect_db()) as conn: + cursor = conn.cursor() + cursor.execute("SELECT * FROM pets") + return cursor.fetchall() + +def fetch_user_by_id(user_id): + """Retrieve a user by their user_id.""" + with closing(connect_db()) as conn: + cursor = conn.cursor() + cursor.execute("SELECT * FROM users WHERE user_id = ?", (user_id,)) + return cursor.fetchone() diff --git a/Backend/generateData.py b/Backend/generateData.py new file mode 100644 index 0000000..4df7a35 --- /dev/null +++ b/Backend/generateData.py @@ -0,0 +1,77 @@ +'''ONLY USE THIS IF THE DATABASE IS EMPTY. IT'S THE INIT CODE''' + +import sqlite3 +from contextlib import closing +import os + + + +def populate_test_data(db_path): + '''THE ACTUAL FUNCITON''' + + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + + + + # Create tables + cursor.executescript(''' + CREATE TABLE IF NOT EXISTS users ( + user_id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + age INTEGER, + marital_status TEXT, + pet_preference TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); + + CREATE TABLE IF NOT EXISTS pets ( + pet_id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + age INTEGER, + gender TEXT CHECK(gender IN ('male', 'female')), + breed TEXT, + type TEXT CHECK(type IN ('dog', 'cat')), + location TEXT, + photo_path TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); + + CREATE TABLE IF NOT EXISTS user_tests ( + test_id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER, + question TEXT, + answer TEXT, + FOREIGN KEY (user_id) REFERENCES users(user_id) + ); + ''') #ur welcome :) + + + # Insert sample users + cursor.executescript(''' + INSERT INTO users (name, age, marital_status, pet_preference) VALUES + ('Ben Ten', 28, 'single', 'dog'), + ('Spongebob Smith', 35, 'married', 'cat'), + ('Dipper Pines', 25, 'married', 'any'), + ('Emilia Kirej', 20, 'married', 'dog'); + + ''') + + # Insert sample pets + cursor.executescript(''' + INSERT INTO pets (name, age, gender, breed, type, location, photo_path) VALUES + ('Gunner', 9, 'male', 'Golden Retriever', 'dog', 'Myrtle Beach, SC', 'images/gunner.jpg'), + ('Lizzie Izzie', 5, 'female', 'Donskoy', 'cat', 'Milford, CT', 'images/lizzie_izzie.jpg'), + ('Chuck', 1, 'male', 'Corgi', 'dog', 'Orlando, FL', 'images/chuck.jpg'), + ('Monster', 5, 'female', 'Maine Coon', 'cat', 'Houston, TX', 'images/monster.jpg'); + ''') + + conn.commit() + conn.close() + + + + +#populate_test_data('/home/sus98/2102/proj/cse2102-fall24-Team51/Backend/testData.db') + + diff --git a/Backend/images/Chuck.jpg b/Backend/images/Chuck.jpg new file mode 100644 index 0000000..0c9dedc Binary files /dev/null and b/Backend/images/Chuck.jpg differ diff --git a/Backend/images/gunner.jpg b/Backend/images/gunner.jpg new file mode 100644 index 0000000..fd5455d Binary files /dev/null and b/Backend/images/gunner.jpg differ diff --git a/Backend/images/lizzie_izzie.jpg b/Backend/images/lizzie_izzie.jpg new file mode 100644 index 0000000..68ae6d3 Binary files /dev/null and b/Backend/images/lizzie_izzie.jpg differ diff --git a/Backend/images/monster.jpg b/Backend/images/monster.jpg new file mode 100644 index 0000000..155d4c3 Binary files /dev/null and b/Backend/images/monster.jpg differ diff --git a/Backend/requirements.txt b/Backend/requirements.txt new file mode 100644 index 0000000..5eeda4f --- /dev/null +++ b/Backend/requirements.txt @@ -0,0 +1,8 @@ +Flask==2.0.3 +requests==2.26.0 +pandas==1.3.4 +pytest==7.2.1 +flask_cors==3.0.10 +#Werkzeug==2.1.3 +#pip freeze +