Skip to content

Sharks- Bahareh & Chinazo#22

Open
ChinazoOnwukaike wants to merge 5 commits intoada-c17:mainfrom
ChinazoOnwukaike:main
Open

Sharks- Bahareh & Chinazo#22
ChinazoOnwukaike wants to merge 5 commits intoada-c17:mainfrom
ChinazoOnwukaike:main

Conversation

@ChinazoOnwukaike
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Part 1! Nicely done! Left a few suggestions here and there, but your logic looks good

Comment thread app/routes.py
Comment on lines +32 to +37
planet_response.append({
"id" : planet.planet_id,
"name" : planet.name,
"description" : planet.description,
"color" : planet.color
})
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 would make a good instance method to define in the Planet class

Comment thread app/routes.py
if not planet_response:
return abort(make_response({"message": f"Planet {name_query} is not found"}, 404))

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.

don't forget your status code!

Suggested change
return jsonify(planet_response)
return jsonify(planet_response), 200

Comment thread app/routes.py

#POST new planet
@planet_bp.route("", methods=["POST"])
def add_new_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.

👍

Comment thread app/routes.py
Comment on lines +62 to +67
return {
"id" : planet.planet_id,
"name" : planet.name,
"description" : planet.description,
"color" : planet.color
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

another good reason to make this an instance method! we won't need to duplicate this code again

Comment thread app/routes.py Outdated

db.session.commit()

return make_response(f"Planet #{planet.planet_id}, '{planet.name}', successfully updated.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't forget your status code!

Comment thread app/routes.py Outdated
db.session.delete(planet)
db.session.commit()

return make_response(f"Planet #{planet.planet_id}, '{planet.name}', successfully deleted.") 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.

don't forget your status code!

Comment thread app/routes.py
@@ -1,2 +1,93 @@
from flask import Blueprint
import re
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

are you using re for anything? I didn't see any regular expressions

Comment thread app/routes.py
import re
from flask import Blueprint, jsonify, abort, make_response, request
from app import db
from app.models.Planet import 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.

something to consider: the file itself should be lowercase as in planet.py whereas the class itself is uppercase

Copy link
Copy Markdown

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Part 2! Nicely done Chinazo and Bahareh! One thing to consider is pulling out some functionality into its own files or put it inside the Planet class.

There was one small logic error, where I think you pulled code from Hello Books and forgot to change out the attribute name.

Other than that, it looked just fine!

Comment thread app/routes.py
Comment on lines +75 to +77
planet.name = request_body["name"]
planet.description = request_body["description"]
planet.color = request_body["color"]
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 could also make a good instance method inside the Planet class

Comment thread app/routes.py
Comment on lines +9 to +19
def validate_planet(planet_id):
try:
planet_id = int(planet_id)
except:
return abort(make_response({"message": f"Planet {planet_id} is invalid"}, 400))

planet = Planet.query.get(planet_id)

if not planet:
return abort(make_response({"message": f"Planet {planet_id} is 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.

We could move this out of the routes file into its own helper function file, so that the routes are cleaner

Comment thread app/routes.py

name_query = request.args.get("name")
if name_query:
planets = Planet.query.filter_by(name=name_query.title())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

hmm why are we filtering by title?

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