Skip to content

Zoisite Luwam Ghebremicael #121

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Conversation

CodeWithLuwam
Copy link

No description provided.

Copy link

@kelsey-steven-ada kelsey-steven-ada left a comment

Choose a reason for hiding this comment

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

Congrats on your first solo project API! I've left some comments and questions across the PR, please take a look when you can and reply here or on Slack if there's anything I can clarify =]

Comment on lines +33 to +37
from .task_routes import tasks_bp
app.register_blueprint(tasks_bp)

from .goal_routes import goals_bp
app.register_blueprint(goals_bp)

Choose a reason for hiding this comment

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

Nice choice to split up the routes into files that are more specific to the resources they work with!

Based on the paths to the files, it looks like the route files are directly in the app folder. Since we have more than one route file, I'd suggest creating a routes directory to organize those route files in.

Comment on lines +5 to +30
def validate_task(id):
try:
id = int(id)
except:
abort(make_response({"message": f"Task {id} is invalid"}, 400))

task = Task.query.get(id)

if not task:
abort(make_response({"message": f"Task {id} not found"}, 404))

return task


def validate_goal(id):
try:
id = int(id)
except:
abort(make_response({"message": f"Goal {id} is invalid"}, 400))

goal = Goal.query.get(id)

if not goal:
abort(make_response({"message": f"Goal {id} not found"}, 404))

return goal

Choose a reason for hiding this comment

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

There is a lot of similar code between these functions, how could we D.R.Y. up our code?



def to_json(self):
is_complete = True if self.completed_at else False;

Choose a reason for hiding this comment

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

Great choice to derive the value of is_complete from self.completed_at! We could also use the python bool function here instead of a ternary expression, what could that look like?

Comment on lines +15 to +19
# if request.args.get("sort") == "asc":
# goals = Goal.query.order_by(Goal.title.asc())
# elif request.args.get("sort") == "desc":
# goals = Goal.query.order_by(Goal.title.desc())
# else:

Choose a reason for hiding this comment

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

We want to remove commented code like this before opening PRs and rely on our repo's commit history if we need to look up past code.

Comment on lines +21 to +23
goals_response = []
for goal in goals:
goals_response.append(goal.to_json())

Choose a reason for hiding this comment

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

This would be a great place for a list comprehension:

goals_response = [goal.to_json() for goal in goals]

Are there other places in the project that we fill a list where we could use list comprehensions?

Comment on lines +69 to +70
validated_task = []
[validated_task.append(validate_task(task_id)) for task_id in request_body["task_ids"]]

Choose a reason for hiding this comment

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

This line might not be doing what you intend, line 70 fills validated_task because of the statement validated_task.append(validate_task(task_id)), but it also creates a new list that we don't keep. we could re-write this line something like:

validated_task = [validate_task(task_id) for task_id in request_body["task_ids"]]

This line is a bit long, so we could create a variable to get the task_ids from the request_body:

task_ids = request_body["task_ids"]
validated_task = [validate_task(task_id) for task_id in task_ids]

This feedback around creating a list that we don't end up using by wrapping the line in square brackets applies to line 75 below as well. How might we re-write that line?

db.session.commit()


return make_response({"id" : goal.goal_id, "task_ids":request_body["task_ids"]}), 200

Choose a reason for hiding this comment

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

There are some lines across the files that are a bit long for best practices, how could we split them up?


db.session.commit()

PATH = "https://slack.com/api/chat.postMessage"

Choose a reason for hiding this comment

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

PATH is a local variable of the mark_completed function, so we'd typically see their name lowercased here. We use all caps for constant values, typically when declared where they're accessible across a file or project.

Choose a reason for hiding this comment

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

Overall, really nice use of descriptive names and spacing to make the code easy to read!

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