Skip to content

Snow Leopards - Jennifer & Diana #36

Open
datateur wants to merge 37 commits intoAda-C18:mainfrom
datateur:main
Open

Snow Leopards - Jennifer & Diana #36
datateur wants to merge 37 commits intoAda-C18:mainfrom
datateur:main

Conversation

@datateur
Copy link
Copy Markdown

@datateur datateur commented Nov 4, 2022

No description provided.

Copy link
Copy Markdown

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

👍 Keep it up for Task List API!

Try to apply all the refactors we went over in Learn and class as you work on Task List.

Comment thread app/__init__.py
migrate = Migrate()
load_dotenv()

def create_app(test_config=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.

👍

Comment thread app/models/planet.py
description = db.Column(db.Text, nullable=False)
rings = db.Column(db.Boolean, nullable=False)

def build_planet_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.

Prefer to leave planet out of the name of this function, so build_dict, or as we used in RT, to_dict. Since this is a method of Planet, it's a little redundant to have the class' own name in the methd. We probably will have an instance in a variable named something like planet, in which case, calling this would look like planet.build_planet_dict(). If we shorten the name, it would be planet.build_dict(), or planet.to_dict(), which already communicates that we're converting a planet to a dictionary representation.

Comment thread migrations/README
@@ -0,0 +1,5 @@
<<<<<<< HEAD
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It looks like this file (which Alembic should have generated itself) somehow ended up with a merge conflict in it? Not sure what happened here.

Comment thread migrations/env.py
import logging
from logging.config import fileConfig

<<<<<<< HEAD
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There are more merge conflcicts here. At some point did your migrations stop working? These conflicts look like they would cause the code in this file to break.

@@ -0,0 +1,34 @@
"""adds Book 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.

👍 Good message on the migration

Comment thread tests/conftest.py
Planet(name="Mars", description="The red planet", rings=False),
Planet(name="Jupiter", description="The gas giant", rings=False),
Planet(name="Saturn", description="The second largest planet", rings=True),
Planet(name="Uranus", description="This planet spins on its side", rings=True),
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 fact that Uranus spins on its side is why it's my favorite planet!

Comment thread app/routes.py

planet_bp = Blueprint("planets", __name__, url_prefix="/planets")

def validate_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.

👀 Consider refactoring this to receive the class type as a parameter so that our validate helper could work for more than one type. This will be helpful in Task List when adding the Goal model.

Comment thread app/routes.py

planet_query = Planet.query

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.

👍 Nice handling of multiple query filters.

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

return make_response(f"Planet {new_planet.name} successfully created", 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.

👀 Make sure to jsonify even plain string responses, otherwise flask will return an HTML response rather than JSON.

Comment thread app/routes.py
planet = validate_planet(planet_id)
request_body = request.get_json()

planet.name = request_body["name"]
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 (and in the create method) consider handling a possible KeyError with a more tailored message (similar to the abort handling in the validation function).

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