Skip to content

Commit

Permalink
Added post and get to pet routes
Browse files Browse the repository at this point in the history
  • Loading branch information
apradoada committed Dec 6, 2024
1 parent 2da90b8 commit 66174e2
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions app/routes/pet_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,26 @@
bp = Blueprint("pets", __name__, url_prefix="/pets")

@bp.post("")
def add_pets():
pass
def create_pet():
request_body = request.get_json()
try:
new_pet = Pet.from_dict(request_body)
db.session.add(new_pet)
db.session.commit()

return make_response(new_pet.to_dict(), 201)

except KeyError as e:
abort(make_response({"message": f"missing required value: {e}"}, 400))

@bp.get("")
def get_pets():
pet_query = db.select(Pet)

pets = db.session.scalars(pet_query)
response = []

for pet in pets:
response.append(pet.to_dict())

return jsonify(response)

0 comments on commit 66174e2

Please sign in to comment.