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();
int user_id;
args >> user_id;
if (!args)
if (!user_id)
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
const User* u = mgr->get_user(user_id);
if (!u)

View file

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

View file

@ -236,7 +236,7 @@ namespace util
if (this->users.count(id) == 0)
throw Error(401, "Eine solche BenutzerIn existiert nicht.");
//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.");
}
this->users.erase(id);
@ -246,16 +246,8 @@ namespace util
{
if (this->tasks.count(id) == 0)
throw Error(402, "Eine solche Aufgabe existiert nicht.");
if (!this->get_assignments_for_task(id).empty()) {
throw Error(202, "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.");
}
}
if (this->get_assignments_for_task(id).empty()) {
throw Error(201, "Aufgabe kann nicht gelöscht werden.");
}
this->tasks.erase(id);
}

View file

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

View file

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