generated from Sithas/conan_template
Рабочая сборка второго executor'а
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
#include "IController.h"
|
||||
#include "Controller.h"
|
||||
#include "AuthRegistrationExecutor.h"
|
||||
#include "AuthLoginExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../DAO/IAuthDAO.h"
|
||||
#include "./../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
@@ -13,6 +15,8 @@ class RootExecutor
|
||||
using IRouteExecutor = IExecutor<Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteAuthRegistrationExecutor = AuthRegistrationExecutor<
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteAuthLoginExecutor = AuthLoginExecutor<
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using IRouteController = IController<Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteController = Controller<Body, Allocator, boost::beast::http::string_body>;
|
||||
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
|
||||
@@ -25,15 +29,30 @@ private:
|
||||
RoutesPathes routes_pathes_;
|
||||
mysqlx::Session& session_;
|
||||
std::shared_ptr<IUserDAO> user_dao_;
|
||||
std::shared_ptr<IAuthDAO> auth_dao_;
|
||||
|
||||
public:
|
||||
RootExecutor(mysqlx::Session& session, std::shared_ptr<IUserDAO> user_dao)
|
||||
: session_(session), user_dao_(user_dao)
|
||||
RootExecutor(
|
||||
mysqlx::Session& session,
|
||||
std::shared_ptr<IUserDAO> user_dao,
|
||||
std::shared_ptr<IAuthDAO> auth_dao) :
|
||||
session_(session), user_dao_(user_dao), auth_dao_(auth_dao)
|
||||
|
||||
{
|
||||
routes_pathes_["/api/v1/Auth/Register"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(session_, user_dao_)}
|
||||
}
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(
|
||||
session_,
|
||||
user_dao_
|
||||
)}
|
||||
}
|
||||
);
|
||||
|
||||
routes_pathes_["/api/v1/Auth/Login"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post,
|
||||
std::make_shared<RouteAuthLoginExecutor>(session_, user_dao_, auth_dao_)}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,7 +60,7 @@ public:
|
||||
boost::beast::string_view doc_root,
|
||||
Request&& req,
|
||||
Send&& send
|
||||
)
|
||||
)
|
||||
{
|
||||
const std::string& route = req.target();
|
||||
const bool is_match_route = routes_pathes_.count(route);
|
||||
@@ -77,7 +96,7 @@ public:
|
||||
body.open(path.c_str(), boost::beast::file_mode::scan, ec);
|
||||
|
||||
if (ec == boost::beast::errc::no_such_file_or_directory)
|
||||
return send(SendNotFound(std::move(req),req.target()));
|
||||
return send(SendNotFound(std::move(req), req.target()));
|
||||
|
||||
if (ec)
|
||||
return send(SendServerError(std::move(req), ec.message()));
|
||||
@@ -112,7 +131,7 @@ private:
|
||||
StringResponse SendBadRequest(
|
||||
Request&& req,
|
||||
boost::beast::string_view why
|
||||
)
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::bad_request, req.version()
|
||||
@@ -128,7 +147,7 @@ private:
|
||||
StringResponse SendNotFound(
|
||||
Request&& req,
|
||||
boost::beast::string_view target
|
||||
)
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::not_found, req.version()
|
||||
@@ -144,7 +163,7 @@ private:
|
||||
StringResponse SendServerError(
|
||||
Request&& req,
|
||||
boost::beast::string_view what
|
||||
)
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::internal_server_error, req.version()
|
||||
|
||||
Reference in New Issue
Block a user