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