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

Say Zoisite #109

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

Say Zoisite #109

wants to merge 17 commits into from

Conversation

LRyder17
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! There are a couple things I would like to see you revisit if you have time, I'll add more details on those items in Learn. 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 =]


# client = slack.WebClient(token=os.environ['SLACK_TOKEN'])

Choose a reason for hiding this comment

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

I see this commented line duplicated on line 13, we should remove commented code like this and rely on our repo's commit history if we need to look up past code.

Comment on lines +38 to +39
from app.routes.task_routes import tasks_bp
from app.routes.goal_routes import 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.

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.

Comment on lines +7 to +10
sort_by = query_params.get("sort")

if sort_by:
return get_sorted_items_by_params(cls, query_params)

Choose a reason for hiding this comment

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

I would consider separating out the sort into its own function or renaming filter_by_params to reflect that it results in both sorting and filtering.

Comment on lines +12 to +16
if query_params:
query_params = {k.lower(): v.title() for k, v in query_params.items()}
items = cls.query.filter_by(**query_params).all()
else:
items = cls.query.all()

Choose a reason for hiding this comment

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

There's some similar code repeated depending on if we want to sort and filter or only filter. If we want to D.R.Y. up the code, we could get a reference to the class's query object that we keep updating. One possibility might look like:

model_query = cls.query

if query_params:
    query_params = {k.lower(): v.title() for k, v in query_params.items()}
    model_query = model_query.filter_by(**query_params).all()

if sort_by and sort_by == "asc":
    model_query = model_query.order_by(cls.title.asc())
elif sort_by and sort_by == "desc":
    model_query = model_query.order_by(cls.title.desc())

items = model_query.all()

Comment on lines +80 to +86
task_data.append({
"id": task.task_id,
"goal_id": goal.goal_id,
"title": task.title,
"description": task.description,
"is_complete": task.is_complete
})

Choose a reason for hiding this comment

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

Could we use the task's task_to_dict function?

"description": task.description,
"is_complete": task.is_complete
})
task_data

Choose a reason for hiding this comment

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

We should remove this line since we aren't performing an operation.

Choose a reason for hiding this comment

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

Great looking code across the route files as far as line length, clear variable names, spacing, and overall readability 😊

Comment on lines +1 to +8
# import os
# from pathlib import Path
# from dotenv import load_dotenv

# env_path = Path('.') / '.env'
# load_dotenv(dotenv_path=env_path)

# token = os.environ.get('SLACK_TOKEN')

Choose a reason for hiding this comment

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

Was this file intended to be committed?

Comment on lines +98 to +118
# @pytest.mark.skip(reason="No way to test this feature yet")
def test_get_task_includes_goal_id(client, one_task_belongs_to_one_goal):
response = client.get("/tasks/1")
response = client.get("goals/1/tasks")
response_body = response.get_json()

assert response.status_code == 200
assert "task" in response_body
assert "goal_id" in response_body["task"]
assert "tasks" in response_body
assert "goal_id" in response_body["tasks"][0]
assert response_body == {
"task": {
"id": 1,
"goal_id": 1,
"title": "Go on my daily walk 🏞",
"description": "Notice something new every day",
"is_complete": False
}
}
"id": 1,
"title": "Build a habit of going outside daily",
"tasks": [
{
"id": 1,
"goal_id": 1,
"title": "Go on my daily walk 🏞",
"description": "Notice something new every day",
"is_complete": False
}
]
}

Choose a reason for hiding this comment

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

The original test does not pass. We should use the tests to guide our development - by changing the tests to meet our code, we change the specification of the project. What would need to change about our models or routes to make the original test case pass?

@LRyder17
Copy link
Author

LRyder17 commented May 19, 2023 via email

@kelsey-steven-ada
Copy link

Awesome, thanks for the link!

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