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

Sea Turtles Solar System API Part 1 Tyrah and San #24

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

Conversation

ursaturnine
Copy link

No description provided.

app/routes.py Outdated

class Planet:
def __init__(self, id, name, description, has_moon=None):
Copy link

Choose a reason for hiding this comment

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

for has_moon you can use a boolean value directly as the default. So in this case has_moon=False. We initially used None for the inventory list in swap meet because we wanted to tell whether the call had passed in the inventory list.

app/routes.py Outdated
self.description = description
self.has_moon = has_moon

def to_json(self):
Copy link

Choose a reason for hiding this comment

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

great job making this an instance method!

app/routes.py Outdated
abort(make_response({"message":f"planet {planet_id} not found"}, 404))

@bp.route("", methods=["GET"])
def handle_planets():
Copy link

Choose a reason for hiding this comment

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

Conventionally you would see the naming of the function be similar to the CRUD operation you are performing. Like get_planets or get_all_planets

app/routes.py Outdated
@bp.route("", methods=["GET"])
def handle_planets():
planet_response = [planet.to_json() for planet in planets]
return jsonify(planet_response)
Copy link

Choose a reason for hiding this comment

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

Here it's nice to add a 200 status code. Even though it happens by default it adds readability to your code.

return jsonify(planets_result), 200

app/routes.py Outdated
return jsonify(planet_response)

@bp.route("/<planet_id>", methods=["GET"])
def get_one_planet(planet_id):
Copy link

Choose a reason for hiding this comment

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

💃🏽

"SQLALCHEMY_DATABASE_URI")
else:
app.config["TESTING"] = True
# app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
Copy link

Choose a reason for hiding this comment

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

you can go ahead and remove this

Comment on lines +36 to +40
if not test_config:
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI')
else:
app.config["TESTING"] = True
app.config['SQLALCHEMY_TEST_DATABASE_URI'] = os.environ.get('SQLALCHEMY_TEST_DATABASE_URI')
Copy link

Choose a reason for hiding this comment

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

looks like you all have this twice. Its also on lines 20 - 28. You can remove one of them.

@@ -0,0 +1,29 @@
# from flask import Flask
Copy link

Choose a reason for hiding this comment

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

if this whole file it commented out you can make it an empty __init__.py file.

Comment on lines +5 to +7
name = db.Column(db.String, nullable=False)
description = db.Column(db.String, nullable=False)
has_moon = db.Column(db.Boolean, nullable=False)
Copy link

Choose a reason for hiding this comment

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

I like that you all made this nullable = False



#planet turn itself into dictionary
def to_dict(self):
Copy link

Choose a reason for hiding this comment

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

🙌🏽

Comment on lines +31 to +35
new_planet = Planet(
name=request_body["name"],
description=request_body["description"],
has_moon=request_body["has_moon"],
)
Copy link

Choose a reason for hiding this comment

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

you could also make this an instance method in your Planet class.

has_moon_query = request.args.get("has_moon")


if name_query:
Copy link

Choose a reason for hiding this comment

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

love these multiple ways to query

assert response_body == {
"id": 1,
"name": "Venus",
"description": "watr 4evr",
Copy link

Choose a reason for hiding this comment

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

not watr 4evr 😂

venus_planet = Planet(name="venus",
description="i luv 2 climb rocks", has_moon=True)

db.session.add_all([mars_planet, venus_planet])
Copy link

Choose a reason for hiding this comment

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

👩🏽‍💻

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