Conversation
audreyandoy
left a comment
There was a problem hiding this comment.
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_TRACK_MODIFICATIONS"] = False | ||
| 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.
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.
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.
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.
| 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.
Great job setting up the one-to-many relationship 😄
| complete = False | ||
| else: | ||
| complete = True | ||
| return complete |
|
|
||
|
|
||
|
|
||
| return jsonify({"task": task.display_tasks()}), 201 |
|
|
||
| task = Task.query.get(task_id) | ||
|
|
||
| if task is None: |
There was a problem hiding this comment.
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) |
| "id": goal.goal_id, | ||
| "title": goal.title |
There was a problem hiding this comment.
💡 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) | ||
|
|
No description provided.