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

Sphinx + Phoenix - Sarah K., Charday N., & Priyanka K. #66

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
034283a
Passes Wave 1. Created virtual environment, installed dependencies, d…
skoch-neat Oct 18, 2024
11b0eab
Complete wave 02. Add new get endpoint to planets blueprint
chardayneal Oct 21, 2024
70f0a3a
Correct code for wave1 and wave2 from PR feedback
PriyankaKaramchandani Oct 25, 2024
0e7c2a9
Removed hardcoded data. Created project database. Connected the datab…
PriyankaKaramchandani Oct 25, 2024
db19c66
Initialize migration, generate migration and apply migration to database
PriyankaKaramchandani Oct 25, 2024
2198141
Complete wave 3 implementation.
PriyankaKaramchandani Oct 25, 2024
7ac8d4d
Implement validate_planet function to use in get_one_planet endpoint.
PriyankaKaramchandani Oct 25, 2024
517a1e2
Updated code to comply with PEP8 standards. Changed import statements…
skoch-neat Oct 28, 2024
9c4e80d
Merge pull request #1 from skoch-neat/pep8-cleanup
skoch-neat Oct 29, 2024
babd837
Updated validation to access database. Added functionality to update …
skoch-neat Oct 29, 2024
458915d
Merge branch 'main' of https://github.com/skoch-neat/solar-system-api
skoch-neat Oct 29, 2024
ac86dfe
Refactor code. Update get_all_planets route to consider query params.…
chardayneal Oct 30, 2024
7b738e0
"test_planet_routes"
PriyankaKaramchandani Oct 31, 2024
dd74ea2
Add app/__init__.py test_database configuration.
PriyankaKaramchandani Oct 31, 2024
60bea74
Added constants file for storing and importing strings used repeatedl…
skoch-neat Nov 1, 2024
cf0a16b
added gunicorn to requirements.txt
skoch-neat Nov 6, 2024
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
@@ -1,7 +1,10 @@
from flask import Flask
from .routes import planets_bp
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment in routes.py first, how would this import statement need to change if your route file was named planet_routes.py and was in a "routes" directory?



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

app.register_blueprint(planets_bp)

return app
21 changes: 21 additions & 0 deletions app/planets.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though we only have one model, planets, we'll still want a directory called "models" and this file would nest under that directory.

Soon you'll be working with APIs that have multiple models and each model will have specific routes so organizing your project accordingly makes it easier to navigate.

Consider making this change before starting on Wave 3!

Also, since the class name is singular, I'd expect that the file name would match the class name so planets.py would be called planet.py

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Planet:
def __init__(self, id, name, description, moons):
self.id = id
self.name = name
self.description = description
self.moons = moons

def to_dict(self):
return {
"id": self.id,
"name": self.name,
"description": self.description,
"moons": self.moons
}

planets = [
Planet(1, "Mercury", "Small, hot, fast", []),
Planet(2, "Venus", "Thick atmosphere", []),
Planet(3, "Earth", "Supports life, very watery", ["Moon"]),
Planet(4, "Mars", "Red planet, biggest volcano", ["Phobos", "Deimos"])
]
28 changes: 27 additions & 1 deletion app/routes.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though we only have one model, planets, we'll still want a directory called "routes" and this file would nest under that directory and should be renamed planet_routes.py

Consider making this change before starting on Wave 3!

Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
from flask import Blueprint
from flask import Blueprint, abort, make_response
from .planets import planets

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

@planets_bp.get('')
def get_all_planets():
return [planet.to_dict() for planet in planets], 200

@planets_bp.get('/<planet_id>')
def get_one_planet(planet_id):
planet = validate_planet(planet_id)

return planet.to_dict(), 200

def validate_planet(planet_id):
try:
planet_id = int(planet_id)
except ValueError:
response = {"message": f"planet {planet_id} invalid"}
abort(make_response(response, 400))

for planet in planets:
if planet.id == planet_id:
return planet

response = {"message": f"planet {planet_id} not found"}
abort(make_response(response, 404))
9 changes: 7 additions & 2 deletions requirements.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

Did dependencies get updated? Do we need to be tracking these changes in the requirements.txt? Maybe i missed something since I wasn't in the round table, but I wouldn't expect needing to make changes to this file.

Copy link
Author

Choose a reason for hiding this comment

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

We both had some issues installing Flask, but we didn't intend to make any changes to the requirements.txt (and also missed that this was included in the commit). We'll revert the changes with the next push.

Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
alembic==1.13.1
autopep8==1.5.5
blinker==1.7
blinker==1.7.0
certifi==2020.12.5
chardet==4.0.0
click==8.1.7
coverage==7.6.4
Flask==3.0.2
Flask-Migrate==4.0.5
Flask-SQLAlchemy==3.1.1
idna==2.10
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.3
Mako==1.1.4
MarkupSafe==2.1.5
packaging==24.1
pluggy==1.5.0
psycopg2-binary==2.9.9
pycodestyle==2.6.0
pytest==8.0.0
Expand All @@ -23,5 +27,6 @@ requests==2.25.1
six==1.15.0
SQLAlchemy==2.0.25
toml==0.10.2
typing_extensions==4.12.2
urllib3==1.26.4
Werkzeug==3.0.1
Werkzeug==3.0.1