create list interactivity
This commit is contained in:
14
src/app.py
14
src/app.py
@ -11,14 +11,14 @@ CORS(app)
|
||||
def serve_index():
|
||||
return render_template('app.html')
|
||||
|
||||
@app.route('/app/init', methods = ['GET'])
|
||||
@app.route('/init', methods = ['GET'])
|
||||
def init_db():
|
||||
status = check_schema()
|
||||
if not status:
|
||||
initialize()
|
||||
return str(status)
|
||||
|
||||
@app.route('/app/update', methods = ['GET'])
|
||||
@app.route('/update', methods = ['GET'])
|
||||
def update_hist():
|
||||
print("update")
|
||||
update_items()
|
||||
@ -69,8 +69,14 @@ def createList():
|
||||
data = request.get_json()
|
||||
name = data.get('name')
|
||||
description = data.get('description')
|
||||
create_list(name, description)
|
||||
return jsonify({'created list ': name}), 200
|
||||
items = data.get('items')
|
||||
list_uuid = create_list(name, description)
|
||||
if list_uuid:
|
||||
for item in items.split('#'):
|
||||
add_to_list(list_uuid, item)
|
||||
return jsonify({'created list ': name}), 200
|
||||
else:
|
||||
return jsonify({'create failed': name}), 400
|
||||
|
||||
@app.route('/app/add-to-list', methods=['POST'])
|
||||
def addToList():
|
||||
|
31
src/db.py
31
src/db.py
@ -164,19 +164,38 @@ def delete_item(uuid):
|
||||
def create_list(name, description):
|
||||
'''
|
||||
initialize an itemlist in the database
|
||||
return list uuid
|
||||
return None if a list with this name already exist
|
||||
'''
|
||||
if len(name) <= 50:
|
||||
connection = connect_db()
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
INSERT INTO itemlist (uuid, name, description)
|
||||
VALUES (nextval('uuid_list_sequence'), %s, %s)
|
||||
""", (name, description))
|
||||
SELECT uuid
|
||||
FROM itemlist
|
||||
WHERE name = %s
|
||||
""", (name,))
|
||||
|
||||
result = cursor.rowcount
|
||||
|
||||
if result == 0:
|
||||
cursor.execute("""
|
||||
INSERT INTO itemlist (uuid, name, description)
|
||||
VALUES (nextval('uuid_list_sequence'), %s, %s)
|
||||
""", (name, description))
|
||||
cursor.execute("""
|
||||
SELECT uuid
|
||||
FROM itemlist
|
||||
WHERE name = %s
|
||||
""", (name,))
|
||||
result = cursor.fetchall()[0][0]
|
||||
else:
|
||||
result = None
|
||||
|
||||
connection.commit()
|
||||
connection.close()
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
return result
|
||||
|
||||
def add_to_list(list_uuid, item_uuid):
|
||||
'''
|
||||
|
Reference in New Issue
Block a user