diff --git a/server.py b/server.py index d268917..32a11e8 100644 --- a/server.py +++ b/server.py @@ -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,16 +47,21 @@ def create(): ) return redirect('/') -@app.post("/") +@app.put("/") 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]) + 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] + ) + if 'parent_id' in request.form: + return redirect('/'+request.form['parent_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] - ) + return redirect('/') + +@app.delete('/') +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: