#include "ShowCommand.h" #include "Error.h" #include "Manager.h" #include "Util.h" using err::Error; using models::AddTask; using models::AddUser; using util::Manager; using util::Util; namespace commands { ShowCommand::ShowCommand() : SubCommand("show", false) {} void ShowCommand::run(stringstream &args) { Manager *mgr = Manager::get_instance(); const string data_type = Util::read_string(args); 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."); } AddUser unid_user = {*user}; cout << unid_user; } else if (data_type == "task") { Task *task = mgr->get_task(show_id); if (task == nullptr) { throw Error(402, "Eine solche Aufgabe existiert nicht."); } AddTask unid_task = {*task}; cout << unid_task; } else throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); } } // namespace commands