epr24pr5-ojanssen2/ShowCommand.cpp
2025-02-10 01:01:56 +01:00

43 lines
1.3 KiB
C++

#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