Skip to content

Commit

Permalink
Merge pull request #10 from emmanueposu/jbranch3
Browse files Browse the repository at this point in the history
Jbranch3
  • Loading branch information
demuthsa authored Apr 26, 2024
2 parents f74ab5d + a351c09 commit 2946a6f
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 27 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on: [push, pull_request]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with Unittest
run: |
python tests.py
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.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2946a6f

Please sign in to comment.