Created
May 13, 2019 22:45
-
-
Save sidoh/75ca02d4e20b2f5a7ed35ffdc5db0a42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void HttpServer::handleUpdateSettings(RequestContext& request) { | |
JsonObject req = request.getJsonBody().as<JsonObject>(); | |
if (req.isNull()) { | |
request.response.json["error"] = "Invalid JSON"; | |
request.response.setCode(400); | |
return; | |
} | |
ConfigurationDictionary params; | |
for (JsonObject::iterator it = req.begin(); it != req.end(); ++it) { | |
params[it->key().c_str()] = it->value().as<String>(); | |
} | |
settings.setFromDictionary(params); | |
Bleeper.storage.persist(); | |
handleListSettings(request); | |
} | |
void HttpServer::handleListSettings(RequestContext& request) { | |
request.response.sendRaw(200, APPLICATION_JSON, getSettingsBody().c_str()); | |
} | |
String HttpServer::getSettingsBody() { | |
DynamicJsonDocument json(2048); | |
ConfigurationDictionary params = settings.getAsDictionary(true); | |
for (std::map<String, String>::const_iterator it = params.begin(); it != params.end(); ++it) { | |
json[it->first] = it->second; | |
} | |
String strJson; | |
serializeJson(json, strJson); | |
return strJson; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment