From 4cd69298c949e2fc44aab0587336c39d0721810e Mon Sep 17 00:00:00 2001 From: Prince D Rusweka Rwabongoya Date: Wed, 23 Apr 2025 18:37:57 -0400 Subject: [PATCH] Update main.py --- backend/main.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/backend/main.py b/backend/main.py index e4c21af..2f52d4e 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,11 +1,10 @@ """This is the main Flask application for the pet adoption API.""" - import sqlite3 import os - from flask import Flask, jsonify, request from flasgger import Swagger +from utils import create_tables # Initialize Flask app app = Flask(__name__) @@ -27,21 +26,7 @@ def init_db(): """Create tables and add initial data if they don't exist.""" if not os.path.exists(DATABASE): conn = get_db() - cursor = conn.cursor() - - # Create the animals table - cursor.execute(''' - CREATE TABLE IF NOT EXISTS animals ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - species TEXT NOT NULL, - breed TEXT, - age INTEGER, - personality TEXT, - image_path TEXT, - adoption_status TEXT DEFAULT 'Available' - ) - ''') + create_tables(conn) # Insert initial pet data for testing pets = [ @@ -53,7 +38,8 @@ def init_db(): ('Bella', 'Dog', 'Bulldog', 2, 'Gentle', '/images/bella.jpg', 'Available') ] - # Insert data into the animals table + conn = get_db() + cursor = conn.cursor() cursor.executemany(''' INSERT INTO animals (name, species, breed, age, personality, image_path, adoption_status) VALUES (?, ?, ?, ?, ?, ?, ?)