Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jbranch3 #5

Closed
wants to merge 7 commits into from
Closed
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
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions trivia-forge/backend/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
from flask import Flask, render_template, json, redirect

app = Flask(__name__)

SUPABASE_URL = os.getenv('SUPABASE_URL')
SUPABASE_ANON_KEY = os.getenv('SUPABASE_ANON_KEY')

@app.route('/')
def home():
return 'Hello, World!'
22 changes: 22 additions & 0 deletions trivia-forge/backend/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#from flask_sqlalchemy import SQLAlchemy
from flask import Flask
#from flask_cors import CORS
from supabase import create_client, Client
#from sqlalchemy.orm import sessionmaker
from dotenv import dotenv_values

def create_app():

app = Flask(__name__)
config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
#print("url:",url)
key: str = config.get('SUPABASE_KEY')
#print("key:",key)
supabase: Client = create_client(url, key)
app.config['Client'] = supabase
return app


if __name__ == '__main__':
create_app()
46 changes: 46 additions & 0 deletions trivia-forge/backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from flask import Flask, request, jsonify
from config import create_app
from dotenv import load_dotenv

app = create_app()

def test_supabase_connection():
try:
# Replace 'your_table' with an actual table name to test fetching data
supabase = app.config['Client'] # Ensure this is consistent across your app
data = supabase.table("Users").select("*").execute()
if data:
print("Data fetched successfully:", data.data)
return True, "Database connection was successful."

print("Failed to fetch data:", data.error_message)
return False, data.error_message
except Exception as e:
print("An error occurred during the database connection:", e)
return False, str(e)
def serialize_user(user):
"""Convert user dictionary to a JSON serializable format."""
return {
"id": user.get("id"),
"name": user.get("name"),
"email": user.get("email")
# Add more fields as needed based on your database structure
}

@app.route("/users", methods=['GET','POST'])
def get_users():
supabase = app.config['Client']
data = supabase.table("Users").select("*").execute()
users = data.data
# Assuming you have a function to serialize data as JSON
return jsonify([serialize_user(user) for user in users])

@app.route("/test", methods=['GET'])
def test():
success, message = test_supabase_connection()
return jsonify({"success": success, "message": message})



if __name__ == '__main__':
app.run(debug=True)
1 change: 1 addition & 0 deletions trivia-forge/backend/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading