epr24pr5-ojanssen2/DelCommand.cpp
2025-02-10 00:25:28 +01:00

32 lines
844 B
C++

#include "DelCommand.h"
#include "Error.h"
#include "Manager.h"
using util::Util;
using util::Manager;
using err::Error;
namespace commands
{
DelCommand::DelCommand() : SubCommand("delete", true)
{
}
void DelCommand::run(stringstream& args)
{
Manager* mgr = Manager::get_instance();
const string data_type = Util::read_string(args);
int id;
args >> id;
if (!args)
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
if (data_type == "user")
mgr->del_user(id);
else if (data_type == "task")
// Validate if we can Delete This Task.
mgr->del_task(id);
else
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
mgr->save();
}
} // commands