-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (50 loc) · 1.55 KB
/
app.py
File metadata and controls
61 lines (50 loc) · 1.55 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask, request, jsonify
import json
app = Flask(__name__)
tasks = [
{
'id':0,
'responsável':'Matheus',
'tarefa':'Listar tarefas da API',
'status':'Ok'
},
{
'id':1,
'responsável':'Fernando',
'tarefa':'Gerenciamento de Tarefas',
'status':'Ok'
}
]
# To List and Add new tasks
@app.route('/lisad/', methods=['POST', 'GET'])
def listAndAdd():
if request.method == 'POST':
taskData = json.loads(request.data)
position = len(tasks)
taskData['id'] = position
tasks.append(taskData)
return jsonify(tasks[position])
elif request.method == 'GET':
return jsonify(tasks)
@app.route('/lisad/<int:task_id>/', methods=['GET', 'PUT', 'DELETE'])
def idAlt(task_id):
task = next((task for task in tasks if task['id'] == task_id), None)
if task is None:
return jsonify({"status":"This task don't exists"}), 400
if request.method == 'GET':
return jsonify(task), 200
elif request.method == 'PUT':
taskData = request.get_json()
taskData = json.loads(request.data)
if 'status' in taskData:
task['status'] = taskData['status']
return jsonify({"status": "Item atualizado com sucesso"}), 200
else:
pass
elif request.method == 'DELETE':
tasks.remove(task)
return jsonify({"status":"Item excluído com sucesso"})
else:
return jsonify({"status":"ERROR"})
if __name__ == '__main__':
app.run()