diff --git a/ActiveCommand.cpp b/ActiveCommand.cpp index b155d35..18038ae 100644 --- a/ActiveCommand.cpp +++ b/ActiveCommand.cpp @@ -17,7 +17,7 @@ namespace commands Manager* mgr = Manager::get_instance(); int user_id; args >> user_id; - if (!user_id) + if (!args) throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); const User* u = mgr->get_user(user_id); if (!u) diff --git a/ListCommand.cpp b/ListCommand.cpp index 30dec71..4a08f2b 100644 --- a/ListCommand.cpp +++ b/ListCommand.cpp @@ -29,6 +29,6 @@ namespace commands for (const Assignment* a : mgr->get_assignments()) cout << *a; else - throw Error(101, "Befehl ist unbekannt."); + throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); } } // commands diff --git a/Manager.cpp b/Manager.cpp index be1c422..961db75 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -236,7 +236,7 @@ namespace util if (this->users.count(id) == 0) throw Error(401, "Eine solche BenutzerIn existiert nicht."); //Assigment - if (this->get_assignments_for_user(id).empty()) { + if (!this->get_assignments_for_user(id).empty()) { throw Error(201, "Benutzer kann nicht gelöscht werden."); } this->users.erase(id); @@ -246,7 +246,7 @@ namespace util { if (this->tasks.count(id) == 0) throw Error(402, "Eine solche Aufgabe existiert nicht."); - if (this->get_assignments_for_task(id).empty()) { + if (!this->get_assignments_for_task(id).empty()) { throw Error(201, "Aufgabe kann nicht gelöscht werden."); } this->tasks.erase(id); diff --git a/ShowCommand.cpp b/ShowCommand.cpp index 05c44ac..90424c0 100644 --- a/ShowCommand.cpp +++ b/ShowCommand.cpp @@ -1,36 +1,43 @@ #include "ShowCommand.h" #include "Error.h" -#include "Util.h" #include "Manager.h" +#include "Util.h" +using err::Error; +using models::AddTask; +using models::AddUser; using util::Manager; using util::Util; -using models::AddUser; -using models::AddTask; -using err::Error; -namespace commands -{ - ShowCommand::ShowCommand() : SubCommand("show", false) - { - } +namespace commands { + ShowCommand::ShowCommand() : SubCommand("show", false) {} - void ShowCommand::run(stringstream& args) - { - Manager* mgr = Manager::get_instance(); + void ShowCommand::run(stringstream &args) { + Manager *mgr = Manager::get_instance(); const string data_type = Util::read_string(args); - if (data_type == "user") - for (User* u : mgr->get_users()) { - AddUser au = {*u}; - cout << au; + int show_id; + args >> show_id; + if (!args) + throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); + if (data_type == "user") { + User *user = mgr->get_user(show_id); + if (user == nullptr) { + throw Error(401, "Eine solche BenutzerIn existiert nicht."); } - else if (data_type == "task") - for (Task* t : mgr->get_tasks()) { - AddTask at = {*t}; - cout << at; + AddUser unid_user = {*user}; + cout << unid_user; + + } + + else if (data_type == "task") { + Task *task = mgr->get_task(show_id); + if (task == nullptr) { + throw Error(401, "Eine solche BenutzerIn existiert nicht."); } - else + AddTask unid_task = {*task}; + cout << unid_task; + } else throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); } -} // commands +} // namespace commands diff --git a/User.cpp b/User.cpp index 15ab721..dac1c4b 100644 --- a/User.cpp +++ b/User.cpp @@ -56,7 +56,7 @@ namespace models { } ostream& operator<<(ostream& os, const AddUser& u) { - os << u.get_name() << " " << u.get_surname(); + os << u.get_name() << " " << u.get_surname() << "\n"; return os; } diff --git a/main.cpp b/main.cpp index 4014c5c..abb15f4 100644 --- a/main.cpp +++ b/main.cpp @@ -1,14 +1,15 @@ #pragma once #include "ActiveCommand.h" -#include "std_lib_inc.h" -#include "parameter_reader.h" -#include "HelpCommand.h" #include "AddCommand.h" #include "AssignCommand.h" #include "DelCommand.h" #include "Error.h" +#include "HelpCommand.h" #include "ListCommand.h" +#include "ShowCommand.h" #include "UnassignCommand.h" +#include "parameter_reader.h" +#include "std_lib_inc.h" using commands::SubCommand; using commands::HelpCommand; @@ -18,6 +19,7 @@ using commands::DelCommand; using commands::AssignCommand; using commands::UnassignCommand; using commands::ActiveCommand; +using commands::ShowCommand; using err::Error; const vector handlers = { @@ -28,6 +30,7 @@ const vector handlers = { new AssignCommand(), new UnassignCommand(), new ActiveCommand(), + new ShowCommand(), }; int main(int argc, char** argv)