Внесение в контроллеры Session MySQL и MySQLUserDAO

This commit is contained in:
Антон
2025-08-28 08:55:43 +03:00
parent 7321240e59
commit 516b65fc1a
5 changed files with 30 additions and 8 deletions
+1
View File
@@ -1,6 +1,7 @@
#include <cstdint>
#include <vector>
#include <optional>
#pragma once
#include "../entities/User.h"
@@ -1,20 +1,33 @@
#pragma once
#include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h>
#include "IExecutor.h"
#include "../DAO/IUserDAO.h"
namespace uad
{
template <class Body, class Allocator, class ResponseType>
class AuthRegistrationExecutor : public IExecutor<Body, Allocator, ResponseType>
{
mysqlx::Session& session_;
std::shared_ptr<IUserDAO> user_dao_;
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::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
) override
{
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.set(boost::beast::http::field::content_type, "application/json");
+6 -4
View File
@@ -1,12 +1,12 @@
#pragma once
#include <memory>
#include <boost/beast.hpp>
#include "Controller.h"
#include "../db/mysql_connector.h"
#include "../DAO/IUserDAO.h"
#include "AuthRegistrationExecutor.h"
#include "RootExecutor.h"
#include "../DAO/MySQLUserDAO.h"
namespace uad
{
@@ -16,7 +16,9 @@ void HandleRequest(
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req,
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));
}
+6 -2
View File
@@ -2,6 +2,7 @@
#include "IController.h"
#include "Controller.h"
#include "AuthRegistrationExecutor.h"
#include "../DAO/IUserDAO.h"
#include "./../helpers/helpers.h"
namespace uad
@@ -22,13 +23,16 @@ class RootExecutor
private:
RoutesPathes routes_pathes_;
mysqlx::Session& session_;
std::shared_ptr<IUserDAO> user_dao_;
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>(
typename RouteController::HTTPMethodsToExecutors{
{boost::beast::http::verb::get, std::make_shared<RouteAuthRegistrationExecutor>()}
{boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(session_, user_dao_)}
}
);
}
+2
View File
@@ -1,3 +1,5 @@
#pragma once
#include <string>
namespace uad