diff --git a/api/api.py b/api/api.py index 5b1e268..e27790a 100644 --- a/api/api.py +++ b/api/api.py @@ -3,7 +3,6 @@ from .users.user_endpoint import UserEndpoint api = Blueprint('api', __name__, url_prefix='/api') - @api.route('/home', methods=['GET']) def api_home(): response = {"message": "home page"} diff --git a/app.py b/app.py deleted file mode 100644 index 10fb0ea..0000000 --- a/app.py +++ /dev/null @@ -1,58 +0,0 @@ -import os - -from flask import Flask - -# ! SQLAlchemy > Marshmallow - these must be imported in this order -from flask_sqlalchemy import SQLAlchemy -from flask_marshmallow import Marshmallow - -from flask_migrate import Migrate - -from flask_bcrypt import Bcrypt -from flask_cors import CORS - -app = Flask(__name__) -CORS(app) - -# config database -app_settings = os.getenv( - 'APP_SETTINGS', - 'config.DevelopmentConfig' -) - -app.config.from_object(app_settings) - -# init bcrypt -bcrypt = Bcrypt(app) - -# init database -db = SQLAlchemy(app) - -# init marshmallow -ma = Marshmallow(app) - -# init all db models -import models - -migrate = Migrate(app, db) - - -# dev server -DEBUG = True -PORT = 8000 - -# Routes - -@app.route('/') -def hello_world(): - return 'Hello World' - -# Blue prints -from api.api import api -from auth.auth import auth - -app.register_blueprint(api) -app.register_blueprint(auth) - -if __name__ == '__main__': - app.run(debug=DEBUG, port=PORT) \ No newline at end of file diff --git a/auth/auth.py b/auth/auth.py index 94e1723..c1de946 100644 --- a/auth/auth.py +++ b/auth/auth.py @@ -1,6 +1,6 @@ from flask import Blueprint, request, jsonify, session -import models - +from models import User +print(User) auth = Blueprint('auth', __name__, url_prefix='/auth') @auth.route('/signup', methods=['POST']) diff --git a/__init__.py b/config/__init__.py similarity index 100% rename from __init__.py rename to config/__init__.py diff --git a/config.py b/config/config.py similarity index 97% rename from config.py rename to config/config.py index 0b3f00f..55c5173 100644 --- a/config.py +++ b/config/config.py @@ -14,6 +14,7 @@ class DevelopmentConfig(BaseConfig): DEBUG = True BCRYPT_LOG_ROUNDS = 4 SQLALCHEMY_DATABASE_URI = DATABASE + PORT = 8000 class TestingConfig(BaseConfig): diff --git a/config/models_mount.py b/config/models_mount.py new file mode 100644 index 0000000..fa36978 --- /dev/null +++ b/config/models_mount.py @@ -0,0 +1,7 @@ +if __name__ == '__main__': + from ..models.User import User + from ..models.GameRoom import GameRoom + from ..models.TimeSettings import TimeSettings + from ..models.Game import Game + from ..models.Move import Move + from ..models.Message import Message \ No newline at end of file diff --git a/database.py b/database.py new file mode 100644 index 0000000..c43b153 --- /dev/null +++ b/database.py @@ -0,0 +1,15 @@ + +# ! SQLAlchemy > Marshmallow - these must be imported in this order +from flask_sqlalchemy import SQLAlchemy +from flask_marshmallow import Marshmallow +from flask_bcrypt import Bcrypt + +# init bcrypt +def bcrypt(app): + Bcrypt(app) + +# init database +db = SQLAlchemy() + +# init marshmallow +ma = Marshmallow() diff --git a/models.py b/models.py deleted file mode 100644 index 5fa00f1..0000000 --- a/models.py +++ /dev/null @@ -1,6 +0,0 @@ -from models.User import User -from models.GameRoom import GameRoom -from models.TimeSettings import TimeSettings -from models.Game import Game -from models.Move import Move -from models.Message import Message \ No newline at end of file diff --git a/models/User.py b/models/User.py index b71c9c6..a22ff84 100644 --- a/models/User.py +++ b/models/User.py @@ -1,4 +1,4 @@ -from app import db, ma, bcrypt +from database import db, ma, bcrypt import datetime import enum import jwt diff --git a/server.py b/server.py new file mode 100644 index 0000000..c82ac0d --- /dev/null +++ b/server.py @@ -0,0 +1,36 @@ +import os +from database import db, ma, bcrypt + +from flask import Flask + +from flask_migrate import Migrate + +from flask_cors import CORS + +# Blueprints +from api.api import api +from auth.auth import auth + +import config.models_mount + +def create_app(): + app = Flask(__name__) + bcrypt(app) + CORS(app) + app_settings = os.getenv( + 'APP_SETTINGS', + 'config.config.DevelopmentConfig' + ) + + app.config.from_object(app_settings) + db.init_app(app) + ma.init_app(app) + app.register_blueprint(api) + app.register_blueprint(auth) + migrate = Migrate(app, db) + return app + + +if __name__ == '__main__': + app = create_app() + app.run(port=8000, debug=True) \ No newline at end of file