-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task List Project #14
base: master
Are you sure you want to change the base?
Conversation
def create_app(test_config=None): | ||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
|
||
if test_config is None: | ||
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( | ||
"SQLALCHEMY_DATABASE_URI") | ||
else: | ||
app.config["TESTING"] = True | ||
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( | ||
"SQLALCHEMY_TEST_DATABASE_URI") | ||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres@localhost:5432/task_list_api_development' | ||
|
||
db.init_app(app) | ||
migrate.init_app(app, db) | ||
|
||
# Import models here for Alembic setup | ||
from app.models.task import Task | ||
from app.models.goal import Goal | ||
|
||
db.init_app(app) | ||
migrate.init_app(app, db) | ||
from .routes import task_list_api_bp | ||
app.register_blueprint(task_list_api_bp) | ||
|
||
# Register Blueprints here | ||
from .routes import goals_bp | ||
app.register_blueprint(goals_bp) | ||
|
||
return app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should go back to how you previously had it
if test_config is None: app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( "SQLALCHEMY_DATABASE_URI") else: app.config["TESTING"] = True app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( "SQLALCHEMY_TEST_DATABASE_URI")
# from flask import Flask | ||
# from flask_sqlalchemy import SQLAlchemy | ||
# from flask_migrate import Migrate | ||
|
||
# db = SQLAlchemy() | ||
# migrate = Migrate() | ||
|
||
|
||
# def create_app(test_config=None): | ||
# app = Flask(__name__) | ||
|
||
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
# app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres@localhost:5432/task_list_api_development' | ||
|
||
# db.init_app(app) | ||
# migrate.init_app(app, db) | ||
|
||
# from app.models.task import Task | ||
|
||
# return app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code
task_id = db.Column(db.Integer, primary_key=True) | ||
id = db.Column(db.Integer, primary_key=True, autoincrement=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good change!
goal_id = db.Column(db.Integer, primary_key=True) | ||
id = db.Column(db.Integer, primary_key=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good change!
|
||
|
||
@task_list_api_bp.route("", methods=["GET", "POST"]) | ||
def tasks(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because GET and POST are not using the same code you could consider created two different methods to handle GET and POST. For example, get_tasks
and create_task
tasks = Task.query.all() | ||
|
||
tasks_response = [] | ||
# is_complete = task.completed_at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this commented code
"task": { | ||
"id": task.id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": task.completed_at | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider creating a helper function to add this. This makes your code more readable.
|
||
|
||
@goals_bp.route("", methods=["GET", "POST"]) | ||
def handle_goals(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also breaking up this GET and POST for goals into two helper functions get_goals
and create_goal
The tests were passing when I was submitting them but in the end, some of the first tests start to fail and I also didn't have enough time to deploy them before submitting the project.