Skip to content

Commit

Permalink
Merge branch 'statz'
Browse files Browse the repository at this point in the history
  • Loading branch information
tyjsmith1 committed Jan 23, 2024
2 parents 64904f5 + 5e4c167 commit 70bf5b3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,60 @@
# Add your model imports
from models import Users, Recipes, Swipes


# Views go here!

@app.route('/')
def index():
return '<h1>Project Server</h1>'

@app.route('/recipes/<int:id>', methods = ['GET'])
def recipe_by_id(id):
recipe = Recipes.query.filter(Recipes.id == id).first()

if recipe:
response = make_response(
recipe.to_dict(),
200
)
else:
response = make_response(
{ 'error': 'Recipe not found' },
404
)

return response

@app.route('/swipes/<int:id>', methods = ['PATCH'])
def swipe_by_id(id):
swipe = Swipes.query.filter(Swipes.id == id).first()

if swipe:
try:
form_data = request.get_json()

for attr in form_data:
setattr(swipe, attr, form_data[attr])

db.session.commit()

response = make_response(
swipe.to_dict(rules = ('-user', '-recipe')),
202
)
except ValueError:
response = make_response(
{ 'errors': ['validation errors'] },
400
)
else:
response = make_response(
{ 'error': 'Swipe not found' },
404
)

return response

@app.route('/users/<int:id>', methods = ['DELETE'])
def users(id):
user = Users.query.filter(Users.id == id).first()
Expand Down

0 comments on commit 70bf5b3

Please sign in to comment.