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

Spruce - Veronica Osei #28

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

Spruce - Veronica Osei #28

wants to merge 4 commits into from

Conversation

VeronicaO27
Copy link

No description provided.

@VeronicaO27 VeronicaO27 changed the title Solar System - Veronica Osei Spruce - Veronica Osei Oct 28, 2021
Copy link

@audreyandoy audreyandoy left a comment

Choose a reason for hiding this comment

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

Hi Veronica and Cassandra (?) Great work! I have added feedback on how to use helper methods and refactor.

Comment on lines +4 to +7
class Planet(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String)
description = db.Column(db.String)

Choose a reason for hiding this comment

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

Careful! Using the class as it currently is, we'd be able to make a planet with a null name and description. When making classes in the future, consider which columns are required (non-nullable).

Comment on lines +9 to +10
def to_string(self):
return f'{self.id}: {self.name} Description: {self.description}'

Choose a reason for hiding this comment

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

Yay helper methods!

Choose a reason for hiding this comment

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

Also, I highly recommend adding a helper method to turn planet instances into a dictionary (this will definitely save you from writing a few lines of code down the road)!


planets_bp = Blueprint("planets_py", __name__, url_prefix= "/planets")

@planets_bp.route("", methods=["GET","POST"])

Choose a reason for hiding this comment

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

Consider separating each request method into its different functions. This makes testing the endpoints much easier to do and follows the single responsibility principle.

Comment on lines +12 to +19
planets_response = []
for planet in planets:
planets_response.append(
{
"id": planet.id,
"name": planet.name,
"description": planet.description
})

Choose a reason for hiding this comment

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

We could reduce these lines of code using a helper method to turn the planet object into a dictionary in the Planets class:

Suggested change
planets_response = []
for planet in planets:
planets_response.append(
{
"id": planet.id,
"name": planet.name,
"description": planet.description
})
planets_response = []
for planet in planets:
planets_response.append(planet.to_dict())

And further refactor using a list comprehension :D

Suggested change
planets_response = []
for planet in planets:
planets_response.append(
{
"id": planet.id,
"name": planet.name,
"description": planet.description
})
planets_response = [ planets_response.append(planet.to_dict()) for planet in planets ]

Comment on lines +22 to +24
request_body = request.get_json()
new_planet = Planet(name=request_body["name"],
description=request_body["description"])

Choose a reason for hiding this comment

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

We should check if request_body contains falsy values so that a planet isn't created with empty data!

}

elif request.method == "PUT":
request_body = request.get_json()

Choose a reason for hiding this comment

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

We should always check if the request_body is empty

db.session.commit()

return make_response(f"Planet #{planet.id} successfully updated")
elif request.method == "DELETE":

Choose a reason for hiding this comment

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

👍

def test_so_fancy(so_fancy):
assert so_fancy.fancy
so_fancy.or_is_it()
assert not so_fancy.fancy

Choose a reason for hiding this comment

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

V Fancy 💅

# db.session.add(ocean_book)
# db.session.add(mountain_book)
db.session.commit()

Choose a reason for hiding this comment

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

Consider returning [saturn_planet, pluto_planet] after this line, so that tests can make use of the attributes of the records (like the id or name of planet)

# Act
response = client.get("/planets/1")
# ...

Choose a reason for hiding this comment

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

The test for the post request is missing

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.

2 participants