diff --git a/CMakeLists.txt b/CMakeLists.txt index b7cc61e..8b80368 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/endpoints_handlers/GetUserDiariesExecutor.h b/src/endpoints_handlers/GetDiariesExecutor.h similarity index 58% rename from src/endpoints_handlers/GetUserDiariesExecutor.h rename to src/endpoints_handlers/GetDiariesExecutor.h index fac1ecd..ad5faca 100644 --- a/src/endpoints_handlers/GetUserDiariesExecutor.h +++ b/src/endpoints_handlers/GetDiariesExecutor.h @@ -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 GetUserDiariesExecutor : public IExecutor +class GetDiariesExecutor : public IExecutor { mysqlx::Session& session_; const std::shared_ptr& auth_dao_; - const std::shared_ptr& user_treatment_scheme_dao_; + const std::shared_ptr& diaries_dao_; public: - GetUserDiariesExecutor( + GetDiariesExecutor( mysqlx::Session& session, const std::shared_ptr& auth_dao, - const std::shared_ptr& user_treatment_scheme_dao - ) : session_(session), auth_dao_(auth_dao), user_treatment_scheme_dao_(user_treatment_scheme_dao) + const std::shared_ptr& 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& 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); - } }; } diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index fe57d67..9a0d97b 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -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; using RouteController = Controller; using RoutesPathes = std::unordered_map>; @@ -120,6 +123,16 @@ public: }, } ); + + routes_pathes_["/api/v1/Diaries"] = std::make_unique( + typename RouteController::HTTPMethodsToExecutors{ + { + boost::beast::http::verb::get, + std::make_shared(session_, auth_dao_, + diaries_dao_) + }, + } + ); } void operator ()(