Older/Server/Database/Task.cpp
2024-01-04 23:32:07 +08:00

34 lines
871 B
C++

#include "Task.h"
#include <boost/json/array.hpp>
#include <boost/json/object.hpp>
#include <boost/json/serialize.hpp>
namespace boost {
namespace json {
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;
}
std::string serialize(const Tasks &tasks) {
boost::json::array ret;
for (auto &task : tasks) {
ret.push_back(serialize(task));
}
return boost::json::serialize(ret);
}
} // namespace json
} // namespace boost