-
Notifications
You must be signed in to change notification settings - Fork 425
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
Sphinx + Phoenix - Sarah K., Charday N., & Priyanka K. #66
base: main
Are you sure you want to change the base?
Changes from 2 commits
034283a
11b0eab
70f0a3a
0e7c2a9
db19c66
2198141
7ac8d4d
517a1e2
9c4e80d
babd837
458915d
ac86dfe
7b738e0
dd74ea2
60bea74
cf0a16b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
from flask import Flask | ||
from .routes import planets_bp | ||
|
||
|
||
def create_app(test_config=None): | ||
app = Flask(__name__) | ||
|
||
app.register_blueprint(planets_bp) | ||
|
||
return app |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though we only have one model, planets, we'll still want a directory called "models" and this file would nest under that directory. Soon you'll be working with APIs that have multiple models and each model will have specific routes so organizing your project accordingly makes it easier to navigate. Consider making this change before starting on Wave 3! Also, since the class name is singular, I'd expect that the file name would match the class name so |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Planet: | ||
def __init__(self, id, name, description, moons): | ||
self.id = id | ||
self.name = name | ||
self.description = description | ||
self.moons = moons | ||
|
||
def to_dict(self): | ||
return { | ||
"id": self.id, | ||
"name": self.name, | ||
"description": self.description, | ||
"moons": self.moons | ||
} | ||
|
||
planets = [ | ||
Planet(1, "Mercury", "Small, hot, fast", []), | ||
Planet(2, "Venus", "Thick atmosphere", []), | ||
Planet(3, "Earth", "Supports life, very watery", ["Moon"]), | ||
Planet(4, "Mars", "Red planet, biggest volcano", ["Phobos", "Deimos"]) | ||
] |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though we only have one model, planets, we'll still want a directory called "routes" and this file would nest under that directory and should be renamed Consider making this change before starting on Wave 3! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
from flask import Blueprint | ||
from flask import Blueprint, abort, make_response | ||
from .planets import planets | ||
|
||
planets_bp = Blueprint('planets_bp', __name__, url_prefix='/planets') | ||
|
||
@planets_bp.get('') | ||
def get_all_planets(): | ||
return [planet.to_dict() for planet in planets], 200 | ||
|
||
@planets_bp.get('/<planet_id>') | ||
def get_one_planet(planet_id): | ||
planet = validate_planet(planet_id) | ||
|
||
return planet.to_dict(), 200 | ||
|
||
def validate_planet(planet_id): | ||
try: | ||
planet_id = int(planet_id) | ||
except ValueError: | ||
response = {"message": f"planet {planet_id} invalid"} | ||
abort(make_response(response, 400)) | ||
|
||
for planet in planets: | ||
if planet.id == planet_id: | ||
return planet | ||
|
||
response = {"message": f"planet {planet_id} not found"} | ||
abort(make_response(response, 404)) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did dependencies get updated? Do we need to be tracking these changes in the requirements.txt? Maybe i missed something since I wasn't in the round table, but I wouldn't expect needing to make changes to this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We both had some issues installing Flask, but we didn't intend to make any changes to the requirements.txt (and also missed that this was included in the commit). We'll revert the changes with the next push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in
routes.py
first, how would this import statement need to change if your route file was named planet_routes.py and was in a "routes" directory?