forked from University/epr24pr5-ojanssen2
Fix Show Command/List command. AddUser Output
This commit is contained in:
parent
c7ec2ea80d
commit
7a35c951ed
6 changed files with 40 additions and 30 deletions
|
@ -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 (!user_id)
|
if (!args)
|
||||||
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)
|
||||||
|
|
|
@ -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(101, "Befehl ist unbekannt.");
|
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
|
||||||
}
|
}
|
||||||
} // commands
|
} // commands
|
||||||
|
|
|
@ -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,7 +246,7 @@ 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(201, "Aufgabe kann nicht gelöscht werden.");
|
throw Error(201, "Aufgabe kann nicht gelöscht werden.");
|
||||||
}
|
}
|
||||||
this->tasks.erase(id);
|
this->tasks.erase(id);
|
||||||
|
|
|
@ -1,36 +1,43 @@
|
||||||
#include "ShowCommand.h"
|
#include "ShowCommand.h"
|
||||||
|
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include "Util.h"
|
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
|
#include "Util.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);
|
||||||
if (data_type == "user")
|
int show_id;
|
||||||
for (User* u : mgr->get_users()) {
|
args >> show_id;
|
||||||
AddUser au = {*u};
|
if (!args)
|
||||||
cout << au;
|
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.");
|
||||||
}
|
}
|
||||||
else if (data_type == "task")
|
AddUser unid_user = {*user};
|
||||||
for (Task* t : mgr->get_tasks()) {
|
cout << unid_user;
|
||||||
AddTask at = {*t};
|
|
||||||
cout << at;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
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};
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
} // commands
|
} // namespace commands
|
||||||
|
|
2
User.cpp
2
User.cpp
|
@ -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();
|
os << u.get_name() << " " << u.get_surname() << "\n";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
main.cpp
9
main.cpp
|
@ -1,14 +1,15 @@
|
||||||
#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;
|
||||||
|
@ -18,6 +19,7 @@ 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 = {
|
||||||
|
@ -28,6 +30,7 @@ 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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue