-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.cpp
More file actions
35 lines (29 loc) · 867 Bytes
/
Project.cpp
File metadata and controls
35 lines (29 loc) · 867 Bytes
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
#include "Project.h"
Project::Project(const std::string& name) : name(name) {}
void Project::addTask(const Task& task) {
tasks.push_back(task);
}
std::string Project::getName() const { return name; }
std::vector<Task>& Project::getTasks() { return tasks; }
std::chrono::minutes Project::getTotalTimeSpent() const {
std::chrono::minutes total(0);
for (const auto& task : tasks) {
total += task.getTimeSpent();
}
return total;
}
nlohmann::json Project::toJson() const {
nlohmann::json j;
j["name"] = name;
for (const auto& task : tasks) {
j["tasks"].push_back(task.toJson());
}
return j;
}
Project Project::fromJson(const nlohmann::json& j) {
Project project(j["name"]);
for (const auto& taskJson : j["tasks"]) {
project.tasks.push_back(Task::fromJson(taskJson));
}
return project;
}