2025-02-05 12:48:05 +01:00
|
|
|
#include "AddCommand.h"
|
2025-02-09 19:58:55 +01:00
|
|
|
#include "Error.h"
|
|
|
|
#include "Manager.h"
|
2025-02-05 12:48:05 +01:00
|
|
|
|
2025-02-09 19:58:55 +01:00
|
|
|
using util::Manager;
|
|
|
|
using util::Util;
|
|
|
|
using models::AddUser;
|
|
|
|
using models::AddTask;
|
|
|
|
using err::Error;
|
2025-02-05 12:48:05 +01:00
|
|
|
|
2025-02-09 19:58:55 +01:00
|
|
|
namespace commands
|
|
|
|
{
|
|
|
|
AddCommand::AddCommand() : SubCommand("add", 100, true)
|
|
|
|
{
|
2025-02-05 12:48:05 +01:00
|
|
|
}
|
2025-02-09 19:58:55 +01:00
|
|
|
|
2025-02-09 21:14:26 +01:00
|
|
|
void AddCommand::run(stringstream& args)
|
2025-02-09 19:58:55 +01:00
|
|
|
{
|
|
|
|
const string data_type = Util::read_string(args);
|
|
|
|
Manager& mgr = Manager::get_instance();
|
|
|
|
if (data_type == "user")
|
|
|
|
{
|
|
|
|
AddUser u;
|
|
|
|
args >> u;
|
|
|
|
mgr.add_user(new User(u));
|
|
|
|
}
|
|
|
|
else if (data_type == "task")
|
|
|
|
{
|
|
|
|
AddTask t;
|
|
|
|
args >> t;
|
|
|
|
mgr.add_task(new Task(t));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw Error(101, "Befehl ist unbekannt.");
|
|
|
|
mgr.save();
|
|
|
|
}
|
|
|
|
} // commands
|