-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (62 loc) · 2.48 KB
/
app.py
File metadata and controls
75 lines (62 loc) · 2.48 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
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
from src.task_controller import TaskController, TaskNotFoundException
from src.task_factory import TaskFactory
from src.task_view import TaskView
from src.utils.view_utils import ViewUtils
class TaskApp:
def __init__(self, view, factory):
self.view = view
self.factory = factory
def run(self):
while True:
self.view.show_title()
self.handle_user_choice()
def handle_user_choice(self):
choice = self.view.show_menu()
if choice == "1":
self.create_task()
elif choice == "2":
self.list_tasks()
elif choice == "3":
self.mark_task_as_completed()
elif choice == "4":
self.remove_task()
elif choice == "5":
self.display_full_task()
elif choice == "0":
self.exit_application()
return
def create_task(self):
title, description, deadline, urgency_level = self.view.prompt_for_create_task()
self.factory.create_task(title, description, deadline, urgency_level)
def list_tasks(self):
tasks = self.factory.controller.list_tasks()
self.view.display_tasks(tasks)
def mark_task_as_completed(self):
task_id = self.view.prompt_for_task_id()
try:
self.factory.controller.mark_task_as_complete(task_id)
self.view.display_success_message(f"Parabéns! você cumpriu a tarefa {task_id} !")
except TaskNotFoundException:
ViewUtils.display_error(f"Tarefa com ID {task_id} não foi encontrada")
def remove_task(self):
task_id = self.view.prompt_for_task_id()
try:
self.factory.controller.remove_task(task_id)
self.view.display_success_message(f"Tarefa com ID {task_id} removida com sucesso!")
except TaskNotFoundException:
ViewUtils.display_error(f"Tarefa com ID {task_id} não foi encontrada")
def display_full_task(self):
task_id = self.view.prompt_for_task_id()
try:
task = self.factory.controller.get_task_by_id(task_id)
self.view.display_full_task(task)
except TaskNotFoundException:
ViewUtils.display_error(f"Tarefa com ID {task_id} não foi encontrada")
def exit_application(self):
self.view.display_success_message(f"Obrigado, volte sempre!")
sys.exit(0)
task_view = TaskView()
task_factory = TaskFactory()
task_app = TaskApp(task_view, task_factory)
task_app.run()