blob: 53b0d8c2b8be58d5d6a5184584f77714ad719fd0 (
plain) (
blame)
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
|
#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;
}
|