-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit for the backend. Database should be ignored
- Loading branch information
Showing
9 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SQLite database | ||
/Backend/testData.db | ||
*.db | ||
|
||
#Log files for some reason lol | ||
*.log | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|