Older/Database/Task.cpp

34 lines
871 B
C++
Raw Normal View History

2024-01-03 22:44:36 +08:00
#include "Task.h"
#include <boost/json/array.hpp>
#include <boost/json/object.hpp>
#include <boost/json/serialize.hpp>
namespace boost {
namespace json {
2024-01-04 23:32:07 +08:00
static boost::json::object serialize(const Task &task) {
boost::json::object ret;
ret["id"] = task.id;
ret["parentId"] = task.parentId;
ret["finished"] = task.finished;
ret["createTime"] = task.createTime;
ret["content"] = task.content;
ret["comment"] = task.comment;
boost::json::array children;
for (auto &child : task.children) {
children.push_back(serialize(child));
}
ret["children"] = std::move(children);
return ret;
}
2024-01-03 22:44:36 +08:00
std::string serialize(const Tasks &tasks) {
boost::json::array ret;
for (auto &task : tasks) {
2024-01-04 23:32:07 +08:00
ret.push_back(serialize(task));
2024-01-03 22:44:36 +08:00
}
return boost::json::serialize(ret);
}
} // namespace json
} // namespace boost