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 diff --git a/backend/flaskr/__init__.py b/backend/flaskr/__init__.py index eef4a19d8..d991c6bd5 100644 --- a/backend/flaskr/__init__.py +++ b/backend/flaskr/__init__.py @@ -1,10 +1,8 @@ -import os from flask import Flask, request, abort, jsonify -from flask_sqlalchemy import SQLAlchemy 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 +19,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 diff --git a/backend/models.py b/backend/models.py index 3c5f56ed1..7647a6fbf 100644 --- a/backend/models.py +++ b/backend/models.py @@ -1,10 +1,10 @@ -import os -from sqlalchemy import Column, String, Integer, create_engine +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() @@ -13,24 +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) - db.create_all() """ 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 @@ -56,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 @@ -75,4 +71,4 @@ def format(self): return { 'id': self.id, 'type': self.type - } + } 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 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/).