Open
Conversation
spitsfire
reviewed
May 25, 2021
spitsfire
left a comment
There was a problem hiding this comment.
Heck yeah! Good job, Nyckolle! A couple things you could consider for future projects:
- For most of the request methods, you separated them out and gave them their own route decorator and function! Awesome. Think about doing that for the GET and POST methods, too. A function should do one thing and one thing only in practice.
- Try and make your return statements consistent. Everything can be returned using
jsonify(), a dictionary, ormake_response(). Any of these options work, some return "extra" headers and data we may/may not need, but it's good to pick just one. That way your endpoints will have consistency when making tests or being read by others!
| title = db.Column(db.String) | ||
| tasks = db.relationship('Task', backref='goaltask', lazy=True) | ||
|
|
||
| def goal_json(self): |
| goaltask_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'), nullable=True) | ||
|
|
||
| # creates a dictionary of key-value pairs describing the given task | ||
| def to_json(self): |
| @@ -1,2 +1,328 @@ | |||
| from flask import Blueprint | |||
| from flask import Blueprint, request, jsonify | |||
| from werkzeug.wrappers import PlainRequest | |||
There was a problem hiding this comment.
since we aren't using this anywhere, we can get rid of it
Suggested change
| from werkzeug.wrappers import PlainRequest |
| from flask import Blueprint, request, jsonify | ||
| from werkzeug.wrappers import PlainRequest | ||
| from app import db | ||
| from flask.helpers import make_response |
There was a problem hiding this comment.
we can directly import this from flask above
Suggested change
| from flask.helpers import make_response |
| @@ -1,2 +1,328 @@ | |||
| from flask import Blueprint | |||
| from flask import Blueprint, request, jsonify | |||
There was a problem hiding this comment.
Suggested change
| from flask import Blueprint, request, jsonify | |
| from flask import Blueprint, request, jsonify, makes_response |
Comment on lines
+234
to
+237
| goal = Goal.query.get(goal_id) | ||
|
|
||
| if goal is None: | ||
| return make_response("", 404) |
There was a problem hiding this comment.
here we could use get_or_404(), too!
| @goals_bp.route("/<goal_id>", methods=["PUT"], strict_slashes=False) | ||
| def update_goal(goal_id): | ||
|
|
||
| goal = Goal.query.get(goal_id) |
There was a problem hiding this comment.
here we could use get_or_404(), too!
Comment on lines
+264
to
+267
| goal = Goal.query.get(goal_id) | ||
|
|
||
| if goal is None: | ||
| return make_response("", 404) |
There was a problem hiding this comment.
here we could use get_or_404(), too!
Comment on lines
+282
to
+286
| goal = Goal.query.get(goal_id) | ||
|
|
||
| # if no goal with the provided goal_id, returns a 404 error | ||
| if not goal: | ||
| return make_response("", 404) |
There was a problem hiding this comment.
here we could use get_or_404(), too!
Comment on lines
+305
to
+311
| goal = Goal.query.get(goal_id) | ||
| # sets task variable equal to the task with the corresponding goal (in foreignkey column) | ||
| task = Task.query.get(goal_id) | ||
|
|
||
| # if goal doesn't exist, return a 404 error | ||
| if not goal: | ||
| return make_response("", 404) |
There was a problem hiding this comment.
here we could use get_or_404(), too!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.