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

Sharks- Bahareh & Chinazo #22

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

Conversation

ChinazoOnwukaike
Copy link

No description provided.

Copy link

@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 on lines +32 to +37
planet_response.append({
"id" : planet.planet_id,
"name" : planet.name,
"description" : planet.description,
"color" : planet.color
})

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

if not planet_response:
return abort(make_response({"message": f"Planet {name_query} is not found"}, 404))

return jsonify(planet_response)

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


#POST new planet
@planet_bp.route("", methods=["POST"])
def add_new_planet():

Choose a reason for hiding this comment

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

👍

Comment on lines +62 to +67
return {
"id" : planet.planet_id,
"name" : planet.name,
"description" : planet.description,
"color" : planet.color
}

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

app/routes.py Outdated

db.session.commit()

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

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!

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

return make_response(f"Planet #{planet.planet_id}, '{planet.name}', successfully deleted.")

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!

@@ -1,2 +1,93 @@
from flask import Blueprint
import re

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

import re
from flask import Blueprint, jsonify, abort, make_response, request
from app import db
from app.models.Planet import Planet

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

@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 on lines +75 to +77
planet.name = request_body["name"]
planet.description = request_body["description"]
planet.color = request_body["color"]

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

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


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

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