From ca572b6fb542d5095f8a41c649e1f41496f81700 Mon Sep 17 00:00:00 2001 From: jbrass Date: Mon, 10 Feb 2025 14:41:13 +0100 Subject: [PATCH] Show Active Command. is_active Method for Taks --- ActiveCommand.cpp | 8 ++++++-- Manager.cpp | 6 +++++- Task.cpp | 23 ++++++++++++++++++++--- Task.h | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ActiveCommand.cpp b/ActiveCommand.cpp index 18038ae..54ce5f0 100644 --- a/ActiveCommand.cpp +++ b/ActiveCommand.cpp @@ -22,7 +22,11 @@ namespace commands const User* u = mgr->get_user(user_id); if (!u) throw Error(401, "Eine solche BenutzerIn existiert nicht."); - for (const Assignment* a : mgr->get_assignments_for_user(user_id)) - cout << a->get_task_id() << "\n"; + for (const Assignment* a : mgr->get_assignments_for_user(user_id)) { + //Ist der Related Task ein Aktiver Task? + if (mgr->get_task(a->get_task_id())->is_active()) { + cout << a->get_task_id() << "\n"; + } + } } } // commands diff --git a/Manager.cpp b/Manager.cpp index 5abdd35..d69424e 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -250,12 +250,16 @@ namespace util throw Error(202, "Aufgabe kann nicht gelöscht werden."); } //TODO: Zudem kann eine Aufgabe nur gelöscht werden, wenn Sie nicht Nachfolgerin einer anderen Aufgabe ist -> Ensure its no Child - for (Task* task : this->get_tasks()) { + /*for (Task* task : this->get_tasks()) { for (int child_id : task->get_children()) { if (id == child_id) { throw Error(202, "Aufgabe kann nicht gelöscht werden."); } } + }*/ + if (! this->get_task(id)->is_active()) { + throw Error(202, "Aufgabe kann nicht gelöscht werden."); + } this->tasks.erase(id); } diff --git a/Task.cpp b/Task.cpp index 9966e45..0d9ca83 100644 --- a/Task.cpp +++ b/Task.cpp @@ -31,9 +31,26 @@ namespace models return stream; } - int Task::get_id() const - { - return this->id; + int Task::get_id() const { return this->id; } + + /** + * Diese Methode überprüft ob der Task Aktiv ist ( Nicht Nachfolger einer anderen Klass ist) + * @return bool + */ + bool Task::is_active() const { + + Manager* mgr = Manager::get_instance(); + for (Task* task : mgr->get_tasks()) { + for (int child_id : task->get_children()) { + // Aktiver Task ist Child von Einem andern Task -> Nicht aktiv + if (this->id == child_id) { + // cout << this->id << " = " << child_id << endl; + return false; + } + } + } + //Kein Child-> Aktiv + return true; } string Task::get_name() const diff --git a/Task.h b/Task.h index 24cb492..ed3f723 100644 --- a/Task.h +++ b/Task.h @@ -28,6 +28,7 @@ namespace models istream& read(istream&); int get_id() const; + bool is_active() const; string get_name() const; string get_description() const; vector get_children() const;