Spaces:
Sleeping
Sleeping
feat: Add example big project solution and submission
Browse files- example_big_project/solution/requirements.txt +1 -0
- example_big_project/solution/src/main.py +32 -0
- example_big_project/solution/src/utils.py +28 -0
- example_big_project/student_submission/requirements.txt +1 -0
- example_big_project/student_submission/src/main.py +10 -0
- example_big_project/student_submission/src/utils.py +1 -0
example_big_project/solution/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Flask==3.0.3
|
example_big_project/solution/src/main.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from utils import create_task, get_all_tasks, complete_task, get_task_by_id
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
@app.route('/tasks', methods=['GET'])
|
| 7 |
+
def retrieve_tasks():
|
| 8 |
+
tasks = get_all_tasks()
|
| 9 |
+
return jsonify({"tasks": tasks}), 200
|
| 10 |
+
|
| 11 |
+
@app.route('/tasks', methods=['POST'])
|
| 12 |
+
def add_task():
|
| 13 |
+
data = request.get_json()
|
| 14 |
+
if not data or 'title' not in data:
|
| 15 |
+
return jsonify({"error": "Missing 'title' in request body"}), 400
|
| 16 |
+
|
| 17 |
+
title = data['title']
|
| 18 |
+
description = data.get('description', '')
|
| 19 |
+
|
| 20 |
+
task = create_task(title, description)
|
| 21 |
+
return jsonify(task), 201
|
| 22 |
+
|
| 23 |
+
@app.route('/tasks/<task_id>/complete', methods=['PUT'])
|
| 24 |
+
def mark_task_complete(task_id):
|
| 25 |
+
task = complete_task(task_id)
|
| 26 |
+
if not task:
|
| 27 |
+
return jsonify({"error": "Task not found"}), 404
|
| 28 |
+
|
| 29 |
+
return jsonify(task), 200
|
| 30 |
+
|
| 31 |
+
if __name__ == '__main__':
|
| 32 |
+
app.run(debug=True)
|
example_big_project/solution/src/utils.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import uuid
|
| 2 |
+
|
| 3 |
+
# In-memory storage for tasks
|
| 4 |
+
tasks_db = {}
|
| 5 |
+
|
| 6 |
+
def create_task(title, description=""):
|
| 7 |
+
task_id = str(uuid.uuid4())
|
| 8 |
+
task = {
|
| 9 |
+
"id": task_id,
|
| 10 |
+
"title": title,
|
| 11 |
+
"description": description,
|
| 12 |
+
"completed": False
|
| 13 |
+
}
|
| 14 |
+
tasks_db[task_id] = task
|
| 15 |
+
return task
|
| 16 |
+
|
| 17 |
+
def get_all_tasks():
|
| 18 |
+
return list(tasks_db.values())
|
| 19 |
+
|
| 20 |
+
def get_task_by_id(task_id):
|
| 21 |
+
return tasks_db.get(task_id)
|
| 22 |
+
|
| 23 |
+
def complete_task(task_id):
|
| 24 |
+
task = tasks_db.get(task_id)
|
| 25 |
+
if task:
|
| 26 |
+
task["completed"] = True
|
| 27 |
+
return task
|
| 28 |
+
return None
|
example_big_project/student_submission/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Flask==3.0.3
|
example_big_project/student_submission/src/main.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
|
| 5 |
+
# TODO: Implement the GET /tasks endpoint
|
| 6 |
+
# TODO: Implement the POST /tasks endpoint
|
| 7 |
+
# TODO: Implement the PUT /tasks/<task_id>/complete endpoint
|
| 8 |
+
|
| 9 |
+
if __name__ == '__main__':
|
| 10 |
+
app.run(debug=True)
|
example_big_project/student_submission/src/utils.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# TODO: Implement business logic and data storage for tasks here
|