/** * @param TodoWasMarkedAsDone $event * @throws \RuntimeException if data of the the assigned user can not be found */ public function onTodoWasMarkedAsDone(TodoWasMarkedAsDone $event) { $user = $this->userFinder->findUserOfTodo($event->todoId()->toString()); if (!$user) { throw new \RuntimeException(sprintf("Data of the assigned user of the todo %s cannot be found", $event->todoId()->toString())); } $stmt = $this->connection->prepare(sprintf('UPDATE %s SET open_todos = open_todos - 1, done_todos = done_todos + 1 WHERE id = :assignee_id', Table::USER)); $stmt->bindValue('assignee_id', $user->id); $stmt->execute(); }
/** * @param TodoWasUnmarkedAsExpired $event * @throws UserNotFound if data of the the assigned user can not be found */ public function onTodoWasUnmarkedAsExpired(TodoWasUnmarkedAsExpired $event) { $user = $this->userFinder->findUserOfTodo($event->todoId()->toString()); if (!$user) { throw new UserNotFound(sprintf("Data of the assigned user of the todo %s cannot be found", $event->todoId()->toString())); } $stmt = $this->connection->prepare(sprintf('UPDATE %s SET open_todos = open_todos + 1, expired_todos = expired_todos - 1 WHERE id = :assignee_id', Table::USER)); $stmt->bindValue('assignee_id', $user->id); $stmt->execute(); }