|
|
|
|
@ -24,10 +24,6 @@ cursor = mydb.cursor()
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app)
|
|
|
|
|
|
|
|
|
|
@app.put('/')
|
|
|
|
|
def test():
|
|
|
|
|
return 'hi'
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
|
|
|
def show_all():
|
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id IS NULL')
|
|
|
|
|
@ -51,12 +47,8 @@ def create():
|
|
|
|
|
)
|
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
@app.post("/<int:id>")
|
|
|
|
|
@app.put("/<int:id>")
|
|
|
|
|
def deleteUpdate(id):
|
|
|
|
|
# TODO: deal with deleting item that has children
|
|
|
|
|
if request.args.get('_method') == 'DELETE':
|
|
|
|
|
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
|
|
|
|
|
else:
|
|
|
|
|
cursor.execute(
|
|
|
|
|
'UPDATE items SET title=%s, description=%s, parent_id=%s WHERE id=%s',
|
|
|
|
|
[request.form['title'], request.form['description'], request.form['parent_id'] if request.form['parent_id'] != '' else None, id]
|
|
|
|
|
@ -66,6 +58,15 @@ def deleteUpdate(id):
|
|
|
|
|
else:
|
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
@app.delete('/<int:id>')
|
|
|
|
|
def delete(id):
|
|
|
|
|
# TODO: deal with deleting item that has children
|
|
|
|
|
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
|
|
|
|
|
if 'parent_id' in request.form:
|
|
|
|
|
return redirect('/'+request.form['parent_id'])
|
|
|
|
|
else:
|
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
@app.get("/<id>")
|
|
|
|
|
def show(id):
|
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
|
|