forked from antonaleks/LinuxPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (27 loc) · 878 Bytes
/
Copy pathapp.py
File metadata and controls
39 lines (27 loc) · 878 Bytes
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
34
35
36
37
38
39
from flask import Flask, request, jsonify
app = Flask(__name__)
# Список для хранения задач в памяти
tasks = []
next_id = 1
@app.route("/tasks", methods=['POST'])
def create_task():
global next_id
data = request.get_json()
description = data['description']
task = {'id': next_id, 'description': description}
tasks.append(task)
next_id += 1
return jsonify(task), 201
@app.route("/tasks", methods=['GET'])
def get_all_tasks():
return jsonify(tasks)
@app.route("/tasks/<int:id>", methods=['PUT'])
def update_task(id):
data = request.get_json()
description = data['description']
for task in tasks:
if task['id'] == id:
task['description'] = description
return jsonify(task)
return jsonify({'error': 'Task is not found'}), 404
app.run(host='0.0.0.0', port=5000)