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
{
ActiveCommand::ActiveCommand() : SubCommand("active", 100, false)
ActiveCommand::ActiveCommand() : SubCommand("active", false)
{
}
@ -19,10 +19,10 @@ namespace commands
args >> user_id;
if (!user_id)
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)
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";
}
} // commands

View file

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

View file

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

View file

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

View file

@ -1,10 +1,10 @@
#include "HelpCommand.h"
namespace commands {
HelpCommand::HelpCommand(): SubCommand("help", 100, false) {}
HelpCommand::HelpCommand(): SubCommand("help", false) {}
void HelpCommand::run(stringstream& args) {
cout << "Projekt 5\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
{
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")
{
//Open File
ifstream in(this->filename, ios_base::in);
ifstream in = ifstream(this->filename, ios_base::in);
if (!in)
{
this->save();
in.clear();
in.open(this->filename);
in.open(this->filename, ios_base::in);
if (!in)
throw Error(601, "Datei kann nicht geöffnet werden.");
}
map<DataType, vector<string>> buffer;
DataType current_type = DataType::INIT;
string d; // dump
char c;
string line, section;
//Parse all Lines until EOF
while (getline(in, line))
@ -118,14 +117,14 @@ namespace util
int Manager::get_user_id()
{
int value = this->user_id_index;
const int value = this->user_id_index;
++this->user_id_index;
return value;
}
int Manager::get_task_id()
{
int value = this->task_id_index;
const int value = this->task_id_index;
++this->task_id_index;
return value;
}

View file

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

View file

@ -2,7 +2,7 @@
#include <sstream>
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) {
cout << "Not impl!\n";

View file

@ -11,11 +11,8 @@ namespace commands
string name;
bool show_result;
protected:
int return_value;
public:
SubCommand(const string& indicator, const int& value, const bool show_result);
SubCommand(const string& indicator, const bool show_result);
string get_name();
int get_value() 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
{
stream << *this;
@ -44,9 +51,7 @@ namespace models
return this->children;
}
AddTask::AddTask(): Task()
{
}
AddTask::AddTask(): Task() {}
AddTask::AddTask(Task& t): Task(t)
{
@ -104,9 +109,6 @@ namespace models
istream& operator>>(istream& is, AddTask& t)
{
Manager& mgr = Manager::get_instance();
int id = mgr.get_task_id();
try
{
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");
const string description = Util::read_string_between_percent(is);
const vector<int> children = Util::read_numbers(is);
Task ft = {id, name, description, children};
t = {ft};
Task at = {0, name, description, children};
t = at;
return is;
}
catch (Error& err)

61
Task.h
View file

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

View file

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