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

Sharks - Morgan B. and Huma H. #21

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

Conversation

Morfiend
Copy link

No description provided.

app/routes.py Outdated
Comment on lines 27 to 36
try:
id = int(id)
except:
abort(make_response({"message": f"Planet {id} is not valid"}, 400))

for planet in planets:
if planet.id == id:
return planet

return abort(make_response({"message": f"Planet {id} not found"}, 404))

Choose a reason for hiding this comment

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

LGTM 👍🏽

return abort(make_response({"message": f"Planet {id} not found"}, 404))

@planets_bp.route("", methods=["GET"])
def get_planets():

Choose a reason for hiding this comment

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

Nice job naming the method to describe what this route does.

In the future, when you split your routes up into distinct route files (cat_routes.py and dog_routes.py for example in a routes directory) then you could have method names like get_all() and get_one() since we know that all the routes in cat_routes.py are related to the Cat class.

app/routes.py Outdated
for planet in planets:
planet_response_body.append(planet.to_json())

return jsonify(planet_response_body)

Choose a reason for hiding this comment

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

Adding 200 status code adds clarity even though it happens by default

return jsonify(planet_response_body), 200

app/routes.py Outdated
def read_one_planet(planet_id):
planet = validate_planet(planet_id)

return jsonify(planet.to_json())

Choose a reason for hiding this comment

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

Same comment as above, you can return status code 200 here

Comment on lines +23 to +29
def create(cls, req_body):
new_planet = cls(
name=req_body["name"],
description=req_body["description"],
moon_count=req_body["moon_count"]
)
return new_planet

Choose a reason for hiding this comment

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

Nice work refactoring this into a class method so that your route stays short. How would you add in validation to make sure that all the required fields are sent in the request to your server?

For example, if someone sent a POST request but left off moon_count, then line 27 would throw KeyError that it couldn't find moon_count.

it would be nice to handle the error and return a message so that the client knows their request was invalid and they need to include moon_count. Something to think about for Task List.

Comment on lines +17 to +20
def update(self, req_body):
self.name = req_body["name"]
self.description = req_body["description"]
self.moon_count = req_body["moon_count"]

Choose a reason for hiding this comment

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

Same thought here about validating the PUT request fields that your server needs to handle as with POST. How can you validate and handle the KeyError if a field is not present in the request?

@@ -0,0 +1,39 @@
import pytest

Choose a reason for hiding this comment

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

Looks good!

@@ -0,0 +1,65 @@
from urllib import response

Choose a reason for hiding this comment

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

These tests look good to me!

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.

3 participants