namespace samples::mongodb {
public:
static constexpr std::string_view kName = "handler-translations";
request.
GetHttpResponse().
SetContentType(http::content_type::kApplicationJson);
if (request.
GetMethod() == server::http::HttpMethod::kPatch) {
InsertNew(request);
return {};
} else {
return ReturnDiff(request);
}
}
private:
storages::mongo::PoolPtr pool_;
};
}
namespace samples::mongodb {
const auto& key = request.
GetArg(
"key");
const auto& lang = request.
GetArg(
"lang");
const auto& value = request.
GetArg(
"value");
auto transl = pool_->GetCollection("translations");
transl.InsertOne(MakeDoc("key", key, "lang", lang, "value", value));
}
auto time_point = std::chrono::system_clock::time_point{};
if (request.
HasArg(
"last_update")) {
const auto& update_time = request.
GetArg(
"last_update");
}
auto transl = pool_->GetCollection("translations");
auto cursor = transl.Find(
options::Sort{std::make_pair("_id", options::Sort::kAscending)}
);
if (!cursor) {
return "{}";
}
auto content = vb["content"];
for (const auto& doc : cursor) {
const auto key = doc[
"key"].
As<std::string>();
const auto lang = doc["lang"].As<std::string>();
content[key][lang] = doc["value"].As<std::string>();
last = doc;
}
}
}
int main(int argc, char* argv[]) {
.Append<components::Mongo>("mongo-tr")
.Append<samples::mongodb::Translations>();
}