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

Pine Ainur and Tirhas #17

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

Pine Ainur and Tirhas #17

wants to merge 13 commits into from

Conversation

tirhas20
Copy link

No description provided.

Copy link

@jbieniosek jbieniosek left a comment

Choose a reason for hiding this comment

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

Great work on this project! This project is green.

app/routes.py Outdated

@solarsystem_bp.route("", methods=["GET"])
def handle_solarsystem():
solarsystem_response =[vars(planet) for planet in planets]

Choose a reason for hiding this comment

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

Neat solution!

app/routes.py Outdated
Comment on lines 38 to 39
else:
return "please enter a valid planet", 404

Choose a reason for hiding this comment

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

This is a great idea, but it doesn't quite work as intended. If the first planet name does not match, this endpoint will return the 404 message, rather than continuing to look for a matching planet. Moving the 404 return outside of the for loop will result in returning the 404 only if the planet is not found by the for loop.

Suggested change
else:
return "please enter a valid planet", 404
return "please enter a valid planet", 404

app/routes.py Outdated
Comment on lines 45 to 46
for planet in planets:
max_distance = max(distances)

Choose a reason for hiding this comment

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

The max_distance is the same for every iteration of the for loop - I recommend moving it outside of the loop to improve the efficiency of the algorithm.

Suggested change
for planet in planets:
max_distance = max(distances)
max_distance = max(distances)
for planet in planets:

app/routes.py Outdated
print(name)
for planet in planets:
if planet.name == name:
return vars(planet)

Choose a reason for hiding this comment

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

I recommend adding jsonify to the return even in the case where the Flask default behavior is doing the same thing. Using jsonify adds a layer of error protection and also makes it clear that json is the intended behavior.

Suggested change
return vars(planet)
return jsonify(vars(planet))

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Nice work Ainur & Tirhas, you hit the learning goals here. Well done, do take some time to review Query params and tests when you get to them in Task List. Those are likely to be the tricky parts on that project.

app/__init__.py Outdated

def create_app(test_config=None):
app = Flask(__name__)

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://postgres:postgres@localhost:5432/solarsystem_db'

Choose a reason for hiding this comment

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

This is fine here, but in the TaskList project you should make the connection string come from an env variable

distance_from_sun = db.Column(db.Integer)
radius = db.Column(db.Integer)

def to_dict(self):

Choose a reason for hiding this comment

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

👍 Good helper function

for planet in planets:
solarsystem_response.append(planet.to_dict())

return jsonify(solarsystem_response)

Choose a reason for hiding this comment

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

For readability I suggest using response codes, even for 200s

Suggested change
return jsonify(solarsystem_response)
return jsonify(solarsystem_response) , 200

Comment on lines +34 to +40
if 'name' not in request_data or 'surface_area' not in request_data or 'orbital_period' not in request_data \
or 'distance_from_sun' not in request_data or 'radius' not in request_data:
return jsonify({'message': "missing data"}),400
if type(request_data['name']) != str or type(request_data['surface_area']) != int or\
type(request_data['orbital_period']) != int or type(request_data['distance_from_sun']) != int\
or type(request_data['radius']) != int :
return jsonify({'message': "Unsupported data type"}),400

Choose a reason for hiding this comment

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

This might make a good helper function.

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.

4 participants