Skip to content

Zoisite - Nadia and L. - Waves 1 & 2#17

Open
Ljpeg wants to merge 29 commits intoAda-C19:mainfrom
Ljpeg:main
Open

Zoisite - Nadia and L. - Waves 1 & 2#17
Ljpeg wants to merge 29 commits intoAda-C19:mainfrom
Ljpeg:main

Conversation

@Ljpeg
Copy link
Copy Markdown

@Ljpeg Ljpeg commented Apr 25, 2023

No description provided.

Copy link
Copy Markdown

@apradoada apradoada left a comment

Choose a reason for hiding this comment

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

Overall, really well done, y'all! This looks great!

Comment thread app/routes.py
# read one planet
# return 400 for invalid id
# return 404 for non existing planet
planets_bp = Blueprint("planets", __name__, url_prefix="/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.

Great job putting together your planet class, your planet list and your planet blueprint!

Comment thread app/routes.py Outdated
def handle_planets():
results = []
for planet in planets:
results.append(planet.to_dict())
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 looks great! Just food for thought, I wonder if this would be a good candidate for a list comprehension... 🤔

Comment thread app/routes.py Outdated
if planet.id == planet_id:
return planet

abort(make_response({"message":f"planet {planet_id} not found"}, 404)) No newline at end of file
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 rest of this looks really good!

Copy link
Copy Markdown

@apradoada apradoada left a comment

Choose a reason for hiding this comment

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

Well done, Nadia and L! I left a few comments/things to think about but overall this looks great!

Comment thread app/__init__.py

def create_app(test_config=None):
app = Flask(__name__)
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.

Nice job placing this above the conditional so we don't repeat code!

Comment thread app/models/planet.py
id=db.Column(db.Integer, primary_key=True, autoincrement=True)
name=db.Column(db.String, nullable=False)
description=db.Column(db.String, nullable=False)
solar_day=db.Column(db.Float, 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.

Good idea to make these attributes non-nullable! That being said, it can be beneficial to have some nullable attributes. It all boils down to how you want to design your particular class though!

Comment thread app/models/planet.py
name=planet_data["name"],
description=planet_data["description"],
solar_day=planet_data["solar_day"]
)
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
if not model:
abort(make_response(jsonify({"message":f"{cls.__name__} {model_id} not found"}), 404))

return model
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 updating the validate model method to be generic and applicable to any class!

Comment thread app/routes.py
db.session.add(new_planet)
db.session.commit()

return make_response(jsonify(f"Planet {new_planet.name} created successfully."), 201)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When you created your Planet class, you made each of the attributes non-nullable, which means that each one needs to be present when an instance of that class is created! With that in mind, it might be a good idea to include some level of error handling when your planet is created in case any of the attributes aren't present!

Comment thread app/routes.py

db.session.commit()

return make_response(jsonify(f"Planet {planet.name} updated successfully."))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similarly as before, this method would be a good candidate for error handling as well.

Comment thread tests/conftest.py
return {
"name": "Walla-Walla",
"description": "A bad place.",
"solar_day": 0.5
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 this!

Comment thread tests/conftest.py
)

db.session.add_all([nebula, gamora])
db.session.commit()
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 creating a custom fixture to work with multiple planets!

Comment thread tests/test_routes.py
response_body = response.get_json()

assert response.status_code == 200
assert response_body == "Planet Walla-Walla updated successfully."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These tests look great! Well done!

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