#ifndef GRADIDO_LOGIN_SERVER_CONTROLLER_NODE_SERVER_INCLUDE #define GRADIDO_LOGIN_SERVER_CONTROLLER_NODE_SERVER_INCLUDE #include "../model/table/NodeServer.h" #include "../controller/HederaId.h" #include "../lib/JsonRequest.h" #include "Poco/SharedPtr.h" #include "TableControllerBase.h" namespace controller { struct NodeServerConnection { NodeServerConnection(const std::string& _url, int _port) : url(_url), port(_port) {} NodeServerConnection() :port(0) {}; // with http:// or https:// inline std::string getUrlWithPort() const { return url + ":" + std::to_string(port); } // without http:// or https:// std::string getUriWithPort() const; std::string getUri() const; bool isValid() { return url != "" && port; } std::string url; int port; Poco::AutoPtr hederaId; }; typedef Poco::Tuple NodeServerFullTuple; class NodeServer : public TableControllerBase { public: ~NodeServer(); static Poco::AutoPtr create(const std::string& url, int port, int groupId, model::table::NodeServerType type, int nodeHederaId); //! \param group_id is zero take everyone static std::vector> load(model::table::NodeServerType type, int group_id = 0); static Poco::AutoPtr load(int id); static std::vector> listAll(); // pick server randomly static NodeServerConnection pick(ServerConfig::HederaNetworkType type, int group_id = 0); static NodeServerConnection pick(model::table::NodeServerType type, int group_id = 0); bool deleteFromDB(); inline Poco::AutoPtr getModel() { return _getModel(); } inline void setHederaId(Poco::AutoPtr hederaId) { mHederaID = hederaId; } inline Poco::AutoPtr getHederaId() { return mHederaID; } std::string getBaseUri(); JsonRequest createJsonRequest(); protected: NodeServer(model::table::NodeServer* dbModel); Poco::AutoPtr mHederaID; }; } #endif //GRADIDO_LOGIN_SERVER_CONTROLLER_NODE_SERVER_INCLUDE