From b45e6653d05e576e4f7e0b2d3a1f59aea9500881 Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Sun, 3 Nov 2024 17:59:45 -0300 Subject: [PATCH 1/6] Add .env entry to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ec824f4aa..ec21f5e01 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ venv ehthumbs.db Thumbs.db env/ -frontend/node_modules/ \ No newline at end of file +frontend/node_modules/ + +.env \ No newline at end of file From 56f806654e31de9451c6e45db1957b30acc500f8 Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Sun, 3 Nov 2024 17:59:58 -0300 Subject: [PATCH 2/6] Add recommended node version info --- frontend/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/README.md b/frontend/README.md index a3aa782d1..5795bb34c 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -6,6 +6,8 @@ ### Installing Dependencies +Recommended node version: 16x + 1. **Installing Node and NPM** This project depends on Nodejs and Node Package Manager (NPM). Before continuing, you must download and install Node (the download includes NPM) from [https://nodejs.com/en/download](https://nodejs.org/en/download/). From a58c3c517c4e179ecdc6859c776fd018c4ba26b5 Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Sun, 3 Nov 2024 18:08:28 -0300 Subject: [PATCH 3/6] Add db import and create_all execution --- backend/flaskr/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/flaskr/__init__.py b/backend/flaskr/__init__.py index eef4a19d8..940231123 100644 --- a/backend/flaskr/__init__.py +++ b/backend/flaskr/__init__.py @@ -4,7 +4,7 @@ from flask_cors import CORS import random -from models import setup_db, Question, Category +from models import setup_db, Question, Category, db QUESTIONS_PER_PAGE = 10 @@ -21,6 +21,8 @@ def create_app(test_config=None): """ @TODO: Set up CORS. Allow '*' for origins. Delete the sample route after completing the TODOs """ + with app.app_context(): + db.create_all() """ @TODO: Use the after_request decorator to set Access-Control-Allow From d6a6b148adbdfb7c6683fd8187625200aea47c84 Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Sun, 3 Nov 2024 18:09:34 -0300 Subject: [PATCH 4/6] Remove unused import statements --- backend/flaskr/__init__.py | 2 -- backend/models.py | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/flaskr/__init__.py b/backend/flaskr/__init__.py index 940231123..d991c6bd5 100644 --- a/backend/flaskr/__init__.py +++ b/backend/flaskr/__init__.py @@ -1,6 +1,4 @@ -import os from flask import Flask, request, abort, jsonify -from flask_sqlalchemy import SQLAlchemy from flask_cors import CORS import random diff --git a/backend/models.py b/backend/models.py index 3c5f56ed1..032554bb1 100644 --- a/backend/models.py +++ b/backend/models.py @@ -1,5 +1,4 @@ -import os -from sqlalchemy import Column, String, Integer, create_engine +from sqlalchemy import Column, String, Integer from flask_sqlalchemy import SQLAlchemy import json @@ -17,7 +16,6 @@ def setup_db(app, database_path=database_path): app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False db.app = app db.init_app(app) - db.create_all() """ Question From 9e8ba5e44416b6c972281dab2674fc859035f9fb Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Sun, 3 Nov 2024 18:09:48 -0300 Subject: [PATCH 5/6] Adjust boilerplate code --- backend/models.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/models.py b/backend/models.py index 032554bb1..7647a6fbf 100644 --- a/backend/models.py +++ b/backend/models.py @@ -1,9 +1,10 @@ from sqlalchemy import Column, String, Integer from flask_sqlalchemy import SQLAlchemy -import json - database_name = 'trivia' -database_path = 'postgresql://{}/{}'.format('localhost:5432', database_name) +database_user = 'postgres' +database_password = 'password' +database_host = 'localhost:5432' +database_path = f'postgresql://{database_user}:{database_password}@{database_host}/{database_name}' db = SQLAlchemy() @@ -12,23 +13,21 @@ binds a flask application and a SQLAlchemy service """ def setup_db(app, database_path=database_path): - app.config["SQLALCHEMY_DATABASE_URI"] = database_path - app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False - db.app = app + app.config['SQLALCHEMY_DATABASE_URI'] = database_path + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) """ Question - """ class Question(db.Model): __tablename__ = 'questions' id = Column(Integer, primary_key=True) - question = Column(String) - answer = Column(String) - category = Column(String) - difficulty = Column(Integer) + question = Column(String, nullable=False) + answer = Column(String, nullable=False) + category = Column(String, nullable=False) + difficulty = Column(Integer, nullable=False) def __init__(self, question, answer, category, difficulty): self.question = question @@ -54,17 +53,16 @@ def format(self): 'answer': self.answer, 'category': self.category, 'difficulty': self.difficulty - } + } """ Category - """ class Category(db.Model): __tablename__ = 'categories' id = Column(Integer, primary_key=True) - type = Column(String) + type = Column(String, nullable=False) def __init__(self, type): self.type = type @@ -73,4 +71,4 @@ def format(self): return { 'id': self.id, 'type': self.type - } + } From 722db9302ff5b44ff60b3b9c3af3e90521b6a89e Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Sun, 3 Nov 2024 18:10:11 -0300 Subject: [PATCH 6/6] Update dependencies to support Python 3.10 --- backend/requirements.txt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index fdf8b85aa..232f3fcc5 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,14 +1,14 @@ -aniso8601==6.0.0 -Click==7.0 -Flask==1.0.3 -Flask-Cors==3.0.7 -Flask-RESTful==0.3.7 -Flask-SQLAlchemy==2.4.0 -itsdangerous==1.1.0 -Jinja2==2.10.1 -MarkupSafe==1.1.1 -psycopg2-binary==2.8.2 -pytz==2019.1 -six==1.12.0 -SQLAlchemy==1.3.4 -Werkzeug==0.15.5 +aniso8601>=9.0.1 +Click>=8.0.0 +Flask>=2.0.0 +Flask-Cors>=3.0.10 +Flask-RESTful>=0.3.9 +Flask-SQLAlchemy>=2.5.1 +itsdangerous>=2.0.0 +Jinja2>=3.0.0 +MarkupSafe>=2.0.0 +psycopg2-binary>=2.9.0 +pytz>=2021.1 +six>=1.16.0 +SQLAlchemy>=1.4.0 +Werkzeug>=2.0.0