generated from Sithas/conan_template
Постановка нового маршрута
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "../entities/medication.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class IMedicationsDAO
|
||||
{
|
||||
public:
|
||||
virtual std::vector<medication> GetAll() = 0;
|
||||
|
||||
virtual std::string Create(medication) = 0;
|
||||
|
||||
virtual ~IMedicationsDAO() = default;
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "AuthRegistrationExecutor.h"
|
||||
#include "AuthLoginExecutor.h"
|
||||
#include "AuthLogoutExecutor.h"
|
||||
#include "UserGetMedicationsExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../DAO/IAuthDAO.h"
|
||||
#include "./../helpers/helpers.h"
|
||||
@@ -24,6 +25,8 @@ class RootExecutor
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteAuthLogoutExecutor = AuthLogoutExecutor<
|
||||
Body, Allocator, boost::beast::http::string_body>;
|
||||
using RouteUserGetMedicationsExecutor = UserGetMedicationsExecutor<
|
||||
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>>;
|
||||
@@ -46,26 +49,41 @@ public:
|
||||
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_)}
|
||||
}
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{
|
||||
boost::beast::http::verb::post,
|
||||
std::make_shared<RouteAuthLoginExecutor>(session_, user_dao_, auth_dao_)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
routes_pathes_["/api/v1/Auth/Logout"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{boost::beast::http::verb::post,
|
||||
std::make_shared<RouteAuthLogoutExecutor>(session_, auth_dao_)}
|
||||
}
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{
|
||||
boost::beast::http::verb::post,
|
||||
std::make_shared<RouteAuthLogoutExecutor>(session_, auth_dao_)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
routes_pathes_["api/v1/User/Medications"] = std::make_unique<RouteController>(
|
||||
typename RouteController::HTTPMethodsToExecutors{
|
||||
{
|
||||
boost::beast::http::verb::get,
|
||||
std::make_shared<RouteUserGetMedicationsExecutor>()
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,7 +91,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);
|
||||
@@ -163,7 +181,7 @@ private:
|
||||
StringResponse SendBadRequest(
|
||||
Request&& req,
|
||||
boost::beast::string_view why
|
||||
)
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::bad_request, req.version()
|
||||
@@ -179,7 +197,7 @@ private:
|
||||
StringResponse SendNotFound(
|
||||
Request&& req,
|
||||
boost::beast::string_view target
|
||||
)
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::not_found, req.version()
|
||||
@@ -195,7 +213,7 @@ private:
|
||||
StringResponse SendServerError(
|
||||
Request&& req,
|
||||
boost::beast::string_view what
|
||||
)
|
||||
)
|
||||
{
|
||||
StringResponse res{
|
||||
boost::beast::http::status::internal_server_error, req.version()
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include <regex>
|
||||
#include <boost/json.hpp>
|
||||
#include <mysqlx/xdevapi.h>
|
||||
|
||||
#include "IExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../exceptions/session_exception.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
template <class Body, class Allocator, class ResponseType>
|
||||
class UserGetMedicationsExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||
{
|
||||
public:
|
||||
UserGetMedicationsExecutor() = default;
|
||||
|
||||
boost::beast::http::response<ResponseType> operator ()(
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) override
|
||||
{
|
||||
using namespace boost;
|
||||
using namespace boost::json;
|
||||
using namespace boost::beast;
|
||||
using namespace std::string_literals;
|
||||
|
||||
|
||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
struct medication
|
||||
{
|
||||
std::string uuid;
|
||||
std::string login;
|
||||
std::string hashed_password;
|
||||
};
|
||||
}
|
||||
+1
-3
@@ -50,8 +50,6 @@ int main(int argc, char* argv[])
|
||||
|
||||
InitLogs();
|
||||
|
||||
// Добавление общих атрибутов (включая время)
|
||||
|
||||
uad::SetMySqlSession(new mysqlx::Session(mysql_credentials));
|
||||
|
||||
net::io_context ioc{threads};
|
||||
@@ -61,7 +59,7 @@ int main(int argc, char* argv[])
|
||||
net::signal_set signals(ioc, SIGINT, SIGTERM);
|
||||
signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); });
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Приложение запущено2";
|
||||
BOOST_LOG_TRIVIAL(info) << "Приложение запущено";
|
||||
|
||||
std::vector<std::thread> v;
|
||||
v.reserve(threads - 1);
|
||||
|
||||
Reference in New Issue
Block a user