-
Notifications
You must be signed in to change notification settings - Fork 36
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
Cedar - Jacy & Kit #15
base: main
Are you sure you want to change the base?
Conversation
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.
🎉 Nice work!
app/routes.py
Outdated
planets_response = [] | ||
|
||
for planet in PLANETS: | ||
planets_response.append(vars(planet)) |
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.
nice use of vars
!
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.
I just learned that vars
will cause problems when we have a class that connects to our database. We can achieve the same effect by writing a to_json(self)
instance method on the Planet
class.
app/routes.py
Outdated
from flask import Blueprint, jsonify | ||
|
||
|
||
class Planet(): | ||
def __init__(self, id, name, description, xenomorphs=False): | ||
self.id = id | ||
self.name = name | ||
self.description = description | ||
self.xenomorphs = xenomorphs | ||
|
||
|
||
PLANETS = [ | ||
|
||
Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True), | ||
Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True) | ||
|
||
] | ||
|
||
planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | ||
|
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.
Minor note, consider moving extra spaces:
from flask import Blueprint, jsonify | |
class Planet(): | |
def __init__(self, id, name, description, xenomorphs=False): | |
self.id = id | |
self.name = name | |
self.description = description | |
self.xenomorphs = xenomorphs | |
PLANETS = [ | |
Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True), | |
Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True) | |
] | |
planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | |
from flask import Blueprint, jsonify | |
class Planet(): | |
def __init__(self, id, name, description, xenomorphs=False): | |
self.id = id | |
self.name = name | |
self.description = description | |
self.xenomorphs = xenomorphs | |
PLANETS = [ | |
Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True), | |
Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True) | |
] | |
planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | |
…he server, or whatever.
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.
Great job!
It's too bad your planets seem to have a case of xenomorphs though!
"id": self.id, | ||
"name": self.name, | ||
"description": self.description, | ||
"xenomorphs": self.xenomorphs |
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.
Oh no!
##---partial functionality; would like to discuss---## | ||
if name_query: | ||
planets = Planet.query.filter_by(name=name_query) | ||
elif xenomorphs_query: | ||
planets = Planet.query.filter_by(xenomorphs=xenomorphs_query) | ||
##---END---## |
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.
This might be helpful to look at: https://stackoverflow.com/questions/19699756/flask-sqlalchemy-greater-than-or-equal-to
No description provided.