Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from flask import Flask, jsonify, request, abort
from flask import Flask, jsonify, request, abort, render_template
from uuid import uuid4

app = Flask(__name__)

# In-memory product store
data = {}

@app.route('/')
def index():
return render_template('index.html')

@app.route('/products', methods=['GET'])
def get_products():
return jsonify(list(data.values())), 200
Expand All @@ -23,7 +27,7 @@ def create_product():
if not body or 'name' not in body:
abort(400)
product_id = str(uuid4())
product = {'id': product_id, 'name': body['name'], 'description': body.get('description', '')}
product = {'id': product_id, 'name': body['name'], 'description': body.get('description', ''), 'category': body.get('category', '')}
data[product_id] = product
return jsonify(product), 201

Expand All @@ -34,7 +38,7 @@ def update_product(product_id):
body = request.get_json()
if not body or 'name' not in body:
abort(400)
data[product_id].update({'name': body['name'], 'description': body.get('description', '')})
data[product_id].update({'name': body['name'], 'description': body.get('description', ''), 'category': body.get('category', '')})
return jsonify(data[product_id]), 200

@app.route('/products/<product_id>', methods=['DELETE'])
Expand Down
Loading