diff --git a/CMakeLists.txt b/CMakeLists.txt index ebcf5b1..8bd66d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ add_executable(App ./src/main.cpp src/DAO/IUserTreatmentSchemesDAO.h src/DAO/MySQLUserTreatmentSchemesDAO.cpp src/DAO/MySQLUserTreatmentSchemesDAO.h + src/endpoints_handlers/GetUserTreatmentSchemesExecutor.h ) target_link_libraries(App PRIVATE Boost::boost diff --git a/README.md b/README.md index 131c665..9471a9b 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ null * Пользователю доступны операции добавления, модификации и удаления записей, а также схем лечения ### 8.API-Маршруты * `GET /api/v1/User/Diaries` - получить кусок дневника пользователя (требует Authorization: Bearer ) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20) -* `GET /api/v1/User/TreatmentSchemes` - получить список схем пользователя (требует Authorization: Bearer ) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20) +* `GET /api/v1/UserTreatmentSchemes` - получить список схем пользователя (требует Authorization: Bearer ) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20) ### 9.Контракт #### Diaries-Request ##### Response - 200 - OK @@ -201,7 +201,7 @@ null ##### Errors * `401 TOKEN_REQUIRED|TOKEN_EXPIRED` — токен недействителен, либо отсутствует * `500 DATA_LOAD_FAILED` — ошибка при загрузке данных (`B1`) -#### TreatmentSchemes-Request +#### UserTreatmentSchemes-Request ##### Response - 200 - OK ``` { diff --git a/src/DAO/MySQLUserTreatmentSchemesDAO.cpp b/src/DAO/MySQLUserTreatmentSchemesDAO.cpp index 77526b9..c4567f3 100644 --- a/src/DAO/MySQLUserTreatmentSchemesDAO.cpp +++ b/src/DAO/MySQLUserTreatmentSchemesDAO.cpp @@ -13,7 +13,7 @@ MySQLUserTreatmentSchemesDAO::MySQLUserTreatmentSchemesDAO(mysqlx::Session& sess std::vector MySQLUserTreatmentSchemesDAO::FindByUserLogin( const std::string& login) { - const std::string query = R"( + static const std::string query = R"( SELECT uts.uuid, uts.treatment_name, @@ -28,10 +28,7 @@ std::vector MySQLUserTreatmentSchemesDAO::FindByUserL ORDER BY uts.uuid )"; - mysqlx::SqlStatement stmt = session_.sql(query); - stmt.bind(login); - - mysqlx::SqlResult result = stmt.execute(); + mysqlx::SqlResult result = session_.sql(query).bind(login).execute(); std::unordered_map scheme_map; diff --git a/src/endpoints_handlers/GetUserTreatmentSchemesExecutor.h b/src/endpoints_handlers/GetUserTreatmentSchemesExecutor.h new file mode 100644 index 0000000..e69de29 diff --git a/src/endpoints_handlers/HandleRequest.h b/src/endpoints_handlers/HandleRequest.h index 77422a3..47112ab 100644 --- a/src/endpoints_handlers/HandleRequest.h +++ b/src/endpoints_handlers/HandleRequest.h @@ -5,6 +5,7 @@ #include "../db/mysql_connector.h" #include "../DAO/IUserDAO.h" #include "../DAO/IMedicationsDAO.h" +#include "../DAO/MySQLUserTreatmentSchemesDAO.h" #include "AuthRegistrationExecutor.h" #include "RootExecutor.h" #include "../DAO/MemoryAuthDAO.h" @@ -22,12 +23,14 @@ void HandleRequest( static std::shared_ptr user_dao = std::make_shared(GetMySqlSession()); static std::shared_ptr auth_dao = std::make_shared(GetMySqlSession()); static std::shared_ptr medications_dao = std::make_shared(GetMySqlSession()); + static std::shared_ptr user_treatment_schemes_dao = std::make_shared(GetMySqlSession()); static RootExecutor root_executor( GetMySqlSession(), user_dao, auth_dao, - medications_dao + medications_dao, + user_treatment_schemes_dao ); root_executor(doc_root, std::move(req), std::forward(send)); diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index 6b396f8..f605348 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -12,6 +12,7 @@ #include "../DAO/IUserDAO.h" #include "../DAO/IAuthDAO.h" #include "../DAO/IMedicationsDAO.h" +#include "../DAO/IUserTreatmentSchemesDAO.h" #include "./../helpers/helpers.h" #include "./../exceptions/session_exception.h" @@ -45,14 +46,19 @@ private: const std::shared_ptr& user_dao_; const std::shared_ptr& auth_dao_; const std::shared_ptr& medications_dao_; + const std::shared_ptr& user_treatment_scheme_dao_; public: RootExecutor( mysqlx::Session& session, const std::shared_ptr& user_dao, const std::shared_ptr& auth_dao, - const std::shared_ptr& medications_dao) : - session_(session), user_dao_(user_dao), auth_dao_(auth_dao), medications_dao_(medications_dao) + const std::shared_ptr& medications_dao, + const std::shared_ptr& user_treatment_scheme_dao + ) : + session_(session), user_dao_(user_dao), + auth_dao_(auth_dao), medications_dao_(medications_dao), + user_treatment_scheme_dao_(user_treatment_scheme_dao) { routes_pathes_["/api/v1/Auth/Register"] = std::make_unique( typename RouteController::HTTPMethodsToExecutors{