Compare commits

..

No commits in common. "a8d390ffe39aaa9eea79c8771b6277a2027b49da" and "c7ec2ea80d2a4c5ae8e6c363172759364c7f8e99" have entirely different histories.

6 changed files with 31 additions and 49 deletions

View file

@ -17,7 +17,7 @@ namespace commands
Manager* mgr = Manager::get_instance(); Manager* mgr = Manager::get_instance();
int user_id; int user_id;
args >> user_id; args >> user_id;
if (!args) if (!user_id)
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
const User* u = mgr->get_user(user_id); const User* u = mgr->get_user(user_id);
if (!u) if (!u)

View file

@ -29,6 +29,6 @@ namespace commands
for (const Assignment* a : mgr->get_assignments()) for (const Assignment* a : mgr->get_assignments())
cout << *a; cout << *a;
else else
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); throw Error(101, "Befehl ist unbekannt.");
} }
} // commands } // commands

View file

@ -236,7 +236,7 @@ namespace util
if (this->users.count(id) == 0) if (this->users.count(id) == 0)
throw Error(401, "Eine solche BenutzerIn existiert nicht."); throw Error(401, "Eine solche BenutzerIn existiert nicht.");
//Assigment //Assigment
if (!this->get_assignments_for_user(id).empty()) { if (this->get_assignments_for_user(id).empty()) {
throw Error(201, "Benutzer kann nicht gelöscht werden."); throw Error(201, "Benutzer kann nicht gelöscht werden.");
} }
this->users.erase(id); this->users.erase(id);
@ -246,16 +246,8 @@ namespace util
{ {
if (this->tasks.count(id) == 0) if (this->tasks.count(id) == 0)
throw Error(402, "Eine solche Aufgabe existiert nicht."); throw Error(402, "Eine solche Aufgabe existiert nicht.");
if (!this->get_assignments_for_task(id).empty()) { if (this->get_assignments_for_task(id).empty()) {
throw Error(202, "Aufgabe kann nicht gelöscht werden."); throw Error(201, "Aufgabe kann nicht gelöscht werden.");
}
//TODO: Zudem kann eine Aufgabe nur gelöscht werden, wenn Sie nicht Nachfolgerin einer anderen Aufgabe ist -> Ensure its no Child
for (Task* task : this->get_tasks()) {
for (int child_id : task->get_children()) {
if (id == child_id) {
throw Error(202, "Aufgabe kann nicht gelöscht werden.");
}
}
} }
this->tasks.erase(id); this->tasks.erase(id);
} }

View file

@ -1,43 +1,36 @@
#include "ShowCommand.h" #include "ShowCommand.h"
#include "Error.h" #include "Error.h"
#include "Manager.h"
#include "Util.h" #include "Util.h"
#include "Manager.h"
using err::Error;
using models::AddTask;
using models::AddUser;
using util::Manager; using util::Manager;
using util::Util; using util::Util;
using models::AddUser;
using models::AddTask;
using err::Error;
namespace commands { namespace commands
ShowCommand::ShowCommand() : SubCommand("show", false) {} {
ShowCommand::ShowCommand() : SubCommand("show", false)
{
}
void ShowCommand::run(stringstream &args) { void ShowCommand::run(stringstream& args)
Manager *mgr = Manager::get_instance(); {
Manager* mgr = Manager::get_instance();
const string data_type = Util::read_string(args); const string data_type = Util::read_string(args);
int show_id; if (data_type == "user")
args >> show_id; for (User* u : mgr->get_users()) {
if (!args) AddUser au = {*u};
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); cout << au;
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}; else if (data_type == "task")
cout << unid_user; for (Task* t : mgr->get_tasks()) {
AddTask at = {*t};
} cout << at;
else if (data_type == "task") {
Task *task = mgr->get_task(show_id);
if (task == nullptr) {
throw Error(401, "Eine solche BenutzerIn existiert nicht.");
} }
AddTask unid_task = {*task}; else
cout << unid_task;
} else
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
} }
} // namespace commands } // commands

View file

@ -56,7 +56,7 @@ namespace models {
} }
ostream& operator<<(ostream& os, const AddUser& u) { ostream& operator<<(ostream& os, const AddUser& u) {
os << u.get_name() << " " << u.get_surname() << "\n"; os << u.get_name() << " " << u.get_surname();
return os; return os;
} }

View file

@ -1,15 +1,14 @@
#pragma once #pragma once
#include "ActiveCommand.h" #include "ActiveCommand.h"
#include "std_lib_inc.h"
#include "parameter_reader.h"
#include "HelpCommand.h"
#include "AddCommand.h" #include "AddCommand.h"
#include "AssignCommand.h" #include "AssignCommand.h"
#include "DelCommand.h" #include "DelCommand.h"
#include "Error.h" #include "Error.h"
#include "HelpCommand.h"
#include "ListCommand.h" #include "ListCommand.h"
#include "ShowCommand.h"
#include "UnassignCommand.h" #include "UnassignCommand.h"
#include "parameter_reader.h"
#include "std_lib_inc.h"
using commands::SubCommand; using commands::SubCommand;
using commands::HelpCommand; using commands::HelpCommand;
@ -19,7 +18,6 @@ using commands::DelCommand;
using commands::AssignCommand; using commands::AssignCommand;
using commands::UnassignCommand; using commands::UnassignCommand;
using commands::ActiveCommand; using commands::ActiveCommand;
using commands::ShowCommand;
using err::Error; using err::Error;
const vector<SubCommand*> handlers = { const vector<SubCommand*> handlers = {
@ -30,7 +28,6 @@ const vector<SubCommand*> handlers = {
new AssignCommand(), new AssignCommand(),
new UnassignCommand(), new UnassignCommand(),
new ActiveCommand(), new ActiveCommand(),
new ShowCommand(),
}; };
int main(int argc, char** argv) int main(int argc, char** argv)