Skip to content

Commit

Permalink
Merge pull request #1 from FrancescaFr/solar-part-1
Browse files Browse the repository at this point in the history
completed wave 2
  • Loading branch information
FrancescaFr authored Oct 28, 2022
2 parents db17225 + 4f70d96 commit fe5fce1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Blueprint, jsonify
from flask import Blueprint, jsonify, abort, make_response

class Planet:
def __init__(self, id, name, description, flag):
Expand All @@ -25,4 +25,24 @@ def list_planets():
description = planet.description,
flag = planet.flag
))
return jsonify(planet_list)
return jsonify(planet_list)

@planet_bp.route("/<id>", methods=["GET"])
def get_planet(id):
planet = validate_planet(id)
return jsonify(dict(
id = planet.id,
name = planet.name,
description = planet.description,
flag = planet.flag,
))

def validate_planet(id):
try:
planet_id = int(id)
except:
abort(make_response({"message": f"planet {id} is invalid"}, 400))
for planet in planets:
if planet.id == planet_id:
return planet
abort(make_response({"message": f"{planet_id} not found"}, 404))

0 comments on commit fe5fce1

Please sign in to comment.