-
Notifications
You must be signed in to change notification settings - Fork 71
Rock - Nyckolle L. #52
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
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.
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): |
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.
👍 love to see some helper methods!
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): |
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.
👍
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we aren't using this anywhere, we can get rid of it
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can directly import this from flask
above
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from flask import Blueprint, request, jsonify | |
from flask import Blueprint, request, jsonify, makes_response |
goal = Goal.query.get(goal_id) | ||
|
||
if goal is None: | ||
return make_response("", 404) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we could use get_or_404()
, too!
goal = Goal.query.get(goal_id) | ||
|
||
if goal is None: | ||
return make_response("", 404) |
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.
here we could use get_or_404()
, too!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we could use get_or_404()
, too!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we could use get_or_404()
, too!
No description provided.