Spaces:
Sleeping
Sleeping
File size: 913 Bytes
badfe02 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from flask import Flask, request, jsonify
from utils import create_task, get_all_tasks, complete_task, get_task_by_id
app = Flask(__name__)
@app.route('/tasks', methods=['GET'])
def retrieve_tasks():
tasks = get_all_tasks()
return jsonify({"tasks": tasks}), 200
@app.route('/tasks', methods=['POST'])
def add_task():
data = request.get_json()
if not data or 'title' not in data:
return jsonify({"error": "Missing 'title' in request body"}), 400
title = data['title']
description = data.get('description', '')
task = create_task(title, description)
return jsonify(task), 201
@app.route('/tasks/<task_id>/complete', methods=['PUT'])
def mark_task_complete(task_id):
task = complete_task(task_id)
if not task:
return jsonify({"error": "Task not found"}), 404
return jsonify(task), 200
if __name__ == '__main__':
app.run(debug=True)
|