Skip to content

ns-task-list-api #39

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 9 commits into
base: main
Choose a base branch
from
Open

ns-task-list-api #39

wants to merge 9 commits into from

Conversation

natsen1004
Copy link

No description provided.

Copy link

@apradoada apradoada left a comment

Choose a reason for hiding this comment

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

YELLOW - No need to make changes unless you would like to! It is receiving a Yellow because two of the tests are not passing and could benefit from refactoring.

Overall, this is a good API that mostly works, but could use some refining. A few areas to focus on:

  1. When it comes to error handling, you have a function that does most of it for you (validate_model). After using validate_model however, you often included the same error handling that had already been done. Make sure you aren't overdoing it in the realm of error handling!

  2. You've got some really great helper functions and class functions that you use in some cases and not in others. This includes functions like the to_dict or the from_dict or others. If you are writing these functions, make sure you are using them! There were several places where you could have condensed some code with them.

  3. In general, make sure you are clear about what is happening in each route. There were times where certain routes felt overfilled and certain processes were being repeated. Don't be afraid to go through and find places where you can remove redundant code!

Overall, well done, Natalie!

Comment on lines +3 to +4
from .routes.task_routes import bp as tasks_bp
from .routes.goal_routes import bp as goals_bp

Choose a reason for hiding this comment

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

Great use of aliasing here!


return app

Choose a reason for hiding this comment

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

The rest of your configuration and blueprint registration looks good!

Comment on lines 6 to +8
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str]
tasks: Mapped[list["Task"]] = relationship("Task", back_populates="goal")

Choose a reason for hiding this comment

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

This model looks good! Nice one-to-many mapping!


class Goal(db.Model):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
title: Mapped[str]
tasks: Mapped[list["Task"]] = relationship("Task", back_populates="goal")
def to_dict(self):

Choose a reason for hiding this comment

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

Small nitpick here, but make sure you add some space before your functions!

"id": self.id,
"title": self.title
}
@classmethod

Choose a reason for hiding this comment

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

Same thing here, some whitespace can drastically increase readability!


tasks_response = [task.to_dict() for task in tasks]
return tasks_response, 200

Choose a reason for hiding this comment

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

Perfect!

}

return task_response, 200

Choose a reason for hiding this comment

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

Perfect!

Comment on lines +59 to +60
abort(make_response({"message": f"task_id {task_id} not found"}, 404))

Choose a reason for hiding this comment

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

This should be caught by validate_model

Comment on lines +79 to +92
db.session.commit()

url = "https://slack.com/api/chat.postMessage"
slack_token = os.environ.get("SLACK_BOT_TOKEN")
headers = {
"Authorization": f"Bearer {slack_token}",
"Content-Type": "application/json"
}
request_body = {
"channel": "C07US894WRL",
"text": f"Someone just completed the task {task.title}"
}
response = requests.post(url, json=request_body, headers=headers)

Choose a reason for hiding this comment

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

It couldn't hurt to move this to a helper function!

Comment on lines +113 to +114
abort(make_response({"message": f"task_id {task_id} not found"}, 404))

Choose a reason for hiding this comment

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

Validate model will already take care of this!

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