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/Valerie&Tigist #12
Open
tigistlina
wants to merge
30
commits into
Ada-C19:main
Choose a base branch
from
tigistlina: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 9 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
871339d
wave-01 complete
tigistlina 70d78c0
[WIP] - Wave 1
valerie-valentine 25ecd77
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
valerie-valentine 789c169
RESOLVED MERGE CONFLICT
valerie-valentine 69c7a10
Wave 02 - Refactoring
valerie-valentine 3918b02
Finished Wave 2
valerie-valentine 70352de
refactor wave 2
tigistlina f7c4666
Finished wave 1 & Wave 2
valerie-valentine 1dad0e8
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
valerie-valentine 9dccaaa
adds more attributes
tigistlina 130caac
create Planet model table
tigistlina ef68c3d
Finished handle planet endpoint
valerie-valentine 8ec0f0d
resolves conflict
tigistlina 5533430
Changed planet table column datatypes
valerie-valentine a6810cf
removed white space
tigistlina a0f5a97
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
tigistlina 3a93d5d
Finished Wave 3 Complete
valerie-valentine d2572b5
solves merge conflict
tigistlina 981e916
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
tigistlina 51ff409
changed parent_planet column to mmon_of_planet
tigistlina e7663b4
creates validate_planet and get_one_planet end point
tigistlina 6112ac7
defines update_planet end point
tigistlina 00e54c5
Finished Wave 4
valerie-valentine 8f6c798
Create env file and setup databases
valerie-valentine a252622
WIP creating test checks empty db returns empty list
valerie-valentine 1c20053
Finished wave 6 - implemented tests
valerie-valentine adecf6d
setup .env file
tigistlina 5df9359
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
tigistlina 847f3ef
refactors code, creates helper function
tigistlina 0e57c3c
Finished refactoring project
valerie-valentine 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 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,56 @@ | ||
from flask import Blueprint | ||
from flask import Blueprint, jsonify, abort, make_response | ||
|
||
class Planet: | ||
def __init__(self, id, name, description, size): | ||
self.id = id | ||
self.name = name | ||
self.description = description | ||
self.size = size | ||
|
||
def create_dict(self): | ||
return dict( | ||
id=self.id, | ||
name=self.name, | ||
description=self.description, | ||
size=self.size | ||
) | ||
|
||
planets = [ | ||
Planet(1, "Earth", "habitable", "12742km in diameter"), | ||
Planet(2, "Mercury", "inhabitable", "4880km in diameter"), | ||
Planet(3, "Venus", "inhabitable", "12104km in diameter"), | ||
Planet(4, "Mars", "inhabitable", "6779km in diameter"), | ||
Planet(5, "Jupiter", "inhabitable", "139822km in diameter"), | ||
Planet(6, "Saturn", "inhabitable", "116460km in diameter") | ||
] | ||
|
||
planets_bp = Blueprint("planets", __name__, url_prefix="/planets") | ||
|
||
def validate_planet(planet_id): | ||
try: | ||
planet_id=int(planet_id) | ||
except: | ||
abort(make_response({"message": f"planet {planet_id} invalid"}, 400)) | ||
|
||
for planet in planets: | ||
if planet.id == planet_id: | ||
return planet | ||
|
||
abort(make_response({"message": f"planet {planet_id} not found"}, 404)) | ||
|
||
|
||
@planets_bp.route("", methods=["GET"]) | ||
def get_list_of_planets(): | ||
results =[] | ||
for planet in planets: | ||
results.append(planet.create_dict()) | ||
return jsonify(results) | ||
|
||
@planets_bp.route("/<planet_id>", methods=["GET"]) | ||
def get_planet(planet_id): | ||
planet = validate_planet(planet_id) | ||
return planet.create_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. I think lines 51 and 52 are indented two levels, but only needs to be indented once. |
||
|
||
|
||
|
||
|
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 list comprehension, something like: