generated from Sithas/conan_template
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a61656343 | |||
| 2027bbb513 |
+1
-1
@@ -64,7 +64,7 @@ add_executable(App ./src/main.cpp
|
|||||||
src/DAO/MySQLUserTreatmentSchemesDAO.cpp
|
src/DAO/MySQLUserTreatmentSchemesDAO.cpp
|
||||||
src/DAO/MySQLUserTreatmentSchemesDAO.h
|
src/DAO/MySQLUserTreatmentSchemesDAO.h
|
||||||
src/endpoints_handlers/GetUserTreatmentSchemeExecutor.h
|
src/endpoints_handlers/GetUserTreatmentSchemeExecutor.h
|
||||||
src/endpoints_handlers/GetUserDiariesExecutor.h
|
src/endpoints_handlers/GetDiariesExecutor.h
|
||||||
src/DAO/IDiariesDAO.h
|
src/DAO/IDiariesDAO.h
|
||||||
src/dtos/diary_dto.h
|
src/dtos/diary_dto.h
|
||||||
src/DAO/MySQLDiariesDao.cpp
|
src/DAO/MySQLDiariesDao.cpp
|
||||||
|
|||||||
+6
-42
@@ -8,24 +8,25 @@
|
|||||||
|
|
||||||
#include "IExecutor.h"
|
#include "IExecutor.h"
|
||||||
#include "../DAO/IAuthDAO.h"
|
#include "../DAO/IAuthDAO.h"
|
||||||
|
#include "../DAO/IDiariesDAO.h"
|
||||||
#include "../DAO/IUserTreatmentSchemesDAO.h"
|
#include "../DAO/IUserTreatmentSchemesDAO.h"
|
||||||
#include "../exceptions/session_exception.h"
|
#include "../exceptions/session_exception.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
template <class Body, class Allocator, class ResponseType>
|
template <class Body, class Allocator, class ResponseType>
|
||||||
class GetUserDiariesExecutor : public IExecutor<Body, Allocator, ResponseType>
|
class GetDiariesExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||||
{
|
{
|
||||||
mysqlx::Session& session_;
|
mysqlx::Session& session_;
|
||||||
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
||||||
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao_;
|
const std::shared_ptr<IDiariesDAO>& diaries_dao_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GetUserDiariesExecutor(
|
GetDiariesExecutor(
|
||||||
mysqlx::Session& session,
|
mysqlx::Session& session,
|
||||||
const std::shared_ptr<IAuthDAO>& auth_dao,
|
const std::shared_ptr<IAuthDAO>& auth_dao,
|
||||||
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao
|
const std::shared_ptr<IDiariesDAO>& diaries_dao
|
||||||
) : session_(session), auth_dao_(auth_dao), user_treatment_scheme_dao_(user_treatment_scheme_dao)
|
) : session_(session), auth_dao_(auth_dao), diaries_dao_(diaries_dao)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,42 +70,5 @@ public:
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
boost::json::object ToJSON(const user_treatment_scheme_dto& scheme)
|
|
||||||
{
|
|
||||||
boost::json::array medications_json;
|
|
||||||
medications_json.reserve(scheme.medication_uuids.size());
|
|
||||||
|
|
||||||
for (const auto& medication_uuid : scheme.medication_uuids) {
|
|
||||||
medications_json.emplace_back(medication_uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::json::object scheme_json;
|
|
||||||
scheme_json["uuid"] = scheme.uuid;
|
|
||||||
scheme_json["treatment_name"] = scheme.treatment_name;
|
|
||||||
scheme_json["instructions"] = scheme.instructions;
|
|
||||||
scheme_json["medications"] = std::move(medications_json);
|
|
||||||
|
|
||||||
return scheme_json;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::json::array toJSONArray(const std::vector<user_treatment_scheme_dto>& schemes)
|
|
||||||
{
|
|
||||||
using namespace boost;
|
|
||||||
using namespace boost::json;
|
|
||||||
using namespace boost::beast;
|
|
||||||
using namespace std::string_literals;
|
|
||||||
using namespace std::string_view_literals;
|
|
||||||
|
|
||||||
json::array arr;
|
|
||||||
|
|
||||||
for (const auto& m : schemes)
|
|
||||||
{
|
|
||||||
arr.emplace_back(ToJSON(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::move(arr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "../DAO/MemoryAuthDAO.h"
|
#include "../DAO/MemoryAuthDAO.h"
|
||||||
#include "../DAO/MySQLUserDAO.h"
|
#include "../DAO/MySQLUserDAO.h"
|
||||||
#include "../DAO/MySQLMedicationsDAO.h"
|
#include "../DAO/MySQLMedicationsDAO.h"
|
||||||
|
#include "../DAO/MySQLDiariesDAO.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
@@ -24,13 +25,15 @@ void HandleRequest(
|
|||||||
static std::shared_ptr<IAuthDAO> auth_dao = std::make_shared<MemoryAuthDAO>(GetMySqlSession());
|
static std::shared_ptr<IAuthDAO> auth_dao = std::make_shared<MemoryAuthDAO>(GetMySqlSession());
|
||||||
static std::shared_ptr<IMedicationsDAO> medications_dao = std::make_shared<MySQLMedicationsDAO>(GetMySqlSession());
|
static std::shared_ptr<IMedicationsDAO> medications_dao = std::make_shared<MySQLMedicationsDAO>(GetMySqlSession());
|
||||||
static std::shared_ptr<IUserTreatmentSchemeDAO> user_treatment_schemes_dao = std::make_shared<MySQLUserTreatmentSchemesDAO>(GetMySqlSession());
|
static std::shared_ptr<IUserTreatmentSchemeDAO> user_treatment_schemes_dao = std::make_shared<MySQLUserTreatmentSchemesDAO>(GetMySqlSession());
|
||||||
|
static std::shared_ptr<IDiariesDAO> diaries_dao = std::make_shared<MySqlDiariesDAO>(GetMySqlSession());
|
||||||
|
|
||||||
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(),
|
GetMySqlSession(),
|
||||||
user_dao,
|
user_dao,
|
||||||
auth_dao,
|
auth_dao,
|
||||||
medications_dao,
|
medications_dao,
|
||||||
user_treatment_schemes_dao
|
user_treatment_schemes_dao,
|
||||||
|
diaries_dao
|
||||||
);
|
);
|
||||||
|
|
||||||
root_executor(doc_root, std::move(req), std::forward<Send>(send));
|
root_executor(doc_root, std::move(req), std::forward<Send>(send));
|
||||||
|
|||||||
@@ -10,8 +10,10 @@
|
|||||||
#include "GetUserMedicationsExecutor.h"
|
#include "GetUserMedicationsExecutor.h"
|
||||||
#include "GetUserTreatmentSchemeExecutor.h"
|
#include "GetUserTreatmentSchemeExecutor.h"
|
||||||
#include "PostUserMedicationsExecutor.h"
|
#include "PostUserMedicationsExecutor.h"
|
||||||
|
#include "GetDiariesExecutor.h"
|
||||||
#include "../DAO/IUserDAO.h"
|
#include "../DAO/IUserDAO.h"
|
||||||
#include "../DAO/IAuthDAO.h"
|
#include "../DAO/IAuthDAO.h"
|
||||||
|
#include "../DAO/IDiariesDAO.h"
|
||||||
#include "../DAO/IMedicationsDAO.h"
|
#include "../DAO/IMedicationsDAO.h"
|
||||||
#include "../DAO/IUserTreatmentSchemesDAO.h"
|
#include "../DAO/IUserTreatmentSchemesDAO.h"
|
||||||
#include "./../helpers/helpers.h"
|
#include "./../helpers/helpers.h"
|
||||||
@@ -35,6 +37,8 @@ class RootExecutor
|
|||||||
Body, Allocator, boost::beast::http::string_body>;
|
Body, Allocator, boost::beast::http::string_body>;
|
||||||
using RouteGetUserTreatmentSchemeExecutor = GetUserTreatmentSchemeExecutor<
|
using RouteGetUserTreatmentSchemeExecutor = GetUserTreatmentSchemeExecutor<
|
||||||
Body, Allocator, boost::beast::http::string_body>;
|
Body, Allocator, boost::beast::http::string_body>;
|
||||||
|
using RouteGetDiariesExecutor = GetDiariesExecutor<
|
||||||
|
Body, Allocator, boost::beast::http::string_body>;
|
||||||
using IRouteController = IController<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 RouteController = Controller<Body, Allocator, boost::beast::http::string_body>;
|
||||||
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
|
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
|
||||||
@@ -50,6 +54,7 @@ private:
|
|||||||
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
const std::shared_ptr<IAuthDAO>& auth_dao_;
|
||||||
const std::shared_ptr<IMedicationsDAO>& medications_dao_;
|
const std::shared_ptr<IMedicationsDAO>& medications_dao_;
|
||||||
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao_;
|
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao_;
|
||||||
|
const std::shared_ptr<IDiariesDAO>& diaries_dao_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RootExecutor(
|
RootExecutor(
|
||||||
@@ -57,11 +62,15 @@ public:
|
|||||||
const std::shared_ptr<IUserDAO>& user_dao,
|
const std::shared_ptr<IUserDAO>& user_dao,
|
||||||
const std::shared_ptr<IAuthDAO>& auth_dao,
|
const std::shared_ptr<IAuthDAO>& auth_dao,
|
||||||
const std::shared_ptr<IMedicationsDAO>& medications_dao,
|
const std::shared_ptr<IMedicationsDAO>& medications_dao,
|
||||||
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao
|
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao,
|
||||||
) :
|
const std::shared_ptr<IDiariesDAO>& diaries_dao
|
||||||
session_(session), user_dao_(user_dao),
|
) :
|
||||||
auth_dao_(auth_dao), medications_dao_(medications_dao),
|
session_(session),
|
||||||
user_treatment_scheme_dao_(user_treatment_scheme_dao)
|
user_dao_(user_dao),
|
||||||
|
auth_dao_(auth_dao),
|
||||||
|
medications_dao_(medications_dao),
|
||||||
|
user_treatment_scheme_dao_(user_treatment_scheme_dao),
|
||||||
|
diaries_dao_(diaries_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{
|
||||||
@@ -109,7 +118,18 @@ public:
|
|||||||
typename RouteController::HTTPMethodsToExecutors{
|
typename RouteController::HTTPMethodsToExecutors{
|
||||||
{
|
{
|
||||||
boost::beast::http::verb::get,
|
boost::beast::http::verb::get,
|
||||||
std::make_shared<RouteGetUserTreatmentSchemeExecutor>(session_, auth_dao_, user_treatment_scheme_dao_)
|
std::make_shared<RouteGetUserTreatmentSchemeExecutor>(session_, auth_dao_,
|
||||||
|
user_treatment_scheme_dao_)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
routes_pathes_["/api/v1/Diaries"] = std::make_unique<RouteController>(
|
||||||
|
typename RouteController::HTTPMethodsToExecutors{
|
||||||
|
{
|
||||||
|
boost::beast::http::verb::get,
|
||||||
|
std::make_shared<RouteGetDiariesExecutor>(session_, auth_dao_,
|
||||||
|
diaries_dao_)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user