Skip to content

Tigers Team 11: Selam & Kindra #23

Open
kkgre257 wants to merge 14 commits intoAda-C18:mainfrom
kkgre257:main
Open

Tigers Team 11: Selam & Kindra #23
kkgre257 wants to merge 14 commits intoAda-C18:mainfrom
kkgre257:main

Conversation

@kkgre257
Copy link
Copy Markdown

Waves 1 & 2

Copy link
Copy Markdown

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Nice work Selam & Kinda. You hit the learning goals here. Well done. I left some minor comments and let me know if you have questions via slack.

Comment thread app/models/planet.py
Comment on lines +10 to +24
def to_dict(self):
planet_dict = {}
planet_dict["id"] = self.id
planet_dict["name"] = self.name
planet_dict["description"] = self.description
planet_dict["diameter"] = self.diameter
return planet_dict

@classmethod
def from_dict(cls, planet_data):
new_planet = Planet(name=planet_data["name"],
description=planet_data["description"],
diameter=planet_data["diameter"]
)
return new_planet 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.

Nice helper methods.

Comment thread app/routes.py
Comment on lines +11 to +22
def validate_planet(cls, planet_id):
try:
planet_id = int(planet_id)
except:
abort(make_response({"message":f"{cls.__name__} {planet_id} invalid"}, 400))

planet = cls.query.get(planet_id)

if not planet:
abort(make_response({"message":f"{cls.__name__} {planet_id} not found"}, 404))

return 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.

Nice validation function

Comment thread app/routes.py

@planet_bp.route("", methods=["POST"])
def create_planet():
request_body = request.get_json()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doing some validation on the request body (to make sure it has the required fields) would be appropriate.

Comment thread app/routes.py
def update_planet(planet_id):
planet = validate_planet(Planet, planet_id)

request_body = request.get_json()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doing validation on the request body would be appropriate here.

Comment thread tests/test_routes.py
}
]

def test_create_one_planet(client):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Testing the create action with an invalid request body is also appropriate.

Comment thread app/routes.py
return planet.to_dict()

@planet_bp.route("/<planet_id>", methods=["DELETE"])
def delete_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.

Just noting this is untested.

Comment thread app/routes.py
return make_response(jsonify(f"Planet #{planet.id} successfully deleted!"))

@planet_bp.route("/<planet_id>", methods=["PUT"])
def update_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.

Just noting this is untested.

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