From 1b922f7319f821fe3daf302a8c68131aaa94f586 Mon Sep 17 00:00:00 2001 From: neodarz Date: Fri, 6 Sep 2019 18:04:40 +0200 Subject: Change code to use Restbed --- api/umosapi.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 88 insertions(+), 17 deletions(-) (limited to 'api/umosapi.h') diff --git a/api/umosapi.h b/api/umosapi.h index 20c6d7b..a1765d7 100644 --- a/api/umosapi.h +++ b/api/umosapi.h @@ -1,37 +1,108 @@ #ifndef UmosapiService_H_ #define UmosapiService_H_ -#include -#include -#include +//#include +//#include +//#include -#include +#include -using namespace Pistache; +//#include + +#include + +using namespace restbed; +using namespace std; + +using json = nlohmann::json; + +struct tag { + std::string name; + std::string description; +}; + +struct Propertie { + + std::string name; + std::string format; + std::string type; + std::string required; +}; + +struct Definition { + + std::string name; + std::string type; + std::vector props; +}; + +struct Definitions { + std::vector defs; +}; + +struct HttpWord { + std::string name; +}; + +struct Path { + std::string name; + std::vector words; +}; + +struct Paths { + std::vector paths; +}; class UmosapiService { public: - UmosapiService(Address addr); + UmosapiService(); virtual ~UmosapiService() {}; - void init(size_t thr); + void init(); - void start(std::string swaggerui); + void start(int, int); + Service _service; + json _swagger; + vector _tags; private: - void createDescription(); - - void retrieveAll(const Rest::Request& request, Http::ResponseWriter response); + void desc(std::string route, std::string http_word, const std::function< void ( const std::shared_ptr< Session > ) >& callback, const std::function< void(int, const std::exception&, std::shared_ptr) >& error_callback, tag tags[]); + void createResource(); - void addUObject(const Rest::Request& request, Http::ResponseWriter response); + static void retrieveAll( const shared_ptr session ); + static void addUObject( const shared_ptr session ); + static void deleteUObject( const shared_ptr session ); + static void searchUObjectByKeyValue( const shared_ptr session ); + static void swaggerEndpoint( const shared_ptr session ); + static void swaggerEndpointResources( const shared_ptr session ); + static void swaggerEndpointApi( const shared_ptr session ); - void deleteUObject(const Rest::Request& request, Http::ResponseWriter response); + shared_ptr< Resource> _resource; + Definition _definition; + Definitions _definitions; + Path _path; + Paths _paths; + void set_path(); + void set_path(std::string route); + void set_method_handler(std::string http_word, const std::function< void ( const std::shared_ptr< Session > ) >& callback); + void set_error_handler(const std::function< void(int, const std::exception&, std::shared_ptr) >& error_callback); + void produce(std::string); + void consume(std::string); + void parameter(std::string, std::string, std::string); + void response(std::string err_code, std::string description, std::string schema); + void publish(); + void basePath(std::string basePath); + void description(std::string description); + void title(std::string title); + void version(std::string version); + void host(std::string host); + void atag(std::string name, std::string description); + void scheme(std::string scheme); - void searchUObjectByKeyValue(const Rest::Request& request, Http::ResponseWriter response); + void definition(std::string name, std::string type); + void propertie(std::string name, std::string format, std::string type, std::string required); + void swagger(std::string ui_path, std::string swagger_dir, std::string api_path); - std::shared_ptr httpEndpoint; - Rest::Description desc; - Rest::Router router; }; #endif -- cgit v1.2.1 From bc6aeaa834d666221171d302d4f101ce65608898 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 9 Sep 2019 17:17:44 +0200 Subject: Refactoring some code to be more readable --- api/umosapi.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'api/umosapi.h') diff --git a/api/umosapi.h b/api/umosapi.h index a1765d7..3cb2b47 100644 --- a/api/umosapi.h +++ b/api/umosapi.h @@ -16,6 +16,8 @@ using namespace std; using json = nlohmann::json; +namespace UmosapiService { + struct tag { std::string name; std::string description; @@ -53,11 +55,11 @@ struct Paths { std::vector paths; }; -class UmosapiService { +class Api { public: - UmosapiService(); - virtual ~UmosapiService() {}; + Api(); + virtual ~Api() {}; void init(); @@ -105,4 +107,5 @@ class UmosapiService { void swagger(std::string ui_path, std::string swagger_dir, std::string api_path); }; +} #endif -- cgit v1.2.1 From 260ce7465a66427832da15caae0077323dc9750a Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 9 Sep 2019 17:56:09 +0200 Subject: Refactoring a little more --- api/umosapi.h | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'api/umosapi.h') diff --git a/api/umosapi.h b/api/umosapi.h index 3cb2b47..a066ac9 100644 --- a/api/umosapi.h +++ b/api/umosapi.h @@ -1,21 +1,10 @@ #ifndef UmosapiService_H_ #define UmosapiService_H_ -//#include -//#include -//#include - #include -//#include - #include -using namespace restbed; -using namespace std; - -using json = nlohmann::json; - namespace UmosapiService { struct tag { @@ -64,30 +53,30 @@ class Api { void init(); void start(int, int); - Service _service; - json _swagger; - vector _tags; + restbed::Service _service; + nlohmann::json _swagger; + std::vector _tags; private: - void desc(std::string route, std::string http_word, const std::function< void ( const std::shared_ptr< Session > ) >& callback, const std::function< void(int, const std::exception&, std::shared_ptr) >& error_callback, tag tags[]); + void desc(std::string route, std::string http_word, const std::function< void ( const std::shared_ptr< restbed::Session > ) >& callback, const std::function< void(int, const std::exception&, std::shared_ptr< restbed::Session >) >& error_callback, tag tags[]); void createResource(); - static void retrieveAll( const shared_ptr session ); - static void addUObject( const shared_ptr session ); - static void deleteUObject( const shared_ptr session ); - static void searchUObjectByKeyValue( const shared_ptr session ); - static void swaggerEndpoint( const shared_ptr session ); - static void swaggerEndpointResources( const shared_ptr session ); - static void swaggerEndpointApi( const shared_ptr session ); + static void retrieveAll( const std::shared_ptr< restbed::Session > session ); + static void addUObject( const std::shared_ptr< restbed::Session > session ); + static void deleteUObject( const std::shared_ptr< restbed::Session > session ); + static void searchUObjectByKeyValue( const std::shared_ptr< restbed::Session > session ); + static void swaggerEndpoint( const std::shared_ptr< restbed::Session > session ); + static void swaggerEndpointResources( const std::shared_ptr< restbed::Session > session ); + static void swaggerEndpointApi( const std::shared_ptr< restbed::Session > session ); - shared_ptr< Resource> _resource; + std::shared_ptr< restbed::Resource> _resource; Definition _definition; Definitions _definitions; Path _path; Paths _paths; void set_path(); void set_path(std::string route); - void set_method_handler(std::string http_word, const std::function< void ( const std::shared_ptr< Session > ) >& callback); + void set_method_handler(std::string http_word, const std::function< void ( const std::shared_ptr< restbed::Session > ) >& callback); void set_error_handler(const std::function< void(int, const std::exception&, std::shared_ptr) >& error_callback); void produce(std::string); void consume(std::string); -- cgit v1.2.1