forked from AdaGold/solar-system-api
-
Notifications
You must be signed in to change notification settings - Fork 61
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 - Sana Pournaghshband and Camilla #20
Open
sanakakadan22
wants to merge
19
commits into
ada-c17:main
Choose a base branch
from
sanakakadan22:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eb67210
add solar project
sanakakadan22 eaa5fd0
complete wave 1
camilla122333 bd072e3
Wave 1
camilla122333 7ab1975
NEW CHANGES
camilla122333 8e32e29
Completed wave 2
camilla122333 101aa0e
Add wave 1 and wave 2
sanakakadan22 6c98125
Added changes
camilla122333 651bb49
add new migration for boolean
sanakakadan22 0598417
add routes
sanakakadan22 fde39b3
add everything
sanakakadan22 4d63fbc
add 04)
sanakakadan22 c98e261
add wave 5
sanakakadan22 7cf65b3
add wave 5 refactored
sanakakadan22 a6aeaaf
Create testing routes, configurations
camilla122333 e1c2d9d
Fix bug
camilla122333 c419281
create fixtures and tests
camilla122333 20d75b6
Pass all tests
camilla122333 be80290
add relationships with moon
sanakakadan22 8e20245
add Procfile
sanakakadan22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from flask import Blueprint, jsonify, make_response, abort | ||
''' | ||
Defined a Planet class with the attributes id, name, | ||
and description, and moons. Also, Created a list of Planet instances. | ||
''' | ||
|
||
|
||
class Planet(): | ||
def __init__(self, id, name, description, moons): | ||
self.id = id | ||
self.name = name | ||
self.description = description | ||
self.moons = moons | ||
|
||
def to_json(self): | ||
return { | ||
"id": self.id, | ||
"name": self.name, | ||
"description": self.description, | ||
"moons": self.moons | ||
} | ||
|
||
planets = [ | ||
Planet(1, "Mercury", ["Grey", "closest to the sun", "smallest planet"], False), | ||
Planet(2, "Venus", ["Brown and grey", "hottest planet"], False), | ||
Planet(3, "Earth", ["Blue, brown green and white", "water world","1 moon"], True), | ||
Planet(4, "Mars", ["Red, brown and tan", "2 moons"], True), | ||
Planet(5, "Jupiter", ["Brown, orange and tan, with white cloud stripes","largest planet", "79 moons"], True), | ||
Planet(6, "Saturn", ["Golden, brown, and blue-grey"," large and distinct ring system" ,"82 moons"], True), | ||
Planet(7, "Uranus", ["Blue-green", " holds the record for the coldest temperature ever measured in the solar system ","27 moons"], True), | ||
Planet(8, "Neptune", ["Blue"," on average the coldest planet" ,"14 moons"], True) | ||
] | ||
|
||
planet_bp = Blueprint("planet_bp", __name__, url_prefix="/planets") | ||
|
||
#Get all planets | ||
@planet_bp.route("", methods=["GET"]) | ||
def read_all_planets(): | ||
planets_response = [] | ||
|
||
for planet in planets: | ||
planets_response.append(planet.to_json()) | ||
|
||
return jsonify(planets_response) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding 200 status code adds clarity even though it happens by default return jsonify(planets_response), 200 |
||
|
||
''' | ||
Created the following endpoint(s). This API can handle requests such as the following: | ||
...to get one existing planet, so that I can see the id, name, description, | ||
and other data of the planet. | ||
... such that trying to get one non-existing planet responds | ||
with get a 404 response, so that I know the planet resource was not found. | ||
... such that trying to get one planet with an invalid planet_id responds | ||
with get a 400 response, so that I know the planet_id was invalid. | ||
''' | ||
|
||
def validate_planet(id): | ||
try: | ||
id = int(id) | ||
except: | ||
return abort(make_response({"message": f"planet {id} is invalid"}, 400)) | ||
|
||
for planet in planets: | ||
if planet.id == id: | ||
return planet | ||
|
||
return abort(make_response({"message": f"planet {id} is not found"}, 404)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM 👍🏽 |
||
|
||
#Get one planet | ||
@planet_bp.route("/<id>", methods=["GET"]) | ||
def read_one_planet(id): | ||
planet = validate_planet(id) | ||
|
||
return jsonify(planet.to_json(), 200) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job naming the method to describe what this route does.
Since you put your routes in planet_routs.py in routes directory, you can even call this read_all() since we know that all the routes in planet_routes.py are related to the Planet class.