generated from Sithas/conan_template
Внесение в контроллеры Session MySQL и MySQLUserDAO
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "../entities/User.h"
|
#include "../entities/User.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,33 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <mysqlx/xdevapi.h>
|
||||||
|
#include <mysqlx/common/api.h>
|
||||||
|
|
||||||
#include "IExecutor.h"
|
#include "IExecutor.h"
|
||||||
|
#include "../DAO/IUserDAO.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
template <class Body, class Allocator, class ResponseType>
|
template <class Body, class Allocator, class ResponseType>
|
||||||
class AuthRegistrationExecutor : public IExecutor<Body, Allocator, ResponseType>
|
class AuthRegistrationExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||||
{
|
{
|
||||||
|
mysqlx::Session& session_;
|
||||||
|
std::shared_ptr<IUserDAO> user_dao_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
AuthRegistrationExecutor(mysqlx::Session& session,
|
||||||
|
std::shared_ptr<IUserDAO> user_dao)
|
||||||
|
: session_(session), user_dao_(user_dao)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
boost::beast::http::response<ResponseType> operator ()(
|
boost::beast::http::response<ResponseType> operator ()(
|
||||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||||
) override
|
) override
|
||||||
{
|
{
|
||||||
boost::beast::http::response<ResponseType> res{
|
boost::beast::http::response<ResponseType> res{
|
||||||
boost::beast::http::status::ok, req.version()
|
boost::beast::http::status::ok, req.version()
|
||||||
};
|
};
|
||||||
|
|
||||||
res.body() = "{ \"detail\": \"ok\"}";
|
res.body() = "{ \"detail\": \"ok\"}";
|
||||||
res.set(boost::beast::http::field::content_type, "application/json");
|
res.set(boost::beast::http::field::content_type, "application/json");
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <boost/beast.hpp>
|
#include <boost/beast.hpp>
|
||||||
|
|
||||||
#include "Controller.h"
|
#include "../db/mysql_connector.h"
|
||||||
|
#include "../DAO/IUserDAO.h"
|
||||||
#include "AuthRegistrationExecutor.h"
|
#include "AuthRegistrationExecutor.h"
|
||||||
#include "RootExecutor.h"
|
#include "RootExecutor.h"
|
||||||
|
#include "../DAO/MySQLUserDAO.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,9 @@ void HandleRequest(
|
|||||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req,
|
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req,
|
||||||
Send&& send)
|
Send&& send)
|
||||||
{
|
{
|
||||||
static RootExecutor<Body, Allocator, boost::beast::http::string_body, Send> root_executor;
|
static RootExecutor<Body, Allocator, boost::beast::http::string_body, Send> root_executor(
|
||||||
|
GetMySqlSession(), std::make_shared<MySQLUserDAO>(GetMySqlSession())
|
||||||
|
);
|
||||||
|
|
||||||
root_executor(doc_root, std::move(req), std::forward<Send>(send));
|
root_executor(doc_root, std::move(req), std::forward<Send>(send));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "IController.h"
|
#include "IController.h"
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
#include "AuthRegistrationExecutor.h"
|
#include "AuthRegistrationExecutor.h"
|
||||||
|
#include "../DAO/IUserDAO.h"
|
||||||
#include "./../helpers/helpers.h"
|
#include "./../helpers/helpers.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
@@ -22,13 +23,16 @@ class RootExecutor
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
RoutesPathes routes_pathes_;
|
RoutesPathes routes_pathes_;
|
||||||
|
mysqlx::Session& session_;
|
||||||
|
std::shared_ptr<IUserDAO> user_dao_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RootExecutor()
|
RootExecutor(mysqlx::Session& session, std::shared_ptr<IUserDAO> user_dao)
|
||||||
|
: session_(session), user_dao_(user_dao)
|
||||||
{
|
{
|
||||||
routes_pathes_["/api/v1/Auth/Register"] = std::make_unique<RouteController>(
|
routes_pathes_["/api/v1/Auth/Register"] = std::make_unique<RouteController>(
|
||||||
typename RouteController::HTTPMethodsToExecutors{
|
typename RouteController::HTTPMethodsToExecutors{
|
||||||
{boost::beast::http::verb::get, std::make_shared<RouteAuthRegistrationExecutor>()}
|
{boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(session_, user_dao_)}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
|
|||||||
Reference in New Issue
Block a user