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

nadia sarkissian - zoisite #108

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

nadia sarkissian - zoisite #108

wants to merge 24 commits into from

Conversation

pizzagirl1
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 +36
from .routes.task_routes import tasks_bp
app.register_blueprint(tasks_bp)
from .routes.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!

try:
model_id = int(model_id)
except:
abort(make_response(jsonify({"message":f"{cls.__name__} {model_id} invalid"}), 400))

Choose a reason for hiding this comment

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

To keep code shorter and easier to read, I'd suggest splitting this line up.

Choose a reason for hiding this comment

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

I recommend placing this file in the routes directory to keep it close to the code that uses it.

"id": self.goal_id,
"title": self.title,
}
if tasks:

Choose a reason for hiding this comment

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

Nice use of an extra parameter to make the function more flexible!

"id": self.task_id,
"title": self.title,
"description": self.description,
"is_complete": bool(self.completed_at)

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!

Comment on lines +26 to +27
if "completed_at" not in task_data:
task_data["completed_at"] = None

Choose a reason for hiding this comment

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

Nice conditional to ensure you avoid a KeyError if the user didn't send a completed_at value ^_^

@goals_bp.route("/<goal_id>", methods=["GET"])
def get_one_goal(goal_id):
goal = validate_model(Goal, goal_id)
response = {"goal": goal.to_dict()}

Choose a reason for hiding this comment

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

Great way to add what you need for the response while getting to reuse the to_dict function!

goal = validate_model(Goal, goal_id)
updated_data = request.get_json()

goal.title = updated_data["title"]

Choose a reason for hiding this comment

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

There's some error handling in create_goal that we could use here to alert the user if the request was missing a title key. How could we share the behavior with both functions?

Comment on lines +14 to +23
sort_direction = request.args.get("sort")

if sort_direction == "asc":
tasks = Task.query.order_by(Task.title)
elif sort_direction == "desc":
tasks = Task.query.order_by(Task.title.desc())
else:
tasks = Task.query.all()

results = [task.to_dict() for task in tasks]

Choose a reason for hiding this comment

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

We could simplify the if/else tree a little if we get a reference to the Task.query object first:

task_query = Task.query
sort_direction = request.args.get("sort")

if sort_direction == "asc":
    task_query = task_query.order_by(Task.title.asc())
elif sort_direction == "desc":
    task_query = task_query.order_by(Task.title.desc())

results = [task.to_dict() for task in task_query.all()]

db.session.commit()

url = "https://slack.com/api/chat.postMessage"
SLACK_API_TOKEN = os.environ.get("SLACK_API_TOKEN")

Choose a reason for hiding this comment

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

SLACK_API_TOKEN is a local variable of the complete_one_task 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.

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