Skip to content

Commit

Permalink
Finishing other endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrajaci committed Jul 22, 2020
1 parent 7ddc17c commit a60b4af
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ def create_store():
@app.route('/store/<string:name>')
def get_store(name):
# Iterate over stores
# If the store name matches, return it
# If none match, return an error message
for store in stores:
# If the store name matches, return it
if store['name'] == name:
return jsonify(store)
# If none match, return an error message
else:
return jsonify({'message': 'store not found'})
pass


Expand All @@ -45,13 +50,27 @@ def get_stores():
# POST /store/<string:name>/item {name:, price:}
@app.route('/store/<string:name>/item', methods=['POST'])
def create_item_in_store(name):
pass
request_data = request.get_json()
for store in stores:
if store['items'] == name:
new_item = {
'name': request_data['name'],
'price': request_data['price']
}
store['items'].append(new_item)
return jsonify(new_item)
else:
return jsonify({'message': 'store not found'})


# GET /store/<string:name>/item
@app.route('/store/<string:name>/item')
def get_item_in_store(name):
pass
for store in stores:
if store['items'] == name:
return jsonify({'items': store['items']})
else:
return jsonify({'message': 'item not found'})


app.run(port=5000)

0 comments on commit a60b4af

Please sign in to comment.