-
Notifications
You must be signed in to change notification settings - Fork 128
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
base: main
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.
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 =]
from .routes.task_routes import tasks_bp | ||
app.register_blueprint(tasks_bp) | ||
from .routes.goal_routes import goals_bp | ||
app.register_blueprint(goals_bp) |
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.
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)) |
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.
To keep code shorter and easier to read, I'd suggest splitting this line up.
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.
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: |
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.
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) |
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.
Great choice to derive the value of is_complete
from self.completed_at
!
if "completed_at" not in task_data: | ||
task_data["completed_at"] = None |
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.
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()} |
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.
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"] |
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.
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?
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] |
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 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") |
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.
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.
No description provided.