forked from University/epr24pr5-ojanssen2
33 lines
994 B
C++
33 lines
994 B
C++
|
#include "UnassignCommand.h"
|
||
|
#include "Error.h"
|
||
|
#include "Manager.h"
|
||
|
|
||
|
using util::Manager;
|
||
|
using err::Error;
|
||
|
|
||
|
namespace commands
|
||
|
{
|
||
|
UnassignCommand::UnassignCommand() : SubCommand("unassign", 100, true)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void UnassignCommand::run(int argc, stringstream& args)
|
||
|
{
|
||
|
Manager& mgr = Manager::get_instance();
|
||
|
int user_id, task_id;
|
||
|
args >> user_id >> task_id;
|
||
|
if (!args)
|
||
|
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
|
||
|
const User* u = mgr.get_user(user_id);
|
||
|
if (!u)
|
||
|
throw Error(401, "Eine solche BenutzerIn existiert nicht.");
|
||
|
const Task* t = mgr.get_task(task_id);
|
||
|
if (!t)
|
||
|
throw Error(401, "Eine solche Zuordnung existiert nicht.");
|
||
|
if (!mgr.assignment_exists(user_id, task_id))
|
||
|
throw Error(302, "Eine solche Zuordnung existiert bereits.");
|
||
|
mgr.del_assignment({user_id, task_id});
|
||
|
mgr.save();
|
||
|
}
|
||
|
} // commands
|