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

zoisite/Valerie&Tigist #12

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
871339d
wave-01 complete
tigistlina Apr 22, 2023
70d78c0
[WIP] - Wave 1
valerie-valentine Apr 22, 2023
25ecd77
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
valerie-valentine Apr 22, 2023
789c169
RESOLVED MERGE CONFLICT
valerie-valentine Apr 22, 2023
69c7a10
Wave 02 - Refactoring
valerie-valentine Apr 22, 2023
3918b02
Finished Wave 2
valerie-valentine Apr 22, 2023
70352de
refactor wave 2
tigistlina Apr 22, 2023
f7c4666
Finished wave 1 & Wave 2
valerie-valentine Apr 24, 2023
1dad0e8
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
valerie-valentine Apr 24, 2023
9dccaaa
adds more attributes
tigistlina Apr 28, 2023
130caac
create Planet model table
tigistlina Apr 28, 2023
ef68c3d
Finished handle planet endpoint
valerie-valentine Apr 29, 2023
8ec0f0d
resolves conflict
tigistlina Apr 29, 2023
5533430
Changed planet table column datatypes
valerie-valentine Apr 29, 2023
a6810cf
removed white space
tigistlina Apr 29, 2023
a0f5a97
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
tigistlina Apr 29, 2023
3a93d5d
Finished Wave 3 Complete
valerie-valentine Apr 29, 2023
d2572b5
solves merge conflict
tigistlina Apr 29, 2023
981e916
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
tigistlina Apr 29, 2023
51ff409
changed parent_planet column to mmon_of_planet
tigistlina May 2, 2023
e7663b4
creates validate_planet and get_one_planet end point
tigistlina May 2, 2023
6112ac7
defines update_planet end point
tigistlina May 2, 2023
00e54c5
Finished Wave 4
valerie-valentine May 2, 2023
8f6c798
Create env file and setup databases
valerie-valentine May 3, 2023
a252622
WIP creating test checks empty db returns empty list
valerie-valentine May 3, 2023
1c20053
Finished wave 6 - implemented tests
valerie-valentine May 4, 2023
adecf6d
setup .env file
tigistlina May 4, 2023
5df9359
Merge branch 'main' of https://github.com/tigistlina/solar-system-api
tigistlina May 4, 2023
847f3ef
refactors code, creates helper function
tigistlina May 4, 2023
0e57c3c
Finished refactoring project
valerie-valentine May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

def create_app(test_config=None):
app = Flask(__name__)

from .routes import planets_bp
app.register_blueprint(planets_bp)


return app
56 changes: 55 additions & 1 deletion app/routes.py
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())

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:

results = [planet.create_dict() for planet in planets]

return jsonify(results)

@planets_bp.route("/<planet_id>", methods=["GET"])
def get_planet(planet_id):
planet = validate_planet(planet_id)
return planet.create_dict()

Choose a reason for hiding this comment

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