move the Get* endpoints to their right service classes

This commit is contained in:
proddy
2024-08-29 13:53:27 +02:00
parent e2aabb1418
commit 19922ca9fb
14 changed files with 114 additions and 115 deletions

View File

@@ -29,6 +29,9 @@ WebCustomEntityService::WebCustomEntityService(AsyncWebServer * server, FS * fs,
securityManager,
AuthenticationPredicates::IS_AUTHENTICATED)
, _fsPersistence(WebCustomEntity::read, WebCustomEntity::update, this, fs, EMSESP_CUSTOMENTITY_FILE) {
server->on(EMSESP_GET_ENTITIES_PATH,
HTTP_GET,
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { getEntities(request); }, AuthenticationPredicates::IS_ADMIN));
}
// load the settings when the service starts
@@ -708,4 +711,17 @@ void WebCustomEntityService::test() {
}
#endif
// return entities as a json object
void WebCustomEntityService::getEntities(AsyncWebServerRequest * request) {
auto * response = new AsyncJsonResponse(false);
JsonObject root = response->getRoot();
root["type"] = "entities";
System::extractSettings(EMSESP_CUSTOMENTITY_FILE, "Entities", root);
response->setLength();
request->send(response);
}
} // namespace emsesp