forked from AdaGold/solar-system-api
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Zoisite Say R. & Izzy B. #18
Open
LRyder17
wants to merge
27
commits into
Ada-C19:main
Choose a base branch
from
LRyder17: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 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5bf5eec
completes wave 1&2
LRyder17 abe7809
completed
izzybusy5 0f71bd2
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
izzybusy5 09d3931
creates POST endpoint
LRyder17 cc4e408
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
LRyder17 956f55f
handles single planet
LRyder17 0f8994c
updated and deleted endpoints
izzybusy5 1b26e32
refactored
izzybusy5 13c0fbb
adds query params
LRyder17 2d68184
testing
izzybusy5 f5d78e7
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
LRyder17 56672fe
frankinstine merge
LRyder17 e8eb4e6
added pytests
LRyder17 24a2655
deleted files
izzybusy5 868a774
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
izzybusy5 5adc317
adds test for empty database
LRyder17 52b7d0b
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
LRyder17 a50347c
corrects test name
LRyder17 dc1e077
some updates
izzybusy5 24e76bd
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
izzybusy5 f79cc7a
update return message
izzybusy5 d936ce5
adds pytests for update and delete
LRyder17 474ee69
adds generic validate function
LRyder17 ed82db7
final push
LRyder17 b80f5c5
added routes folder and refactors
LRyder17 5534ed1
fixes moon GET route
LRyder17 2134c2b
implements add_moon_to_planet function
LRyder17 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
Next
Next commit
completes wave 1&2
- Loading branch information
commit 5bf5eecf0b2a7a5a65e229d555e96ec62ab6f7c2
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,14 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_migrate import Migrate | ||
|
||
db =SQLAlchemy() | ||
migrate = Migrate() | ||
|
||
|
||
def create_app(test_config=None): | ||
app = Flask(__name__) | ||
|
||
from .routes import planets_bp | ||
app.register_blueprint(planets_bp) | ||
|
||
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,54 @@ | ||
from flask import Blueprint | ||
from flask import Blueprint, jsonify, abort, make_response | ||
|
||
class Planet: | ||
def __init__(self, id, name, description, color): | ||
self.id =id | ||
self.name = name | ||
self.description = description | ||
self.color = color | ||
|
||
def planet_to_dict(self): | ||
return { | ||
"id": self.id, | ||
"name": self.name, | ||
"description": self.description, | ||
"color": self.color | ||
} | ||
|
||
|
||
planets = [ | ||
Planet(1,"big", "Pretty", "Purple"), | ||
Planet(2,"bigg", "Round", "Orange"), | ||
Planet(3,"bigger", "Lumpy", "Rainbow"), | ||
Planet(4,"biggerthan","Wiggly", "Blue"), | ||
] | ||
|
||
planets_bp = Blueprint("planets", __name__, url_prefix="/planets") | ||
|
||
@planets_bp.route("", methods = ["GET"]) | ||
def handle_planets(): | ||
result_list = [] | ||
|
||
for planet in planets: | ||
result_list.append(planet.planet_to_dict()) | ||
|
||
return jsonify(result_list) | ||
|
||
def validate_planet(id): | ||
try: | ||
id = int(id) | ||
except: | ||
abort(make_response({"message":f"Planet {id} invaid"}, 400)) | ||
|
||
for planet in planets: | ||
if planet.id == id: | ||
return planet | ||
|
||
abort(make_response({"message":f"Planet {id} not found"}, 404)) | ||
|
||
@planets_bp.route("/<id>", methods=["GET"]) | ||
def handle_planet(id): | ||
planet = validate_planet(id) | ||
return planet.planet_to_dict() | ||
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. It's not a rule and the code still executes just fine, but usually we'd see all the routes grouped together and all the helpers methods grouped together in a file. |
||
|
||
|
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.
This would be a good candidate for a list comprehension, what could that look like?