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 Say R. & Izzy B. #18

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
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 Apr 25, 2023
abe7809
completed
izzybusy5 Apr 25, 2023
0f71bd2
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
izzybusy5 Apr 25, 2023
09d3931
creates POST endpoint
LRyder17 Apr 28, 2023
cc4e408
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
LRyder17 Apr 28, 2023
956f55f
handles single planet
LRyder17 Apr 28, 2023
0f8994c
updated and deleted endpoints
izzybusy5 May 1, 2023
1b26e32
refactored
izzybusy5 May 1, 2023
13c0fbb
adds query params
LRyder17 May 2, 2023
2d68184
testing
izzybusy5 May 2, 2023
f5d78e7
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
LRyder17 May 2, 2023
56672fe
frankinstine merge
LRyder17 May 2, 2023
e8eb4e6
added pytests
LRyder17 May 3, 2023
24a2655
deleted files
izzybusy5 May 3, 2023
868a774
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
izzybusy5 May 3, 2023
5adc317
adds test for empty database
LRyder17 May 3, 2023
52b7d0b
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
LRyder17 May 3, 2023
a50347c
corrects test name
LRyder17 May 3, 2023
dc1e077
some updates
izzybusy5 May 3, 2023
24e76bd
Merge branch 'main' of https://github.com/LRyder17/solar-system-api
izzybusy5 May 3, 2023
f79cc7a
update return message
izzybusy5 May 3, 2023
d936ce5
adds pytests for update and delete
LRyder17 May 4, 2023
474ee69
adds generic validate function
LRyder17 May 4, 2023
ed82db7
final push
LRyder17 May 4, 2023
b80f5c5
added routes folder and refactors
LRyder17 May 9, 2023
5534ed1
fixes moon GET route
LRyder17 May 9, 2023
2134c2b
implements add_moon_to_planet function
LRyder17 May 9, 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
Next Next commit
completes wave 1&2
  • Loading branch information
LRyder17 committed Apr 25, 2023
commit 5bf5eecf0b2a7a5a65e229d555e96ec62ab6f7c2
9 changes: 8 additions & 1 deletion app/__init__.py
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
54 changes: 53 additions & 1 deletion app/routes.py
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())

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?


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()

Choose a reason for hiding this comment

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