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

Cedar - Jacy & Kit #15

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c5a9bfc
Adds class Planet to routes.py
KitSutliff Oct 18, 2021
eb71eb6
Add get all functions and registers blueprint class
KitSutliff Oct 18, 2021
3d7bffd
Adds get_planet function to routes.py
KitSutliff Oct 18, 2021
9cf827e
debug adds missing carrots to routes.py
KitSutliff Oct 18, 2021
39c4dd7
fixed bug in routes.py; changed planet_id to planet in get_planet fun…
jacyyang04 Oct 18, 2021
6d98074
add comment about local host url
jacyyang04 Oct 18, 2021
b42cc8f
add to_json instance method and removed var(planet)
jacyyang04 Oct 22, 2021
0b775b2
delete spacing
jacyyang04 Oct 22, 2021
45c7886
replaces planet class in app with planet model in app.models.
KitSutliff Oct 25, 2021
a29a3af
moves models folder from pycache to app under SOLAR-SYSTEM-API.
KitSutliff Oct 25, 2021
9a0acd4
updates planet.py class in models to do stuff better... like.. with t…
KitSutliff Oct 25, 2021
3c2ff79
we migrated models and updated routes.
KitSutliff Oct 25, 2021
54be1bb
updates routes to fix bug
KitSutliff Oct 25, 2021
7884f06
changed query.all to query.get for get_planet function
jacyyang04 Oct 25, 2021
7d7a32f
made request_body local var
jacyyang04 Oct 26, 2021
2628ed7
minor space changes
jacyyang04 Oct 26, 2021
c737a22
Adds 'update' and 'delete' methods to routes.py
KitSutliff Oct 26, 2021
f1e3085
Started refactoring source code
jacyyang04 Oct 27, 2021
c673c70
add 404 error code
jacyyang04 Oct 27, 2021
778f1ef
refactor all functions
jacyyang04 Oct 27, 2021
7caf8d2
update function names
jacyyang04 Oct 27, 2021
08d0db3
add error codes for return statements
jacyyang04 Oct 27, 2021
9bd9398
add query search routes
jacyyang04 Oct 27, 2021
45f4ace
add purge
jacyyang04 Oct 27, 2021
edf2bfc
fix bugs in create_planets function
jacyyang04 Oct 28, 2021
351d71d
update create_planets function
jacyyang04 Oct 28, 2021
8aafbfb
set up environmental vars
jacyyang04 Oct 28, 2021
42e0d2c
set up test files
jacyyang04 Oct 28, 2021
19ece10
add test routes
jacyyang04 Oct 28, 2021
54abab4
update
jacyyang04 Oct 28, 2021
49302c3
fix test bugs
jacyyang04 Oct 28, 2021
67b3bf4
fix test bugs, update return statement
jacyyang04 Oct 28, 2021
9af523e
change error code
jacyyang04 Oct 28, 2021
663d89a
finalized comments
jacyyang04 Oct 28, 2021
8b5fa84
add procfile
jacyyang04 Nov 3, 2021
b54163c
add gunicorn to requirements.txt
jacyyang04 Nov 3, 2021
ca7eb00
adds Procfile
KitSutliff Nov 3, 2021
2e2e587
actually adds Procfile, but for real this time
KitSutliff Nov 3, 2021
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
3 changes: 3 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
def create_app(test_config=None):
app = Flask(__name__)

from .routes import planets_bp
app.register_blueprint(planets_bp)

return app
39 changes: 38 additions & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
from flask import Blueprint
# localhost:5000/ <-- add url endpoint/parameters here

from flask import Blueprint, jsonify


class Planet():
def __init__(self, id, name, description, xenomorphs=False):
self.id = id
self.name = name
self.description = description
self.xenomorphs = xenomorphs


PLANETS = [

Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True),
Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True)

]

planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note, consider moving extra spaces:

Suggested change
from flask import Blueprint, jsonify
class Planet():
def __init__(self, id, name, description, xenomorphs=False):
self.id = id
self.name = name
self.description = description
self.xenomorphs = xenomorphs
PLANETS = [
Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True),
Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True)
]
planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets")
from flask import Blueprint, jsonify
class Planet():
def __init__(self, id, name, description, xenomorphs=False):
self.id = id
self.name = name
self.description = description
self.xenomorphs = xenomorphs
PLANETS = [
Planet(426, "Nostromo's End", "Hostile weather. Toxic atmosphere. Evidence of civilization.", True),
Planet(224, "JollyPlanet", "Okay. Decent. Will live for long time.", True)
]
planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets")

# @blueprint_name.route("/endpoint/path/here", methods=["GET"])
@planets_bp.route("", methods=["GET"])
def get_all_planets():
planets_response = []

for planet in PLANETS:
planets_response.append(vars(planet))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of vars!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just learned that vars will cause problems when we have a class that connects to our database. We can achieve the same effect by writing a to_json(self) instance method on the Planet class.


return jsonify(planets_response)

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

for planet in PLANETS:
if planet.id == planet_id:
return vars(planet)