forked from AdaGold/solar-system-api
-
Notifications
You must be signed in to change notification settings - Fork 20
Cohort 22 Salma Anany and Tami Gaertner #15
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
Open
tagaertner
wants to merge
32
commits into
Ada-C22:main
Choose a base branch
from
tagaertner: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 all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
eaec270
work wave1,create virtual env, dependencies, creat planet class and l…
tagaertner 9914158
wave one
SalmaAnany b432ba2
work wave 2- get one existing planet and 404, 400 response.
tagaertner f9ab1f3
removing manual convert to dict
SalmaAnany 458170a
Found the bug Tami!
SalmaAnany 586f72c
Refactor the validate function
SalmaAnany 0b2d368
clean up the try and catch, to a if check
SalmaAnany 3ba5c57
clean up the try and catch, to a if check
SalmaAnany 060a092
clean up the try and catch, to a if check
SalmaAnany 9c30a4d
clean up the try and catch, to a if check
SalmaAnany 48adb54
clean up the try and catch, to a if check
SalmaAnany 8e38137
Merge branch 'main' of https://github.com/tagaertner/solar-system-api
SalmaAnany 5947424
Wave Two completed
SalmaAnany 8d8c5c7
Wave Two completed
SalmaAnany f9a58bc
Wave Two completed
SalmaAnany b718e48
Wave There completed
SalmaAnany 8152076
added info to planet.py
tagaertner 3876ed1
fixed spelling
tagaertner 27b4595
Wave There completed
SalmaAnany 15f540a
working on wave four: read one planet and update
SalmaAnany 8bc777e
fix bug with update function, work delete function
tagaertner af913c5
work wave 5 retrieve description
tagaertner 2f8cabd
work on adding moon to the request
tagaertner c55376c
added sort and fixed moon and desc param
tagaertner 2a22918
fixing the moon query using __eq__ instead of ==
SalmaAnany c4a651f
working on wave 6 (fixture)
SalmaAnany f7fe0b6
working on wave 6 (fixture)
SalmaAnany 01e806c
work wave 6 add fixtures and test to creat,add one, fix bug
tagaertner dd45b20
wave 6 is completed
SalmaAnany 631b646
add pytest.fixture for update and delete and pytest, fixed update and…
tagaertner 40d8c58
change pytest delete fuct and commented out the pytest.fixture
tagaertner 492fa72
fixed moon_param bug not if there is no param is going to retrieve no…
SalmaAnany 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,7 +1,25 @@ | ||
| from importlib import import_module | ||
| from flask import Flask | ||
| from .routes.planet_routes import planets_bp | ||
| from .db import db, migrate | ||
| from .models import planet | ||
| import os | ||
|
|
||
|
|
||
| def create_app(test_config=None): | ||
| def create_app(config=None): | ||
| app = Flask(__name__) | ||
|
|
||
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
|
|
||
| if config: | ||
| app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') | ||
| app.config.update(config) | ||
| else: | ||
| app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') | ||
|
|
||
| db.init_app(app) | ||
| migrate.init_app(app, db) | ||
|
|
||
| app.register_blueprint(planets_bp) | ||
|
|
||
| return app | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from flask_sqlalchemy import SQLAlchemy | ||
| from flask_migrate import Migrate | ||
| from .models.base import Base | ||
|
|
||
| db = SQLAlchemy(model_class=Base) | ||
| migrate = Migrate() | ||
|
|
Empty file.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from sqlalchemy.orm import DeclarativeBase | ||
|
|
||
| class Base(DeclarativeBase): | ||
| pass | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from sqlalchemy.orm import Mapped, mapped_column | ||
| from ..db import db | ||
|
|
||
| class Planet(db.Model): | ||
| __tablename__ = "planets" | ||
| id: Mapped[int] = mapped_column(primary_key= True, autoincrement=True) | ||
| name: Mapped[str] | ||
| description: Mapped[str] | ||
| moon: Mapped[int] | ||
|
|
||
| def to_dict(self): | ||
| return dict( | ||
| id=self.id, | ||
| name=self.name, | ||
| description=self.description, | ||
| moon=self.moon | ||
| ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| # class Planet: | ||
| # def __init__(self,id, name, description, moon): | ||
| # self.id = id | ||
| # self.name = name | ||
| # self.description = description | ||
| # self.moon = moon | ||
| # | ||
| # planets = [ | ||
| # Planet(1, "Mercury", "the smallest planet in the solar system and orbits closest to the Sun, with extreme temperatures ranging from 430°C (800°F) during the day to -180°C (-290°F) at night.", 0), | ||
| # Planet(2, "Venus", "the Sun and has a thick, toxic atmosphere composed mostly of carbon dioxide, creating a runaway greenhouse effect that makes it the hottest planet in the solar system with surface temperatures around 465°C (870°F", 0), | ||
| # Planet(3, "Earth", "Our home planet, the only known planet to harbor life",1), | ||
| # Planet(4,"Mars", "Red Planet due to its reddish appearance caused by iron oxide (rust) on its surface. It has a thin atmosphere composed mostly of carbon dioxide", 2 ), | ||
| # Planet(4, "Pluto", " filled with icy bodies and other small objects. Once considered the ninth planet in the solar system, it was reclassified as a dwarf planet in 2006 due to its size and the fact that it hasn’t cleared its orbit of other debris. Pluto has a rocky core surrounded by a mantle of water ice and a thin atmosphere of nitrogen, methane, and carbon monoxide.", 5), | ||
| # Planet(5, "Jupiter","is the largest planet in the solar system, a gas giant composed primarily of hydrogen and helium, known for its Great Red Spot—a massive storm larger than Earth", 92), | ||
| # Planet(6, "Saturn","sixth planet from the Sun and is best known for its extensive and stunning ring system, made mostly of ice and rock particles. It is a gas giant composed primarily of hydrogen and helium" , 146), | ||
| # Planet(7, "Uranus","is the seventh planet from the Sun, an ice giant with a blue-green color due to the presence of methane in its atmosphere. It is unique for rotating on its side, with an extreme axial tilt of about 98 degrees", 27 ), | ||
| # Planet(8, "Neptune", "is a blue ice giant, the eighth planet from the Sun. Known for strong winds and dark storms", 14), | ||
| # Planet(9, "Pluto", " a small, icy world in the outer solar system. It has a diverse, frozen landscape featuring a distinctive heart-shaped region", 5 ), | ||
| # ] | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| from flask import Blueprint, abort, make_response, request, Response | ||
| from ..db import db | ||
| from app.models.planet import Planet | ||
|
|
||
| planets_bp = Blueprint("planets_bp", __name__, url_prefix="/planets") | ||
|
|
||
| @planets_bp.post("") | ||
| def create_planet(): | ||
| request_body = request.get_json() | ||
| name = request_body["name"] | ||
| moon= request_body["moon"] | ||
| description = request_body["description"] | ||
|
|
||
| new_planet = Planet(name=name, moon=moon, description=description) | ||
| db.session.add(new_planet) | ||
| db.session.commit() | ||
| response = new_planet.to_dict() | ||
| return response, 201 | ||
|
|
||
| @planets_bp.get("") | ||
| def get_all_planets(): | ||
| description_param = request.args.get("description") | ||
| moon_param = request.args.get("moon") | ||
| moon_op_param = request.args.get("moon_param") | ||
| sort_param = request.args.get("sort") | ||
|
|
||
| query = db.select(Planet) | ||
|
|
||
| if description_param: | ||
| query = query.where(Planet.description.like(f"%{description_param}%")) | ||
|
|
||
| if moon_param: | ||
| try: | ||
| moon_count = int(moon_param) | ||
| # Dictionary of comparison operators | ||
| moon_operators = { | ||
| "eq": Planet.moon.__eq__, | ||
| "gt": Planet.moon.__gt__, | ||
| "lt": Planet.moon.__lt__, | ||
| "gte": Planet.moon.__ge__, | ||
| "lte": Planet.moon.__le__ | ||
| } | ||
| operator_func = moon_operators.get(moon_op_param, Planet.moon.__eq__) | ||
| if operator_func: | ||
| query = query.where(operator_func(moon_count)) | ||
| except ValueError: | ||
| return {"message": "Invalid moon parameter"}, 400 | ||
|
|
||
| sort_options ={ | ||
| "name": Planet.name, | ||
| "name_desc": Planet.name.desc(), | ||
| "moon": Planet.moon, | ||
| "moon_desc": Planet.moon.desc(), | ||
| "id": Planet.id | ||
| } | ||
|
|
||
| sort_field = sort_options.get(sort_param, Planet.id) | ||
| query = query.order_by(sort_field) | ||
|
|
||
| planets = db.session.scalars(query).all() | ||
| planets_response = [planet.to_dict() for planet in planets] | ||
| return planets_response | ||
|
|
||
| @planets_bp.get("/<planet_id>") | ||
| def get_one_planet(planet_id): | ||
| planet = validate_planet_one(planet_id) | ||
|
|
||
| return { | ||
| "id": planet.id, | ||
| "name": planet.name, | ||
| "description": planet.description, | ||
| "moon": planet.moon | ||
| } | ||
|
|
||
| @planets_bp.put("/<planet_id>") | ||
| def update_planet(planet_id): | ||
| planets = Planet.query.all() | ||
| planet = validate_planet(planet_id, planets) | ||
| request_body = request.get_json() | ||
|
|
||
| planet.name= request_body["name"] | ||
| planet.description = request_body["description"] | ||
| planet.moon= request_body["moon"] | ||
| db.session.commit() | ||
|
|
||
| return Response(status=204, mimetype="application/json") | ||
|
|
||
| @planets_bp.delete("/<planet_id>") | ||
| def delete_planet(planet_id): | ||
| planet = validate_planet_one(planet_id) | ||
| db.session.delete(planet) | ||
| db.session.commit() | ||
|
|
||
| return Response(status=204, mimetype="application/json") | ||
|
|
||
| def validate_planet(planet_id, planets): | ||
| # Narrow the errors - data error, type error | ||
| try: | ||
| planet_id = int(planet_id) | ||
| except: | ||
| abort(make_response({"message": f"Planet id {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)) | ||
|
|
||
|
|
||
| def validate_planet_one(planet_id): | ||
|
|
||
| try: | ||
| planet_id = int(planet_id) | ||
| except: | ||
| response = {"message": f"planet {planet_id} invalid"} | ||
| abort(make_response(response, 400)) | ||
|
|
||
| query = db.select(Planet).where(Planet.id == planet_id) | ||
| planet = db.session.scalar(query) | ||
|
|
||
| if not planet: | ||
| response = {"message": f"{planet_id} not found"} | ||
| abort(make_response(response, 404)) | ||
|
|
||
| return planet |
This file contains hidden or 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,25 +1,44 @@ | ||
| # Coworking Agreement | ||
| .# Coworking Agreement | ||
|
|
||
| Talk through each section with your partner. Add notes on what you discussed and agreed upon in each section. At the bottom, type your names to sign off on your agreement. | ||
|
|
||
| ## Accessibility Needs | ||
| *What does each team member need access to in order to succeed and show up the best they can?* | ||
|
|
||
| 1- Time and energy | ||
| 2- Slowness | ||
| 3- Communication | ||
| 4- Fallibility | ||
|
|
||
| ## Collaboration vs. individual work expectations | ||
| *Clarify your collaboration expectations- does your group want to write code together all of the time? Or divide work to do independently, then come together to share accomplishments? What tools and technologies can help your collaboration?* | ||
| Depends | ||
| 1- pair programming | ||
| 2- Independent- when we work independent we Communicate and share our changes via slack or zoom, etc. | ||
| 3- tools and technologies we used to collaborate is zoom and slack. | ||
|
|
||
| ## Learning Style | ||
| *How does each team member learn best in project settings?* | ||
| 1- Doing | ||
| 2- Explaining | ||
| 3- Researching | ||
| 4- Coping | ||
|
|
||
| ## Preferred Feedback Style | ||
| *How does each team member best receive feedback?* | ||
| - By being honest and open. | ||
|
|
||
| ## One Team Communication Skill to Improve | ||
| *What is a teamwork-related skill you want to work on?* | ||
| for Salma | ||
| - Speak more | ||
| - Repeat the info to make sure that I understand correctly | ||
| for Tami | ||
| - Speck clear and slowly | ||
|
|
||
| ## Optional: Other agreements | ||
| *Other co-working agreements that were not captured in the above sections.* | ||
|
|
||
| ## Signatures | ||
| ______________ _______________ | ||
| Date: _________ | ||
| Salma Anany, Tami Gaertner | ||
| Date: oct 21,2024 | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Single-database configuration for Flask. |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # A generic, single database configuration. | ||
|
|
||
| [alembic] | ||
| # template used to generate migration files | ||
| # file_template = %%(rev)s_%%(slug)s | ||
|
|
||
| # set to 'true' to run the environment during | ||
| # the 'revision' command, regardless of autogenerate | ||
| # revision_environment = false | ||
|
|
||
|
|
||
| # Logging configuration | ||
| [loggers] | ||
| keys = root,sqlalchemy,alembic,flask_migrate | ||
|
|
||
| [handlers] | ||
| keys = console | ||
|
|
||
| [formatters] | ||
| keys = generic | ||
|
|
||
| [logger_root] | ||
| level = WARN | ||
| handlers = console | ||
| qualname = | ||
|
|
||
| [logger_sqlalchemy] | ||
| level = WARN | ||
| handlers = | ||
| qualname = sqlalchemy.engine | ||
|
|
||
| [logger_alembic] | ||
| level = INFO | ||
| handlers = | ||
| qualname = alembic | ||
|
|
||
| [logger_flask_migrate] | ||
| level = INFO | ||
| handlers = | ||
| qualname = flask_migrate | ||
|
|
||
| [handler_console] | ||
| class = StreamHandler | ||
| args = (sys.stderr,) | ||
| level = NOTSET | ||
| formatter = generic | ||
|
|
||
| [formatter_generic] | ||
| format = %(levelname)-5.5s [%(name)s] %(message)s | ||
| datefmt = %H:%M:%S |
Oops, something went wrong.
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.
Thanks for filling this out ❤️ Even if what you listed out mostly stuff you're already doing, it can be really helpful to keep in mind and help make sure folks aren't relying on assumptions about how they will work together.