Skip to content
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

Philomena Kelly - Sharks #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Philomena-Kelly
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, Philomena! One thing to consider is staying consistent as you can with your route responses. Sometimes you send through just a dictionary, sometimes you jsonify the dictionary, sometimes you bring in make_response, etc.

Double check your routes so that they are formatted consistently and that they have predictable behavior.

completed_at = db.Column(db.DateTime, nullable=True)
is_complete = False
goal_id = db.Column(db.Integer, db.ForeignKey('goal.goal_id'))
goal = db.relationship("Goal", back_populates="tasks")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job! If you are curious, check out backref attribute in SQLAlchemy to save you a line of code here!

https://docs.sqlalchemy.org/en/14/orm/backref.html

Comment on lines +28 to +29
def written_out(cls):
return "task"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would make for a good @staticmethod over a @classmethod

Suggested change
def written_out(cls):
return "task"
@staticmethod
def written_out():
return "task"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also is this used anywhere? I couldn't find any files where this method was called? If that's the case, let's get rid of it

Comment on lines +12 to +13
goals_bp = Blueprint("goals_bp", __name__, url_prefix="/goals")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

often in industry we will separate out routes based on models into their own file to help balance the workload on files, as well as making sure teammates don't step on each other's toes when coding

response = { "goal": new_goal.to_json()}

return make_response(response, 201)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are staying super consistent with your return statements with make_response(jsonify(), so let's bring in jsonify here as well

Comment on lines +23 to +25
task = validate_object("task", task)
task.goal_id = goal_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would make a good instance method

Comment on lines +210 to +214
PARAMS = {'text' : f"Someone just completed the task {task.title}",
'channel' : 'task-notifications'}
HEADERS = {'Authorization' : f'Bearer {os.environ.get("TASKLIST_BOT_KEY")}'}
r = requests.get(url = URL, params = PARAMS, headers = HEADERS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would make a good helper function

Comment on lines +233 to +236



Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +225 to +226
task.completed_at = None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could make this into an instance method

response = { "task": task.to_json()}

return response, 200

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep consistency with your return statements here, so that users can use your API in a predictable fashion

Suggested change
return response, 200
return make_response(jsonify(response), 200)

Comment on lines +238 to +253

try:
object_id = int(object_id)
except:
abort(make_response({"message":f"{object_type} {object_id} invalid"}, 400))

if object_type == "task":
item = Task.query.get(object_id)
elif object_type == "goal":
item = Goal.query.get(object_id)

if not item:
abort(make_response({"message":f"{object_type} {object_id} not found"}, 404))

return item

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this into its own file for helper functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants