blob: 53b0d8c2b8be58d5d6a5184584f77714ad719fd0 (
plain) (
tree)
|
|
#include "Response.hpp"
Response::json Response::simple_response(std::string const &text, std::string const &session, bool success) {
std::vector<json> reply_vec;
reply_vec.emplace_back(create_text(text));
return create_response(std::move(reply_vec), session, success);
}
Response::json Response::create_annotation(Reply::AnnotationType annotationType, std::string const &extra) {
json annotation(crow::json::type::Object);
annotation["type"] = Reply::GetStringAnnotationType(annotationType);
if (extra.empty()) {
annotation["extra"] = json(crow::json::type::List);
} else {
annotation["extra"] = create_text(extra);
}
return annotation;
}
Response::json Response::create_annotation(Reply::AnnotationType annotationType, std::vector<json> &&extra) {
json annotation(crow::json::type::Object);
annotation["type"] = Reply::GetStringAnnotationType(annotationType);
annotation["extra"] = std::move(extra);
return annotation;
}
Response::json Response::create_text(std::string const &text) {
std::vector<json> annotations;
annotations.emplace_back(create_annotation());
return create_text(text, std::move(annotations));
}
Response::json Response::create_text(std::string const &text, std::vector<json> &&annotations) {
json reply(crow::json::type::Object);
reply["text"] = text;
reply["annotations"] = std::move(annotations);
return reply;
}
Response::json Response::create_response(std::vector<json> &&reply, std::string const &session, bool success) {
json response(crow::json::type::Object);
response["success"] = success;
response["session"] = session;
response["reply"] = std::move(reply);
return response;
}
|