Skip to content

Conversation

@sanakakadan22
Copy link

No description provided.

Comment on lines 57 to 66
try:
id = int(id)
except:
return abort(make_response({"message": f"planet {id} is invalid"}, 400))

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

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

Choose a reason for hiding this comment

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

LGTM 👍🏽


#Get all planets
@planet_bp.route("", methods=["GET"])
def read_all_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.

Since you put your routes in planet_routs.py in routes directory, you can even call this read_all() since we know that all the routes in planet_routes.py are related to the Planet class.

for planet in planets:
planets_response.append(planet.to_json())

return jsonify(planets_response)

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(planets_response), 200

Comment on lines +23 to +35
def update(self, request_body):
self.title = request_body["title"]
self.description = request_body["description"]
self.moons = request_body["moons"]

@classmethod
def create(cls,request_body):
new_planet = cls(
title=request_body["title"],
description=request_body["description"],
moons = request_body["moons"]
)
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 pulling these two methods into the model Planet to keep your routes short and sweet.

This comment applies to your create() and update() methods:

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 moons, then line 33 would throw KeyError that it couldn't find moons.

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 moons. Something to think about for Task List.

from flask import Blueprint, jsonify, make_response, abort, request
from app.models.planet import Planet

def validate_planet(id):

Choose a reason for hiding this comment

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

In the future, you might need to make 'helper.py' more specific. Think about Task List, you have Goal and Task, you may need helpers for each. If you refactor helper methods into a helper file then you could have goal_helper.py and task_helper.py

@@ -0,0 +1,89 @@
from flask import jsonify, make_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