Fix Show Command/List command. AddUser Output

This commit is contained in:
jbrass 2025-02-10 00:49:31 +01:00
parent c7ec2ea80d
commit 7a35c951ed
6 changed files with 40 additions and 30 deletions

View file

@ -17,7 +17,7 @@ namespace commands
Manager* mgr = Manager::get_instance();
int user_id;
args >> user_id;
if (!user_id)
if (!args)
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(101, "Befehl ist unbekannt.");
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
}
} // 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,7 +246,7 @@ namespace util
{
if (this->tasks.count(id) == 0)
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.");
}
this->tasks.erase(id);

View file

@ -1,36 +1,43 @@
#include "ShowCommand.h"
#include "Error.h"
#include "Util.h"
#include "Manager.h"
#include "Util.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)
{
void ShowCommand::run(stringstream &args) {
Manager *mgr = Manager::get_instance();
const string data_type = Util::read_string(args);
if (data_type == "user")
for (User* u : mgr->get_users()) {
AddUser au = {*u};
cout << au;
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.");
}
else if (data_type == "task")
for (Task* t : mgr->get_tasks()) {
AddTask at = {*t};
cout << at;
AddUser unid_user = {*user};
cout << unid_user;
}
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");
}
} // commands
} // namespace commands

View file

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

View file

@ -1,14 +1,15 @@
#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;
@ -18,6 +19,7 @@ using commands::DelCommand;
using commands::AssignCommand;
using commands::UnassignCommand;
using commands::ActiveCommand;
using commands::ShowCommand;
using err::Error;
const vector<SubCommand*> handlers = {
@ -28,6 +30,7 @@ const vector<SubCommand*> handlers = {
new AssignCommand(),
new UnassignCommand(),
new ActiveCommand(),
new ShowCommand(),
};
int main(int argc, char** argv)