diff --git a/CMakeLists.txt b/CMakeLists.txt index b68146e..d0d0f88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,8 +42,9 @@ add_executable(App ./src/main.cpp ./src/entities/User.h ./src/DAO/MySQLUserDAO.cpp ./src/DAO/MySQLUserDAO.h - src/endpoints_handlers/IExecutor.h - src/endpoints_handlers/AuthRegistrationExecutor.h + ./src/endpoints_handlers/IExecutor.h + ./src/endpoints_handlers/AuthRegistrationExecutor.h + ./src/endpoints_handlers/RootExecutor.h ) target_link_libraries(App PRIVATE Boost::boost Threads::Threads mysql::concpp) diff --git a/src/endpoints_handlers/HandleRequest.h b/src/endpoints_handlers/HandleRequest.h index 0ecd3e7..4d7c0ad 100644 --- a/src/endpoints_handlers/HandleRequest.h +++ b/src/endpoints_handlers/HandleRequest.h @@ -6,6 +6,7 @@ #include "Controller.h" #include "AuthRegistrationExecutor.h" +#include "RootExecutor.h" #include "./../helpers/helpers.h" namespace uad @@ -15,13 +16,6 @@ void HandleRequest( boost::beast::string_view doc_root, boost::beast::http::request>&& req, Send&& send) { - using IRouteExecutor = IExecutor; - using RouteAuthRegistrationExecutor = AuthRegistrationExecutor< - Body, Allocator, boost::beast::http::string_body>; - using IRouteController = IController; - using RouteController = Controller; - using RoutesPathes = std::unordered_map>; - auto const bad_request = [&req](boost::beast::string_view why) { boost::beast::http::response res{ @@ -61,17 +55,7 @@ void HandleRequest( return res; }; - static RoutesPathes routes_pathes; - - typename RouteController::HTTPMethodsToExecutors auth_registration_executors; - - auth_registration_executors[boost::beast::http::verb::post] = std::make_shared< - RouteAuthRegistrationExecutor>(RouteAuthRegistrationExecutor()); - - std::unique_ptr auth_registration_controller = - std::make_unique(std::move(auth_registration_executors)); - - routes_pathes["/api/v1/Auth/Register"] = std::move(auth_registration_controller); + static RootExecutor root_executor; if (req.method() != boost::beast::http::verb::get && req.method() != boost::beast::http::verb::head) diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h new file mode 100644 index 0000000..2d8b96d --- /dev/null +++ b/src/endpoints_handlers/RootExecutor.h @@ -0,0 +1,46 @@ +#include "IExecutor.h" +#include "IController.h" +#include "Controller.h" +#include "AuthRegistrationExecutor.h" + +namespace uad +{ +template +class RootExecutor : public IExecutor +{ + using IRouteExecutor = IExecutor; + using RouteAuthRegistrationExecutor = AuthRegistrationExecutor< + Body, Allocator, boost::beast::http::string_body>; + using IRouteController = IController; + using RouteController = Controller; + using RoutesPathes = std::unordered_map>; +private: + RoutesPathes routes_pathes_; +public: + RootExecutor() + { + typename RouteController::HTTPMethodsToExecutors authorization_registration_executors { + {boost::beast::http::verb::post, std::make_shared()} + }; + + routes_pathes_["/api/v1/Auth/Register"] = std::make_unique( + std::move(authorization_registration_executors) + ); + + } + boost::beast::http::response operator ()( + boost::beast::http::request>&& req + ) override + { + boost::beast::http::response res{ + boost::beast::http::status::ok, req.version() + }; + + res.body() = "{ \"detail\": \"ok\"}"; + res.set(boost::beast::http::field::content_type, "application/json"); + res.content_length(res.body().size()); + + return res; + } +}; +}