forked from AdaGold/solar-system-api
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Pine - Mariah and Kayla #14
Open
khuddleup
wants to merge
9
commits into
Ada-C16:main
Choose a base branch
from
khuddleup: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 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b48115b
Solar System Part 1: Complete
khuddleup bc401c3
refactors get_planet() to handle 404 error
mrosman7 667d83b
sets up SAQLAlchemy and Migrate in __init__.py
mrosman7 07b1d1c
creates models package including planets.py which defines the Planet …
mrosman7 7a79290
refactors routes.py to query data from the solar_system_development d…
mrosman7 07c641c
New planet blueprint added
khuddleup 0592a4e
adds to_dict() function to Planet Model
mrosman7 5dc0a10
adds Put and Delete methods to handle_planet function
mrosman7 3bd3065
Solar System API Complete
khuddleup 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
#create app function and registering blueprints | ||
from flask import Flask | ||
|
||
|
||
def create_app(test_config=None): | ||
app = Flask(__name__) | ||
from .routes import planets_bp #importing from routes | ||
app.register_blueprint(planets_bp) #registering the route | ||
|
||
return app |
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 |
---|---|---|
@@ -1,2 +1,44 @@ | ||
from flask import Blueprint | ||
#define our class and make bluprints | ||
from flask import Blueprint, jsonify | ||
|
||
#class are capitalized | ||
class Planet: | ||
def __init__(self, id, name, description, num_moons): | ||
self.id = id | ||
self.name = name | ||
self.description = description | ||
self.num_moons = num_moons | ||
|
||
planets = [ | ||
Planet(1, "Earth", "Green and Blue", 1), | ||
Planet(2, "Mars", "Red and Orange", 2), | ||
Planet(3, "Jupiter", "Gray and Brown", 79) | ||
] | ||
|
||
planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | ||
|
||
@planets_bp.route("", methods=["GET"]) #decorator communicates with flask | ||
def get_planets(): #function does the work | ||
planets_response = [] | ||
for planet in planets: | ||
planets_response.append({ | ||
"id" : planet.id, | ||
"name" : planet.name, | ||
"description" : planet.description, | ||
"num_moons" : planet.num_moons | ||
}) | ||
return jsonify(planets_response) | ||
|
||
@planets_bp.route("/<planet_id>", methods=["GET"]) | ||
def get_planet(planet_id): | ||
for planet in planets: | ||
if planet.id == int(planet_id): | ||
response = { | ||
"id" : planet.id, | ||
"name" : planet.name, | ||
"description" : planet.description, | ||
"num_moons" : planet.num_moons | ||
} | ||
return jsonify(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. Nice! |
||
|
||
return 'Planet ID 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. 💯 |
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.
👍