-
Notifications
You must be signed in to change notification settings - Fork 242
/
app_service.py
51 lines (42 loc) · 1.37 KB
/
app_service.py
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
import json
class AppService:
tasks = [
{
'id': 1,
'name': "task1",
"description": "This is task 1"
},
{
"id": 2,
"name": "task2",
"description": "This is task 2"
},
{
"id": 3,
"name": "task3",
"description": "This is task 3"
}
]
def __init__(self):
self.tasksJSON = json.dumps(self.tasks)
def get_tasks(self):
return self.tasksJSON
def create_task(self,task):
tasksData = json.loads(self.tasksJSON)
tasksData.append(task)
self.tasksJSON = json.dumps(tasksData)
return self.tasksJSON
def update_task(self, request_task):
tasksData = json.loads(self.tasksJSON)
for task in tasksData:
if task["id"] == request_task['id']:
task.update(request_task)
return json.dumps(tasksData);
return json.dumps({'message': 'task id not found'});
def delete_task(self, request_task_id):
tasksData = json.loads(self.tasksJSON)
for task in tasksData:
if task["id"] == request_task_id:
tasksData.remove(task)
return json.dumps(tasksData);
return json.dumps({'message': 'task id not found'});