-
Notifications
You must be signed in to change notification settings - Fork 71
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
Rock-Leilani Allen #53
base: master
Are you sure you want to change the base?
Conversation
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.
Great job Leilani! You hit all the learning goals for this project. I'm glad you're finding the value in helper methods/functions and I challenge you to use them in future projects. I provided some refactoring tips, especially about unneeded imports.
Overall, great job and keep up the hard work 👍 🔥 ✨
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( | ||
"SQLALCHEMY_TEST_DATABASE_URI") | ||
app.config['JSON_SORT_KEYS']=False |
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.
Nice! Flask automatically organizes keys alphabetically so adding this line ensures json are kept in the order you provided. This isn't actually recommended by Flask for performance reasons, but it is a feature.
More info can be found in documentation: https://flask.palletsprojects.com/en/2.0.x/config/#JSON_SORT_KEYS
I also found this stackoverflow answer helpful.
from .routes import tasks_bp | ||
app.register_blueprint(tasks_bp) | ||
|
||
from .routes import goals_bp | ||
app.register_blueprint(goals_bp) |
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.
You can reduce redundancy here by combining imports like so:
from .routes import tasks_bp | |
app.register_blueprint(tasks_bp) | |
from .routes import goals_bp | |
app.register_blueprint(goals_bp) | |
from .routes import tasks_bp, goals_bp | |
app.register_blueprint(tasks_bp) | |
app.register_blueprint(goals_bp) |
@@ -1,6 +1,13 @@ | |||
from flask import current_app | |||
from app import db | |||
from sqlalchemy import Table, Column, Integer, ForeignKey |
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.
Hm... I'm not sure you needed these imports as Column
, Integer
, and ForeignKey
should be coming from your own instance of SqlAlchemy called db
.
class Goal(db.Model): | ||
goal_id = db.Column(db.Integer, primary_key=True) | ||
title = db.Column(db.String) | ||
#relating to tasks database | ||
tasks = db.relationship('Task', backref='goal', lazy=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.
Great job setting up the one-to-many relationship 😄
complete = False | ||
else: | ||
complete = True | ||
return complete |
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.
Nice helper method!
|
||
|
||
|
||
return jsonify({"task": task.display_tasks()}), 201 |
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 job! 👍
|
||
task = Task.query.get(task_id) | ||
|
||
if task is None: |
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.
Another way to write these is conditional is:
if task is None: | |
if not task: |
|
||
task.completed_at = datetime.now() | ||
db.session.commit() | ||
slack_message(task) |
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.
Nice helper function Leilani 👍 🔥
"id": goal.goal_id, | ||
"title": goal.title |
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.
💡 Refactor tip: notice how you return the same goal dictionary for GET and POST? I think a helper method to return a dictionary would come in handy here.
"title": goal.title, | ||
"tasks": tasks | ||
} , 200) | ||
|
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.
Nice! This looks great Leilani!
No description provided.