Skip to content

Commit

Permalink
Bugfix: AddTask is a command, not an event
Browse files Browse the repository at this point in the history
  • Loading branch information
NateMeyvis committed Jun 5, 2022
1 parent 4f98fe8 commit bf64e12
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions main.py
Expand Up @@ -7,72 +7,72 @@
from objects.task import CompletionStatus, Task
from repositories.helpers.helpers import mark_complete
from objects.commands import AddTask, Command
from objects.events import Event, TaskCompletion
from objects.events import Event
from repositories.coordinator_repository import SQLiteCoordinatorRepository
from repositories.task_repository import TaskRepository, SQLiteTaskRepository

task_repo = SQLiteTaskRepository("tasks.db")
coordinator_repo = SQLiteCoordinatorRepository("tasks.db")


def task_adder(add_task_event: AddTask):
task_repo.add_task(event.task)
if event.coordinator is not None:
def task_adder(add_task_command: AddTask):
task_repo.add_task(add_task_command.task)
if add_task_command.reschedule_interval is not None:
raise NotImplementedError


def event_handler(event: Event):
if isinstance(event, AddTask):
task_adder(event)
def command_handler(command: Command):
if isinstance(command, AddTask):
task_adder(command)
else:
raise NotImplementedError


@route("/")
def list_tasks(task_repository: TaskRepository = task_repo):
def list_tasks():
active = [
task
for task in task_repository.get_all_tasks()
for task in task_repo.get_all_tasks()
if task.status == CompletionStatus.OUTSTANDING
]
return task_display(active)


@route("/add")
def add_task(task_repository: TaskRepository = task_repo):
def add_task():
return task_display(
[
task
for task in task_repository.get_all_tasks()
for task in task_repo.get_all_tasks()
if task.status == CompletionStatus.OUTSTANDING
]
)


@route("/add", method="POST")
def proc_add_task(task_repository: TaskRepository = task_repo):
def proc_add_task():
description = request.forms.get("description")
due = (
datetime.fromisoformat(request.forms.get("due"))
if request.forms.get("due")
else None
)
task_repository.add_task(Task(description=description, due=due))
task_repo.add_task(Task(description=description, due=due))
redirect("/add")


@route("/complete/<uuid_str>", method="POST")
def proc_complete_task(uuid_str: str, task_repository: TaskRepository = task_repo):
mark_complete(task_repository, UUID(uuid_str))
def proc_complete_task(uuid_str: str):
mark_complete(task_repo, UUID(uuid_str))
redirect("/add")


@route("/kick/<uuid_str>", method="POST")
def proc_kick_task(uuid_str: str, task_repository: TaskRepository = task_repo):
def proc_kick_task(uuid_str: str):
# Supports only the default for now
task = task_repository.retrieve_task_by_uuid(UUID(uuid_str))
task = task_repo.retrieve_task_by_uuid(UUID(uuid_str))
task.kick()
task_repository.update_task(task)
task_repo.update_task(task)
redirect("/add")


Expand Down

0 comments on commit bf64e12

Please sign in to comment.