База для ручки GetUserDiariesExecutor.h

This commit is contained in:
2026-01-17 09:55:03 +03:00
parent 2027bbb513
commit 8a61656343
3 changed files with 20 additions and 43 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ add_executable(App ./src/main.cpp
src/DAO/MySQLUserTreatmentSchemesDAO.cpp
src/DAO/MySQLUserTreatmentSchemesDAO.h
src/endpoints_handlers/GetUserTreatmentSchemeExecutor.h
src/endpoints_handlers/GetUserDiariesExecutor.h
src/endpoints_handlers/GetDiariesExecutor.h
src/DAO/IDiariesDAO.h
src/dtos/diary_dto.h
src/DAO/MySQLDiariesDao.cpp
@@ -8,24 +8,25 @@
#include "IExecutor.h"
#include "../DAO/IAuthDAO.h"
#include "../DAO/IDiariesDAO.h"
#include "../DAO/IUserTreatmentSchemesDAO.h"
#include "../exceptions/session_exception.h"
namespace uad
{
template <class Body, class Allocator, class ResponseType>
class GetUserDiariesExecutor : public IExecutor<Body, Allocator, ResponseType>
class GetDiariesExecutor : public IExecutor<Body, Allocator, ResponseType>
{
mysqlx::Session& session_;
const std::shared_ptr<IAuthDAO>& auth_dao_;
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao_;
const std::shared_ptr<IDiariesDAO>& diaries_dao_;
public:
GetUserDiariesExecutor(
GetDiariesExecutor(
mysqlx::Session& session,
const std::shared_ptr<IAuthDAO>& auth_dao,
const std::shared_ptr<IUserTreatmentSchemeDAO>& user_treatment_scheme_dao
) : session_(session), auth_dao_(auth_dao), user_treatment_scheme_dao_(user_treatment_scheme_dao)
const std::shared_ptr<IDiariesDAO>& diaries_dao
) : session_(session), auth_dao_(auth_dao), diaries_dao_(diaries_dao)
{
}
@@ -69,42 +70,5 @@ public:
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);
}
};
}
+13
View File
@@ -10,6 +10,7 @@
#include "GetUserMedicationsExecutor.h"
#include "GetUserTreatmentSchemeExecutor.h"
#include "PostUserMedicationsExecutor.h"
#include "GetDiariesExecutor.h"
#include "../DAO/IUserDAO.h"
#include "../DAO/IAuthDAO.h"
#include "../DAO/IDiariesDAO.h"
@@ -36,6 +37,8 @@ class RootExecutor
Body, Allocator, boost::beast::http::string_body>;
using RouteGetUserTreatmentSchemeExecutor = GetUserTreatmentSchemeExecutor<
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 RouteController = Controller<Body, Allocator, boost::beast::http::string_body>;
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
@@ -120,6 +123,16 @@ public:
},
}
);
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_)
},
}
);
}
void operator ()(