-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathTaskManager.cpp
More file actions
64 lines (54 loc) · 1.67 KB
/
Copy pathTaskManager.cpp
File metadata and controls
64 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "TaskStorage.cpp"
#include <algorithm>
class TodoManager {
private:
vector<Task> tasks;
FileHandler fileHandler;
int nextId;
public:
TodoManager() : fileHandler("tasks.txt") {
tasks = fileHandler.loadTasks();
nextId = tasks.empty() ? 1 : tasks.back().getId() + 1;
}
void addTask(const string& description, const string& date) {
if (!description.empty()) {
tasks.push_back(Task(nextId++, description, date, false));
fileHandler.saveTasks(tasks);
}
}
void editTask(int id, const string& description, const string& date) {
for (auto& task : tasks) {
if (task.getId() == id) {
task.setDescription(description);
task.setDueDate(date);
fileHandler.saveTasks(tasks);
return;
}
}
}
const vector<Task>& getAllTasks() const {
return tasks;
}
void markComplete(int id) {
for (auto& task : tasks) {
if (task.getId() == id) {
task.setCompleted(true);
fileHandler.saveTasks(tasks);
return;
}
}
}
void deleteTask(int id) {
auto it = remove_if(tasks.begin(), tasks.end(),
[id](const Task& t) { return t.getId() == id; });
if (it != tasks.end()) {
tasks.erase(it, tasks.end());
fileHandler.saveTasks(tasks);
}
}
void clearAll() {
tasks.clear();
fileHandler.saveTasks(tasks);
nextId = 1;
}
};