#ifndef HttpEndpoint_h #define HttpEndpoint_h #include #include #include #include #include #define HTTP_ENDPOINT_ORIGIN_ID "http" template class HttpGetEndpoint { public: HttpGetEndpoint(JsonStateReader stateReader, StatefulService * statefulService, AsyncWebServer * server, const String & servicePath, SecurityManager * securityManager, AuthenticationPredicate authenticationPredicate = AuthenticationPredicates::IS_ADMIN) : _stateReader(stateReader) , _statefulService(statefulService) { } HttpGetEndpoint(JsonStateReader stateReader, StatefulService * statefulService, AsyncWebServer * server, const String & servicePath) : _stateReader(stateReader) , _statefulService(statefulService) { } protected: JsonStateReader _stateReader; StatefulService * _statefulService; void fetchSettings(AsyncWebServerRequest * request) { } }; template class HttpPostEndpoint { public: HttpPostEndpoint(JsonStateReader stateReader, JsonStateUpdater stateUpdater, StatefulService * statefulService, AsyncWebServer * server, const String & servicePath, SecurityManager * securityManager, AuthenticationPredicate authenticationPredicate = AuthenticationPredicates::IS_ADMIN) : _stateReader(stateReader) , _stateUpdater(stateUpdater) , _statefulService(statefulService) { } HttpPostEndpoint(JsonStateReader stateReader, JsonStateUpdater stateUpdater, StatefulService * statefulService, AsyncWebServer * server, const String & servicePath) : _stateReader(stateReader) , _stateUpdater(stateUpdater) , _statefulService(statefulService) { } protected: JsonStateReader _stateReader; JsonStateUpdater _stateUpdater; StatefulService * _statefulService; void updateSettings(AsyncWebServerRequest * request, JsonVariant & json) { if (!json.is()) { return; } JsonObject jsonObject = json.as(); StateUpdateResult outcome = _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater); if (outcome == StateUpdateResult::ERROR) { return; } if (outcome == StateUpdateResult::CHANGED) { } } }; template class HttpEndpoint : public HttpGetEndpoint, public HttpPostEndpoint { public: HttpEndpoint(JsonStateReader stateReader, JsonStateUpdater stateUpdater, StatefulService * statefulService, AsyncWebServer * server, const String & servicePath, SecurityManager * securityManager, AuthenticationPredicate authenticationPredicate = AuthenticationPredicates::IS_ADMIN) : HttpGetEndpoint(stateReader, statefulService, server, servicePath, securityManager, authenticationPredicate) , HttpPostEndpoint(stateReader, stateUpdater, statefulService, server, servicePath, securityManager, authenticationPredicate) { } HttpEndpoint(JsonStateReader stateReader, JsonStateUpdater stateUpdater, StatefulService * statefulService, AsyncWebServer * server, const String & servicePath) : HttpGetEndpoint(stateReader, statefulService, server, servicePath) , HttpPostEndpoint(stateReader, stateUpdater, statefulService, server, servicePath) { } }; #endif