-
Notifications
You must be signed in to change notification settings - Fork 428
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
Phoenix-Liubov_Davidova-Anh_Tran #63
Open
momofAnAl
wants to merge
36
commits into
AdaGold:main
Choose a base branch
from
momofAnAl: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.
+479
−5
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
fe0c62a
Finish wave 1 together
momofAnAl 67a0ce7
cann't resolve conflict
LiubovDav 1322e3f
Working on resolve conflict
LiubovDav fa4fef4
Conflict resolved
momofAnAl 9e89a7c
Merge branch 'main' of https://github.com/momofAnAl/solar-system-api
momofAnAl 3165fdf
Resolved conflict
momofAnAl 763417e
Resolved conflicts
momofAnAl 2eb21ed
Working on resolve conflict
LiubovDav 1f9484f
Working on resolve conflict
LiubovDav 6945df6
Update get one planet and handeling errors
momofAnAl 240d490
Created do_dict function and return in planet_id
momofAnAl ce5ab0d
adding code 200 in line 23 of routes
momofAnAl c42ffb3
Fix the typo on validate and add diameter and number_of_moons to attr…
momofAnAl 40d6289
Adding Pluto
momofAnAl 32cb34a
using to_dict() in get_all_planets and update list comprehension
momofAnAl 7a86581
create base and db. Update migration and connect db Planet model gene…
momofAnAl 52c0b7d
create POST request for Planet table and add 3 planets
momofAnAl af930b6
Create get method for all planets
momofAnAl 13ff70f
Nothing changed
LiubovDav bfd35df
resolvled conflict
LiubovDav 1a2fd50
remove id in POST method
momofAnAl ab90026
create get single planet, update and deleted
LiubovDav 91a07db
there were nothing change
momofAnAl c2c89a6
Merge branch 'main' of https://github.com/momofAnAl/solar-system-api
momofAnAl c28922e
Update get all planets with add query params for description and numb…
momofAnAl 461683d
change the .get[] to .get()
momofAnAl 6516233
Update the query for number_of_moons_param that take record set for n…
momofAnAl 7bccff0
Create tests environment and update all unit tests and conftest.py
momofAnAl 026ee76
changing the name for test in database variable name in .env and conf…
momofAnAl ae2d925
change the name of model file to macth the name of class. Remove the …
momofAnAl c9a39df
change name of column to diameter_in-km
momofAnAl 50f3748
return 2 planets in two_saved_planets
momofAnAl 3020969
update tests id after return the values of two planets
momofAnAl 343eb55
change the name of clumn diameter
momofAnAl 062e52e
delete migration folder
momofAnAl 6bfb32b
install gunicorn and add to requirements.txt
momofAnAl 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
create get single planet, update and deleted
commit ab90026f5b6fe77c57c7c308ef998b5463c47f5a
There are no files selected for viewing
This file contains 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,4 +1,4 @@ | ||
from flask import Blueprint, abort, make_response, request | ||
from flask import Blueprint, abort, make_response, request, Response | ||
from app.models.planets import Planet | ||
from ..db import db | ||
|
||
|
@@ -28,7 +28,57 @@ def get_all_planets(): | |
response_body = [planet.to_dict() for planet in planets] | ||
|
||
return response_body, 200 | ||
|
||
|
||
@planet_bp.get("/<planet_id>") | ||
def get_single_planet(planet_id): | ||
planet = validate_planet(planet_id) | ||
|
||
return planet.to_dict() | ||
|
||
|
||
def validate_planet(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 {planet_id} not found" | ||
} | ||
abort(make_response(response, 404)) | ||
|
||
return planet | ||
|
||
@planet_bp.put("/<planet_id>") | ||
def update_single_planet(planet_id): | ||
planet = validate_planet(planet_id) | ||
request_body = request.get_json() | ||
|
||
planet.name = request_body["name"] | ||
planet.description = request_body["description"] | ||
planet.diameter = request_body["diameter"] | ||
planet.number_of_moons = request_body["number_of_moons"] | ||
|
||
db.session.commit() | ||
|
||
return Response(status=204, mimetype='application/json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 This is how we say there's no content in the response, but even still, we should keep our type consistently as json for all our endpoints. |
||
|
||
@planet_bp.delete("/<planet_id>") | ||
def delete_single_planet(planet_id): | ||
planet = validate_planet(planet_id) | ||
|
||
db.session.delete(planet) | ||
db.session.commit() | ||
|
||
return Response(status=204, mimetype='application/json') | ||
|
||
|
||
|
||
|
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.
Similar problems as for creating a record could happen here as well. What might we want to check for, and how might we respond?