Skip to content

Pine Ainur and Tirhas#17

Open
tirhas20 wants to merge 13 commits into
Ada-C16:mainfrom
tirhas20:main
Open

Pine Ainur and Tirhas#17
tirhas20 wants to merge 13 commits into
Ada-C16:mainfrom
tirhas20:main

Conversation

@tirhas20
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

Comment thread app/routes.py Outdated

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

Choose a reason for hiding this comment

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

Neat solution!

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

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

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

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:

Comment thread app/routes.py Outdated
print(name)
for planet in planets:
if planet.name == name:
return vars(planet)
Copy link
Copy Markdown

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
Copy Markdown

@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.

Comment thread app/__init__.py Outdated
app = Flask(__name__)

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

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

Comment thread app/models/planet.py
distance_from_sun = db.Column(db.Integer)
radius = db.Column(db.Integer)

def to_dict(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Good helper function

Comment thread app/routes.py
for planet in planets:
solarsystem_response.append(planet.to_dict())

return jsonify(solarsystem_response)
Copy link
Copy Markdown

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 thread app/routes.py
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
Copy link
Copy Markdown

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