From f56c14b3da6a99d5b1e0891ca89dc795bdd375b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Fri, 16 Jan 2026 07:40:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=B0=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=80=D1=83=D1=87=D0=BA=D0=B8=20PostUserMedicationsExecutor?= =?UTF-8?q?.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 ++ README.md | 4 +- src/DAO/IDiariesDAO.h | 17 ++++++++ src/DAO/MySQLDiariesDAO.cpp | 64 ++++++++++++++++++++++++++++++ src/DAO/MySQLDiariesDAO.h | 20 ++++++++++ src/dtos/diary_dto.h | 22 ++++++++++ src/endpoints_handlers/IExecutor.h | 40 +++++++++---------- 7 files changed, 150 insertions(+), 21 deletions(-) create mode 100644 src/DAO/IDiariesDAO.h create mode 100644 src/DAO/MySQLDiariesDAO.cpp create mode 100644 src/DAO/MySQLDiariesDAO.h create mode 100644 src/dtos/diary_dto.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 946c041..0efb83f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,10 @@ add_executable(App ./src/main.cpp src/DAO/MySQLUserTreatmentSchemesDAO.cpp src/DAO/MySQLUserTreatmentSchemesDAO.h src/endpoints_handlers/GetUserTreatmentSchemeExecutor.h + src/DAO/IDiariesDAO.h + src/dtos/diary_dto.h + src/DAO/MySQLDiariesDao.cpp + src/DAO/MySQLDiariesDao.h ) target_link_libraries(App PRIVATE Boost::boost diff --git a/README.md b/README.md index 9471a9b..77146fe 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ - ~~Заменить internal_server_error на bad_request и перепроверить коды ошибок~~ - ~~Создание и удаление вспомогательных классов должно быть вынесено в фикстуру~~ - ~~К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов~~ +- Попробовать nodiscard к executoru +- Найти слабые места в C++ -- std::forward, universal reference # UseCase'ы приложения: @@ -193,7 +195,7 @@ null "dream_level": 6, "anxiety_level": 7, "comment": "Накрыл психоз. Выпил одну таблетку аминазина" - "treatment_scheme_uuid": bf6d1555-39e9-4d73-8928-4763627f4dd5 + "user_treatment_scheme_uuid": bf6d1555-39e9-4d73-8928-4763627f4dd5 } ] } diff --git a/src/DAO/IDiariesDAO.h b/src/DAO/IDiariesDAO.h new file mode 100644 index 0000000..e5de2e8 --- /dev/null +++ b/src/DAO/IDiariesDAO.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#include "./../dtos/diary_dto.h" + +namespace uad +{ +class IDiariesDAO +{ +public: + virtual std::vector GetDiariesByLogin(const std::string& login) = 0; + + virtual ~IDiariesDAO() = default; +}; +} diff --git a/src/DAO/MySQLDiariesDAO.cpp b/src/DAO/MySQLDiariesDAO.cpp new file mode 100644 index 0000000..d33d8e6 --- /dev/null +++ b/src/DAO/MySQLDiariesDAO.cpp @@ -0,0 +1,64 @@ +#include "MySQLDiariesDAO.h" + +namespace uad +{ +MySqlDiariesDAO::MySqlDiariesDAO(mysqlx::Session& session) : session_(session) +{ +} + +std::vector MySqlDiariesDAO::GetDiariesByLogin(const std::string& login) +{ + static const std::string query = R"( + SELECT + d.uuid, + UNIX_TIMESTAMP(d.time) * 1000 AS time_ms, + d.mania_level, + d.depression_level, + d.mood_level, + d.activity_level, + d.appetite_level, + d.dream_level, + d.anxiety_level, + d.comment, + d.user_treatment_schemes_uuid + FROM up_and_down.users u + JOIN up_and_down.diaries d + ON d.user_uuid = u.uuid + WHERE u.login = ? + ORDER BY d.time ASC + )"; + + mysqlx::SqlResult result = session_ + .sql(query) + .bind(login) + .execute(); + + std::vector diaries; + diaries.reserve(result.count()); + + for (const mysqlx::Row& row : result) + { + diary_dto dto; + + dto.uuid = row[0].get(); + dto.time_ms = row[1].get(); + dto.mania_level = row[2].get(); + dto.depression_level = row[3].get(); + dto.mood_level = row[4].get(); + dto.activity_level = row[5].get(); + dto.appetite_level = row[6].get(); + dto.dream_level = row[7].get(); + dto.anxiety_level = row[8].get(); + + dto.comment = + row[9].isNull() ? "" : row[9].get(); + + dto.user_treatment_scheme_uuid = + row[10].isNull() ? "" : row[10].get(); + + diaries.push_back(std::move(dto)); + } + + return diaries; +} +} diff --git a/src/DAO/MySQLDiariesDAO.h b/src/DAO/MySQLDiariesDAO.h new file mode 100644 index 0000000..276a64f --- /dev/null +++ b/src/DAO/MySQLDiariesDAO.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "./../DAO/IDiariesDao.h" +#include "./../db/mysql_connector.h" + +namespace uad +{ +class MySqlDiariesDAO final : public IDiariesDAO +{ + mysqlx::Session& session_; +public: + explicit MySqlDiariesDAO(mysqlx::Session& session); + + std::vector GetDiariesByLogin(const std::string& login) override; + +}; +} \ No newline at end of file diff --git a/src/dtos/diary_dto.h b/src/dtos/diary_dto.h new file mode 100644 index 0000000..d666df5 --- /dev/null +++ b/src/dtos/diary_dto.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +namespace uad +{ +struct diary_dto +{ + std::string uuid; + int64_t time_ms; + int64_t mania_level; + int64_t depression_level; + int64_t mood_level; + int64_t activity_level; + int64_t appetite_level; + int64_t dream_level; + int64_t anxiety_level; + std::string comment; + std::string user_treatment_scheme_uuid; +}; +} diff --git a/src/endpoints_handlers/IExecutor.h b/src/endpoints_handlers/IExecutor.h index ab7a675..5505e43 100644 --- a/src/endpoints_handlers/IExecutor.h +++ b/src/endpoints_handlers/IExecutor.h @@ -14,24 +14,24 @@ public: virtual ~IExecutor() = default; }; -class IAuthorizable : public IExecutor -{ - IExecutor& next_executor_; -public: - IAuthorizable(IExecutor& next_executor): next_executor_(next_executor) - { - - } - - boost::beast::http::response operator ()( - boost::beast::http::request>&& req - ) override - { - // Логика проверки авторизации - // передать управление следующему executorу - возврат req - // посмотреть chain of responsibility, composite - // выбрасывать исключение здесь - return next_executor_(req); - } -}; +// class IAuthorizable : public IExecutor +// { +// IExecutor& next_executor_; +// public: +// IAuthorizable(IExecutor& next_executor): next_executor_(next_executor) +// { +// +// } +// +// boost::beast::http::response operator ()( +// boost::beast::http::request>&& req +// ) override +// { +// // Логика проверки авторизации +// // передать управление следующему executorу - возврат req +// // посмотреть chain of responsibility, composite +// // выбрасывать исключение здесь +// return next_executor_(req); +// } +// }; }