Skip to content

Commit

Permalink
Updated backend and frontend for app deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanueposu committed Jun 2, 2024
1 parent fc2ce0c commit 0fc25df
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 60 deletions.
9 changes: 5 additions & 4 deletions trivia-forge/backend/endpoints/category.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values

load_dotenv()

bp = Blueprint('category', __name__, url_prefix='/categories')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
9 changes: 5 additions & 4 deletions trivia-forge/backend/endpoints/choice.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values

load_dotenv()

bp = Blueprint('choice', __name__, url_prefix='/choices')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
10 changes: 5 additions & 5 deletions trivia-forge/backend/endpoints/game.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values


load_dotenv()

bp = Blueprint('game', __name__, url_prefix='/games')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
2 changes: 1 addition & 1 deletion trivia-forge/backend/endpoints/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

@bp.get('')
def get_home():
return 'Welcome to Trivia Forge!'
return 'Trivia Forge API'
9 changes: 5 additions & 4 deletions trivia-forge/backend/endpoints/question.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values

load_dotenv()

bp = Blueprint('question', __name__, url_prefix='/questions')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
10 changes: 5 additions & 5 deletions trivia-forge/backend/endpoints/user.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from dotenv import load_dotenv
from flask import Blueprint, request, jsonify
from supabase import create_client, Client
from dotenv import dotenv_values


load_dotenv()

bp = Blueprint('user', __name__, url_prefix='/users')

config = dotenv_values("./.env")
url: str = config.get('SUPABASE_URL')
key: str = config.get('SUPABASE_KEY')
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)


Expand Down
10 changes: 8 additions & 2 deletions trivia-forge/backend/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from flask import Flask, request, jsonify
import os
from dotenv import load_dotenv
from flask import Flask
from endpoints import home, user, game, category, question, choice
from flask_cors import CORS

load_dotenv()

host = os.environ.get("HOST")


app = Flask(__name__)
CORS(app)
Expand All @@ -15,4 +21,4 @@


if __name__ == '__main__':
app.run(debug=True)
app.run(host=host, port=5000, debug=True)
37 changes: 36 additions & 1 deletion trivia-forge/backend/poetry.lock

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

2 changes: 2 additions & 0 deletions trivia-forge/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ python = "^3.10"
supabase = "^2.4.3"
flask = "^3.0.3"
python-dotenv = "^1.0.1"
flask-cors = "^4.0.1"
gunicorn = "^22.0.0"


[build-system]
Expand Down
4 changes: 0 additions & 4 deletions trivia-forge/frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import SignUpPage from './pages/signUpPage';
import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';

let signedIn = false;

function App() {
const [count, setCount] = useState(0)
return (

<div className="App">
<BrowserRouter>

Expand All @@ -40,7 +37,6 @@ function App() {
</footer>
</BrowserRouter>
</div>

)
}

Expand Down
6 changes: 3 additions & 3 deletions trivia-forge/frontend/src/components/Navigation.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { Navbar } from "react-bootstrap";
import { Nav, Button} from "react-bootstrap";
import { useNavigate } from "react-router-dom";
import { Link, useNavigate } from "react-router-dom";
import useStore from '../hooks/useStore';


Expand All @@ -20,8 +20,8 @@ function Navigation() {
<Navbar bg="dark" data-bs-theme="dark">
<Nav className="me-auto">
<Nav.Link className="navbar-brand" href="/">Home</Nav.Link>
<Nav.Link href="/triviaGen">Create New Trivia</Nav.Link>
<Nav.Link href="/myTrivia">My Trivia</Nav.Link>
<Nav.Link as={Link} to="/triviaGen">Create New Trivia</Nav.Link>
<Nav.Link as={Link} to="/myTrivia">My Trivia</Nav.Link>
</Nav>

<Nav className="me-2">
Expand Down
1 change: 1 addition & 0 deletions trivia-forge/frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'


ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
Expand Down
2 changes: 1 addition & 1 deletion trivia-forge/frontend/src/pages/homePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Home() {

<Row>
<Col>
<Button variant="primary" onClick={() => navigate('/triviagen')}> <FaPlusCircle /> Create New Game </Button>
<Button variant="primary" onClick={() => navigate('/triviaGen')}> <FaPlusCircle /> Create New Game </Button>
</Col>
</Row>

Expand Down
4 changes: 2 additions & 2 deletions trivia-forge/frontend/src/pages/loginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ function LoginPage() {
<Form onSubmit={handleSubmit} className="form-group">
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email</Form.Label>
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} />
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} required />
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Enter Password" value={password} onChange={(e) => setPassword(e.target.value)} />
<Form.Control type="password" placeholder="Enter Password" value={password} onChange={(e) => setPassword(e.target.value)} required />
</Form.Group>

<p>Not a member? <Link to="/signUp" className="text-decoration-none">Sign Up</Link></p>
Expand Down
2 changes: 0 additions & 2 deletions trivia-forge/frontend/src/pages/myTriviaPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ function MyTriviaPage() {

function handleShowWarning(game) {
setCurrentGame(game);
console.log("current game", currentGame);
setShowWarning(true);
};
function handleWarningClose() {
setShowWarning(false);
};
function handleDelete() {
console.log("deleting game", currentGame);
deleteGame(currentGame).then(res => {
setUserGames(userGames.filter(g => g.id !== currentGame.id));
});
Expand Down
8 changes: 4 additions & 4 deletions trivia-forge/frontend/src/pages/signUpPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ function SignUpPage() {
<Form onSubmit={handleSubmit} className="form-group">
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email address</Form.Label>
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} />
<Form.Control type="email" placeholder="Enter email" value={email} onChange={(e) => setEmail(e.target.value)} required />
<Form.Text className="text-muted">
We'll never share your email with anyone else.
</Form.Text>
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicUsername">
<Form.Label>Username</Form.Label>
<Form.Control type="text" placeholder="Username" value={username} onChange={(e) => setUsername(e.target.value)} />
<Form.Control type="text" placeholder="Username" value={username} onChange={(e) => setUsername(e.target.value)} required />
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" value={password} onChange={(e) => setPassword(e.target.value)} />
<Form.Control type="password" placeholder="Password" value={password} onChange={(e) => setPassword(e.target.value)} required />
</Form.Group>

<Form.Group className="mb-3" controlId="formBasicConfirmPassword">
<Form.Label>Confirm Password</Form.Label>
<Form.Control type="password" placeholder="Confirm Password" value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} />
<Form.Control type="password" placeholder="Confirm Password" value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} required />
</Form.Group>

<div className="d-flex justify-content-center">
Expand Down
9 changes: 0 additions & 9 deletions trivia-forge/frontend/src/pages/triviaGenPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ function TriviaGenPage() {
}
//create a new game and category object and add category to game
//need to change third parameter to current User ID once Users can sign in.
console.log("User:", user);
let game = new Game(Title, Theme, user.id);
console.log("Game:", game);

for (let i = 0; i < categories.length; i++) {
let newCategory = new Category(categories[i].name);
console.log(newCategory.name);
game.addCategory(newCategory);
//parse response from API
let sections = responses[i]; // store trivia questions
Expand Down Expand Up @@ -138,13 +135,7 @@ function TriviaGenPage() {
newCategory.addQuestion(newQuestion);
}
}
console.log("Category Questions:", newCategory.questions);
}
console.log("Game Categories", game.categories);

// Save game to global state and local storage
console.log("test:", game)
// addGame(game);
// state property to pass data as object to new route
navigate('/review', { state: { game: game, page: 'review', isMultipleChoice: isMultipleChoice } });
//console.log(completion.choices[0].message);
Expand Down
3 changes: 0 additions & 3 deletions trivia-forge/frontend/src/pages/triviaReviewPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ function TriviaReviewPage() {
const updateGame = useStore(state => state.updateGame);
const addGame = useStore(state => state.addGame);

console.log(game)

const HandleUpdateGame = async () => {
await UpdateAllForGame(game);
updateGame(game)
Expand All @@ -43,7 +41,6 @@ function TriviaReviewPage() {
}
}


return (
<div>
<title>Trivia Review</title>
Expand Down
3 changes: 0 additions & 3 deletions trivia-forge/frontend/src/services/saveGameService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as api from './triviaForgeApiService';


export const AddAllForGame = async (game) => {
console.log("start game:", game)
try {
// Add the game to the database
//console.log("Adding game:", game);
Expand Down Expand Up @@ -38,9 +37,7 @@ export const AddAllForGame = async (game) => {
}
newGame.categories.push(newCategory);
}

// Return the newly created game
console.log("end game:", newGame)
return newGame;
} catch (error) {
console.error("Error adding game, categories, questions, or choices:", error);
Expand Down
4 changes: 1 addition & 3 deletions trivia-forge/frontend/src/services/triviaForgeApiService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Question } from '../models/question';
import { Category } from '../models/category';
import { Choice } from '../models/choice';

const API_URL = 'http://127.0.0.1:5000';
const API_URL = import.meta.env.VITE_REACT_APP_API_URL;

/* ************************************ User ************************************ */

Expand Down Expand Up @@ -274,10 +274,8 @@ export const editCategory = async (category) => {
/* ************************************ Choice ************************************ */

export const getChoices = async (questions) => {
console.log("questions:", questions)
try {
const response = await axios.get(`${API_URL}/choices`);
console.log("response.data:", response.data)
for (let i = 0; i < response.data.length; i++) {
if (questions[response.data[i].question_id] !== undefined) {
questions[response.data[i].question_id]['choices'].push(response.data[i].text);
Expand Down

0 comments on commit 0fc25df

Please sign in to comment.