Skip to content

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

Open
ursaturnine wants to merge 11 commits intoada-c17:mainfrom
ursaturnine:main
Open

Sea Turtles Solar System API Part 1 Tyrah and San #24
ursaturnine wants to merge 11 commits intoada-c17:mainfrom
ursaturnine:main

Conversation

@ursaturnine
Copy link
Copy Markdown

No description provided.

Comment thread app/routes.py Outdated
from flask import Blueprint, jsonify, abort, make_response

class Planet:
def __init__(self, id, name, description, has_moon=None):
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 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.

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

def to_json(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.

great job making this an instance method!

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

@bp.route("", methods=["GET"])
def handle_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.

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

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

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

Comment thread app/routes.py Outdated
return jsonify(planet_response)

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

Choose a reason for hiding this comment

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

💃🏽

Comment thread app/__init__.py
"SQLALCHEMY_DATABASE_URI")
else:
app.config["TESTING"] = True
# app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
Copy link
Copy Markdown

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

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.

Comment thread app/models/__init__.py
@@ -0,0 +1,29 @@
# from flask import Flask
Copy link
Copy Markdown

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 thread app/models/planet.py
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
Copy Markdown

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

Comment thread app/models/planet.py


#planet turn itself into dictionary
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.

🙌🏽

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

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.

Comment thread app/routes.py
has_moon_query = request.args.get("has_moon")


if name_query:
Copy link
Copy Markdown

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

Comment thread test/test_route.py
assert response_body == {
"id": 1,
"name": "Venus",
"description": "watr 4evr",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not watr 4evr 😂

Comment thread tests/conftest.py
venus_planet = Planet(name="venus",
description="i luv 2 climb rocks", has_moon=True)

db.session.add_all([mars_planet, venus_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.

👩🏽‍💻

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