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

This commit is contained in:
2026-01-10 17:24:17 +03:00
parent 8eb44b6e45
commit a81952e40e
6 changed files with 17 additions and 10 deletions
+1
View File
@@ -63,6 +63,7 @@ add_executable(App ./src/main.cpp
src/DAO/IUserTreatmentSchemesDAO.h src/DAO/IUserTreatmentSchemesDAO.h
src/DAO/MySQLUserTreatmentSchemesDAO.cpp src/DAO/MySQLUserTreatmentSchemesDAO.cpp
src/DAO/MySQLUserTreatmentSchemesDAO.h src/DAO/MySQLUserTreatmentSchemesDAO.h
src/endpoints_handlers/GetUserTreatmentSchemesExecutor.h
) )
target_link_libraries(App PRIVATE Boost::boost target_link_libraries(App PRIVATE Boost::boost
+2 -2
View File
@@ -175,7 +175,7 @@ null
* Пользователю доступны операции добавления, модификации и удаления записей, а также схем лечения * Пользователю доступны операции добавления, модификации и удаления записей, а также схем лечения
### 8.API-Маршруты ### 8.API-Маршруты
* `GET /api/v1/User/Diaries` - получить кусок дневника пользователя (требует Authorization: Bearer <token>) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20) * `GET /api/v1/User/Diaries` - получить кусок дневника пользователя (требует Authorization: Bearer <token>) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20)
* `GET /api/v1/User/TreatmentSchemes` - получить список схем пользователя (требует Authorization: Bearer <token>) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20) * `GET /api/v1/UserTreatmentSchemes` - получить список схем пользователя (требует Authorization: Bearer <token>) query-параметры: from (int, по умолч. 0), count (int, по умолч. 20)
### 9.Контракт ### 9.Контракт
#### Diaries-Request #### Diaries-Request
##### Response - 200 - OK ##### Response - 200 - OK
@@ -201,7 +201,7 @@ null
##### Errors ##### Errors
* `401 TOKEN_REQUIRED|TOKEN_EXPIRED` — токен недействителен, либо отсутствует * `401 TOKEN_REQUIRED|TOKEN_EXPIRED` — токен недействителен, либо отсутствует
* `500 DATA_LOAD_FAILED` — ошибка при загрузке данных (`B1`) * `500 DATA_LOAD_FAILED` — ошибка при загрузке данных (`B1`)
#### TreatmentSchemes-Request #### UserTreatmentSchemes-Request
##### Response - 200 - OK ##### Response - 200 - OK
``` ```
{ {
+2 -5
View File
@@ -13,7 +13,7 @@ MySQLUserTreatmentSchemesDAO::MySQLUserTreatmentSchemesDAO(mysqlx::Session& sess
std::vector<user_treatment_scheme_dto> MySQLUserTreatmentSchemesDAO::FindByUserLogin( std::vector<user_treatment_scheme_dto> MySQLUserTreatmentSchemesDAO::FindByUserLogin(
const std::string& login) const std::string& login)
{ {
const std::string query = R"( static const std::string query = R"(
SELECT SELECT
uts.uuid, uts.uuid,
uts.treatment_name, uts.treatment_name,
@@ -28,10 +28,7 @@ std::vector<user_treatment_scheme_dto> MySQLUserTreatmentSchemesDAO::FindByUserL
ORDER BY uts.uuid ORDER BY uts.uuid
)"; )";
mysqlx::SqlStatement stmt = session_.sql(query); mysqlx::SqlResult result = session_.sql(query).bind(login).execute();
stmt.bind(login);
mysqlx::SqlResult result = stmt.execute();
std::unordered_map<std::string, user_treatment_scheme_dto> scheme_map; std::unordered_map<std::string, user_treatment_scheme_dto> scheme_map;
+4 -1
View File
@@ -5,6 +5,7 @@
#include "../db/mysql_connector.h" #include "../db/mysql_connector.h"
#include "../DAO/IUserDAO.h" #include "../DAO/IUserDAO.h"
#include "../DAO/IMedicationsDAO.h" #include "../DAO/IMedicationsDAO.h"
#include "../DAO/MySQLUserTreatmentSchemesDAO.h"
#include "AuthRegistrationExecutor.h" #include "AuthRegistrationExecutor.h"
#include "RootExecutor.h" #include "RootExecutor.h"
#include "../DAO/MemoryAuthDAO.h" #include "../DAO/MemoryAuthDAO.h"
@@ -22,12 +23,14 @@ void HandleRequest(
static std::shared_ptr<IUserDAO> user_dao = std::make_shared<MySQLUserDAO>(GetMySqlSession()); static std::shared_ptr<IUserDAO> user_dao = std::make_shared<MySQLUserDAO>(GetMySqlSession());
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 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
); );
root_executor(doc_root, std::move(req), std::forward<Send>(send)); root_executor(doc_root, std::move(req), std::forward<Send>(send));
+8 -2
View File
@@ -12,6 +12,7 @@
#include "../DAO/IUserDAO.h" #include "../DAO/IUserDAO.h"
#include "../DAO/IAuthDAO.h" #include "../DAO/IAuthDAO.h"
#include "../DAO/IMedicationsDAO.h" #include "../DAO/IMedicationsDAO.h"
#include "../DAO/IUserTreatmentSchemesDAO.h"
#include "./../helpers/helpers.h" #include "./../helpers/helpers.h"
#include "./../exceptions/session_exception.h" #include "./../exceptions/session_exception.h"
@@ -45,14 +46,19 @@ private:
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_;
public: public:
RootExecutor( RootExecutor(
mysqlx::Session& session, mysqlx::Session& session,
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,
session_(session), user_dao_(user_dao), auth_dao_(auth_dao), medications_dao_(medications_dao) const std::shared_ptr<IUserTreatmentSchemeDAO>& 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<RouteController>( routes_pathes_["/api/v1/Auth/Register"] = std::make_unique<RouteController>(
typename RouteController::HTTPMethodsToExecutors{ typename RouteController::HTTPMethodsToExecutors{