Farben der Habits wälbarmachen
This commit is contained in:
23
app.py
23
app.py
@@ -32,7 +32,8 @@ def get_habits():
|
||||
current_habit_data = {
|
||||
'id': habit_doc.doc_id,
|
||||
'name': habit_doc.get('name'),
|
||||
'completed_dates': habit_doc.get('completed_dates', [])
|
||||
'completed_dates': habit_doc.get('completed_dates', []),
|
||||
'color': habit_doc.get('color', '#4CAF50')
|
||||
}
|
||||
|
||||
completion_history = {}
|
||||
@@ -48,11 +49,12 @@ def get_habits():
|
||||
def add_habit():
|
||||
data = request.json
|
||||
name = data.get('name')
|
||||
color = data.get('color', '#4CAF50') # Default green color
|
||||
if not name:
|
||||
return jsonify({'error': 'Habit name is required'}), 400
|
||||
|
||||
habit_id = db.insert({'name': name, 'completed_dates': []})
|
||||
return jsonify({'id': habit_id, 'name': name, 'completed_dates': []}), 201
|
||||
habit_id = db.insert({'name': name, 'completed_dates': [], 'color': color})
|
||||
return jsonify({'id': habit_id, 'name': name, 'completed_dates': [], 'color': color}), 201
|
||||
|
||||
@app.route('/habits/<int:habit_id>/complete', methods=['POST'])
|
||||
def complete_habit(habit_id):
|
||||
@@ -86,16 +88,23 @@ def uncomplete_habit(habit_id):
|
||||
def update_habit(habit_id):
|
||||
data = request.json
|
||||
name = data.get('name')
|
||||
color = data.get('color')
|
||||
|
||||
if not name:
|
||||
return jsonify({'error': 'Habit name is required'}), 400
|
||||
if not name and not color:
|
||||
return jsonify({'error': 'Habit name or color is required'}), 400
|
||||
|
||||
habit = db.get(doc_id=habit_id)
|
||||
if not habit:
|
||||
return jsonify({'error': 'Habit not found'}), 404
|
||||
|
||||
db.update({'name': name}, doc_ids=[habit_id])
|
||||
return jsonify({'message': f'Habit {habit_id} updated', 'name': name})
|
||||
update_data = {}
|
||||
if name:
|
||||
update_data['name'] = name
|
||||
if color:
|
||||
update_data['color'] = color
|
||||
|
||||
db.update(update_data, doc_ids=[habit_id])
|
||||
return jsonify({'message': f'Habit {habit_id} updated', **update_data})
|
||||
|
||||
@app.route('/habits/<int:habit_id>', methods=['DELETE'])
|
||||
def delete_habit(habit_id):
|
||||
|
||||
Reference in New Issue
Block a user