fix: fixed tasks again

This commit is contained in:
moonleay 2025-02-09 22:30:03 +01:00
parent 31e84d54bf
commit 20a88a6edf
Signed by: moonleay
GPG key ID: 82667543CCD715FB
13 changed files with 61 additions and 57 deletions

View file

@ -8,7 +8,7 @@ using err::Error;
namespace commands namespace commands
{ {
ActiveCommand::ActiveCommand() : SubCommand("active", 100, false) ActiveCommand::ActiveCommand() : SubCommand("active", false)
{ {
} }
@ -19,10 +19,10 @@ namespace commands
args >> user_id; args >> user_id;
if (!user_id) 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");
User* u = mgr.get_user(user_id); const User* u = mgr.get_user(user_id);
if (!u) if (!u)
throw Error(401, "Eine solche BenutzerIn existiert nicht."); throw Error(401, "Eine solche BenutzerIn existiert nicht.");
for (Assignment* a : mgr.get_assignments_for_user(user_id)) for (const Assignment* a : mgr.get_assignments_for_user(user_id))
cout << a->get_task_id() << "\n"; cout << a->get_task_id() << "\n";
} }
} // commands } // commands

View file

@ -10,7 +10,7 @@ using err::Error;
namespace commands namespace commands
{ {
AddCommand::AddCommand() : SubCommand("add", 100, true) AddCommand::AddCommand() : SubCommand("add", true)
{ {
} }

View file

@ -8,7 +8,7 @@ using err::Error;
namespace commands namespace commands
{ {
AssignCommand::AssignCommand() : SubCommand("assign", 100, true) AssignCommand::AssignCommand() : SubCommand("assign", true)
{ {
} }

View file

@ -8,7 +8,7 @@ using err::Error;
namespace commands namespace commands
{ {
DelCommand::DelCommand() : SubCommand("delete", 100, true) DelCommand::DelCommand() : SubCommand("delete", true)
{ {
} }

View file

@ -1,10 +1,10 @@
#include "HelpCommand.h" #include "HelpCommand.h"
namespace commands { namespace commands {
HelpCommand::HelpCommand(): SubCommand("help", 100, false) {} HelpCommand::HelpCommand(): SubCommand("help", false) {}
void HelpCommand::run(stringstream& args) { void HelpCommand::run(stringstream& args) {
cout << "Projekt 5\n"; cout << "Projekt 5\n";
cout << "epr24pr5-ojanssen2 <add/delete/list/show/assign/unassign/active/help>\n"; cout << "epr24pr5-ojanssen2 <add/delete/list/show/assign/unassign/active/help>\n";
} }
} } // commands

View file

@ -11,7 +11,7 @@ using err::Error;
namespace commands namespace commands
{ {
ListCommand::ListCommand() : SubCommand("list", 100, false) ListCommand::ListCommand() : SubCommand("list", false)
{ {
} }

View file

@ -11,19 +11,18 @@ namespace util
Manager::Manager(): users({}), tasks({}), assignments({}), user_id_index(0), task_id_index(0), filename("tasks") Manager::Manager(): users({}), tasks({}), assignments({}), user_id_index(0), task_id_index(0), filename("tasks")
{ {
//Open File //Open File
ifstream in(this->filename, ios_base::in); ifstream in = ifstream(this->filename, ios_base::in);
if (!in) if (!in)
{ {
this->save(); this->save();
in.clear(); in.clear();
in.open(this->filename); in.open(this->filename, ios_base::in);
if (!in) if (!in)
throw Error(601, "Datei kann nicht geöffnet werden."); throw Error(601, "Datei kann nicht geöffnet werden.");
} }
map<DataType, vector<string>> buffer; map<DataType, vector<string>> buffer;
DataType current_type = DataType::INIT; DataType current_type = DataType::INIT;
string d; // dump string d; // dump
char c;
string line, section; string line, section;
//Parse all Lines until EOF //Parse all Lines until EOF
while (getline(in, line)) while (getline(in, line))
@ -118,14 +117,14 @@ namespace util
int Manager::get_user_id() int Manager::get_user_id()
{ {
int value = this->user_id_index; const int value = this->user_id_index;
++this->user_id_index; ++this->user_id_index;
return value; return value;
} }
int Manager::get_task_id() int Manager::get_task_id()
{ {
int value = this->task_id_index; const int value = this->task_id_index;
++this->task_id_index; ++this->task_id_index;
return value; return value;
} }

View file

@ -12,7 +12,7 @@ using err::Error;
namespace commands namespace commands
{ {
ShowCommand::ShowCommand() : SubCommand("show", 100, false) ShowCommand::ShowCommand() : SubCommand("show", false)
{ {
} }

View file

@ -2,7 +2,7 @@
#include <sstream> #include <sstream>
namespace commands { namespace commands {
SubCommand::SubCommand(const string& name, const int& return_value, const bool show_result): name(name), return_value(return_value), show_result(show_result) {} SubCommand::SubCommand(const string& name, const bool show_result): name(name), show_result(show_result) {}
void SubCommand::run(stringstream& args) { void SubCommand::run(stringstream& args) {
cout << "Not impl!\n"; cout << "Not impl!\n";

View file

@ -11,11 +11,8 @@ namespace commands
string name; string name;
bool show_result; bool show_result;
protected:
int return_value;
public: public:
SubCommand(const string& indicator, const int& value, const bool show_result); SubCommand(const string& indicator, const bool show_result);
string get_name(); string get_name();
int get_value() const; int get_value() const;
bool should_display_result() const; bool should_display_result() const;

View file

@ -18,6 +18,13 @@ namespace models
{ {
} }
Task::Task(const AddTask& t): id(0), name(t.get_name()), description(t.get_description()), children(t.get_children())
{
Manager& mgr = Manager::get_instance();
this->id = mgr.get_task_id();
}
ostream& Task::write(ostream& stream) const ostream& Task::write(ostream& stream) const
{ {
stream << *this; stream << *this;
@ -44,9 +51,7 @@ namespace models
return this->children; return this->children;
} }
AddTask::AddTask(): Task() AddTask::AddTask(): Task() {}
{
}
AddTask::AddTask(Task& t): Task(t) AddTask::AddTask(Task& t): Task(t)
{ {
@ -104,9 +109,6 @@ namespace models
istream& operator>>(istream& is, AddTask& t) istream& operator>>(istream& is, AddTask& t)
{ {
Manager& mgr = Manager::get_instance();
int id = mgr.get_task_id();
try try
{ {
const string name = Util::read_string_between_percent(is); const string name = Util::read_string_between_percent(is);
@ -114,9 +116,8 @@ namespace models
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
const string description = Util::read_string_between_percent(is); const string description = Util::read_string_between_percent(is);
const vector<int> children = Util::read_numbers(is); const vector<int> children = Util::read_numbers(is);
Task ft = {id, name, description, children}; Task at = {0, name, description, children};
t = at;
t = {ft};
return is; return is;
} }
catch (Error& err) catch (Error& err)

61
Task.h
View file

@ -6,46 +6,53 @@
using util::Util; using util::Util;
namespace models { namespace models
class Task { {
private: class AddTask;
int id; class Task
string name; {
string description; private:
vector<int> children; int id;
public: string name;
Task(const int& id, const string& name, const string& description, const vector<int>& children); string description;
vector<int> children;
Task(); public:
Task(const int& id, const string& name, const string& description, const vector<int>& children);
ostream& write(ostream& stream) const; Task();
istream& read(istream&);
int get_id() const; explicit Task(const AddTask& t);
string get_name() const;
string get_description() const; ostream& write(ostream& stream) const;
vector<int> get_children() const; istream& read(istream&);
int get_id() const;
string get_name() const;
string get_description() const;
vector<int> get_children() const;
friend ostream& operator<<(ostream& os, const Task& t); friend ostream& operator<<(ostream& os, const Task& t);
friend istream& operator>>(istream& is, Task& t); friend istream& operator>>(istream& is, Task& t);
}; };
class AddTask : public Task{ class AddTask : public Task
private: {
public: private:
AddTask(); public:
AddTask(Task& t); AddTask();
AddTask(Task& t);
friend ostream& operator<<(ostream& os, const AddTask& t); friend ostream& operator<<(ostream& os, const AddTask& t);
friend istream& operator>>(istream& is, AddTask& t); friend istream& operator>>(istream& is, AddTask& t);
}; };
ostream& operator<<(ostream& os, const AddTask& t); ostream& operator<<(ostream& os, const AddTask& t);
istream& operator>>(istream& is, AddTask& t); istream& operator>>(istream& is, AddTask& t);
ostream& operator<<(ostream& os, const Task& t); ostream& operator<<(ostream& os, const Task& t);
istream& operator>>(istream& is, Task& t); istream& operator>>(istream& is, Task& t);
} } // models
#endif // TASK_H #endif // TASK_H

View file

@ -7,7 +7,7 @@ using err::Error;
namespace commands namespace commands
{ {
UnassignCommand::UnassignCommand() : SubCommand("unassign", 100, true) UnassignCommand::UnassignCommand() : SubCommand("unassign", true)
{ {
} }