From 49a2913884d5effedc6115ef04d1a165ef3404ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Sun, 4 Jan 2026 18:18:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 ++ README.md | 51 +++--------------- db_assets/sql_scripts/init.sql | 5 +- src/DAO/IMedicationsDAO.h | 19 +++++++ src/endpoints_handlers/RootExecutor.h | 54 ++++++++++++------- .../UserGetMedicationsExecutor.h | 35 ++++++++++++ src/entities/medication.h | 15 ++++++ src/main.cpp | 4 +- 8 files changed, 119 insertions(+), 67 deletions(-) create mode 100644 src/DAO/IMedicationsDAO.h create mode 100644 src/endpoints_handlers/UserGetMedicationsExecutor.h create mode 100644 src/entities/medication.h diff --git a/CMakeLists.txt b/CMakeLists.txt index eed074c..0ba2b85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ add_executable(App ./src/main.cpp ./src/db/mysql_connector.h ./src/DAO/IUserDAO.h ./src/entities/user.h + ./src/entities/medication.h ./src/DAO/MySQLUserDAO.cpp ./src/DAO/MySQLUserDAO.h ./src/endpoints_handlers/IExecutor.h @@ -54,6 +55,8 @@ add_executable(App ./src/main.cpp src/log/Log.h src/log/Log.cpp tests/fixtures/AuthFixture.h + src/endpoints_handlers/UserGetMedicationsExecutor.h + src/DAO/IMedicationsDAO.h ) target_link_libraries(App PRIVATE Boost::boost diff --git a/README.md b/README.md index 0967ef3..9cae26d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ - Возможно, сделать тесты на CI/CD - приоритет - низкий - ~~Заменить internal_server_error на bad_request и перепроверить коды ошибок~~ - ~~Создание и удаление вспомогательных классов должно быть вынесено в фикстуру~~ -- К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов +- ~~К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов~~ # UseCase'ы приложения: @@ -321,13 +321,7 @@ null "treatment_name": "Bipolar I Scheme Urgent", "instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.", "medications": [ - { - "uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b", - "name": "Aminazin", - "dose": 100, - "unit": "mg", - "is_urgent": true - } + "eda5a5f7-167a-44b9-900d-c5c6acfc249b" ] }, } @@ -414,13 +408,7 @@ null "treatment_name": "Bipolar I Scheme Urgent", "instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.", "medications": [ - { - "uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b", - "name": "Aminazin", - "dose": 100, - "unit": "mg", - "is_urgent": true - } + "eda5a5f7-167a-44b9-900d-c5c6acfc249b" ] }, } @@ -504,20 +492,8 @@ null "treatment_name": "Bipolar I Scheme Urgent", "instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.", "medications": [ - { - "uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b", - "name": "Aminazin", - "dose": 100, - "unit": "mg", - "is_urgent": true - }, - { - "uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b", - "name": "Haloperidol", - "dose": 15, - "unit": "mg", - "is_urgent": false - } + "eca5a5f7-167a-44b9-900d-c5c6acfc249b", + "eda5a5f7-167a-44b9-900d-c5c6acfc249b" ] } ``` @@ -531,27 +507,14 @@ null "treatment_name": "Bipolar I Scheme Urgent", "instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.", "medications": [ - { - "uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b", - "name": "Aminazin", - "dose": 100, - "unit": "mg", - "is_urgent": true - }, - { - "uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b", - "name": "Haloperidol", - "dose": 15, - "unit": "mg", - "is_urgent": false - } + "eca5a5f7-167a-44b9-900d-c5c6acfc249b", + "eda5a5f7-167a-44b9-900d-c5c6acfc249b" ] } ``` ##### Errors * `400 BAD_REQUEST` — сервер не смог десереализовать JSON * `400 BAD_REQUEST` — Обязательные поля заполнены неправильно -* `409 SCHEME_ALREADYEXISTS` - такая схема уже существует ### 10. Используемые сущности ДБ * user_treatment_schemes(uuid, user_uuid, treatment_name, instructions) * medications(uuid, name, dose, unit, is_urgent) diff --git a/db_assets/sql_scripts/init.sql b/db_assets/sql_scripts/init.sql index 3dbbd63..211baf6 100644 --- a/db_assets/sql_scripts/init.sql +++ b/db_assets/sql_scripts/init.sql @@ -85,12 +85,13 @@ CREATE TABLE `up_and_down`.`diaries` ( ); CREATE TABLE `up_and_down`.`medications` ( - `uuid` CHAR(36) NOT NULL, + `uuid` CHAR(36) NOT NULL, `name` TEXT NOT NULL, `dose` int8 NOT NULL, `unit` CHAR(30), `is_urgent` BOOL NOT NULL, - PRIMARY KEY (`uuid`) + PRIMARY KEY (`uuid`), + UNIQUE KEY `uniq_medication` (`name`(255), `dose`, `unit`, `is_urgent`) ); CREATE TABLE `up_and_down`.`treatment_schemes` ( diff --git a/src/DAO/IMedicationsDAO.h b/src/DAO/IMedicationsDAO.h new file mode 100644 index 0000000..f4e7ee2 --- /dev/null +++ b/src/DAO/IMedicationsDAO.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +#include "../entities/medication.h" + +namespace uad +{ +class IMedicationsDAO +{ +public: + virtual std::vector GetAll() = 0; + + virtual std::string Create(medication) = 0; + + virtual ~IMedicationsDAO() = default; +}; +} diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index 27cacfc..be91570 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -7,6 +7,7 @@ #include "AuthRegistrationExecutor.h" #include "AuthLoginExecutor.h" #include "AuthLogoutExecutor.h" +#include "UserGetMedicationsExecutor.h" #include "../DAO/IUserDAO.h" #include "../DAO/IAuthDAO.h" #include "./../helpers/helpers.h" @@ -24,6 +25,8 @@ class RootExecutor Body, Allocator, boost::beast::http::string_body>; using RouteAuthLogoutExecutor = AuthLogoutExecutor< Body, Allocator, boost::beast::http::string_body>; + using RouteUserGetMedicationsExecutor = UserGetMedicationsExecutor< + Body, Allocator, boost::beast::http::string_body>; using IRouteController = IController; using RouteController = Controller; using RoutesPathes = std::unordered_map>; @@ -46,26 +49,41 @@ public: session_(session), user_dao_(user_dao), auth_dao_(auth_dao) { routes_pathes_["/api/v1/Auth/Register"] = std::make_unique( - typename RouteController::HTTPMethodsToExecutors{ - {boost::beast::http::verb::post, std::make_shared( - session_, - user_dao_ - )} - } + typename RouteController::HTTPMethodsToExecutors{ + { + boost::beast::http::verb::post, std::make_shared( + session_, + user_dao_ + ) + } + } ); routes_pathes_["/api/v1/Auth/Login"] = std::make_unique( - typename RouteController::HTTPMethodsToExecutors{ - {boost::beast::http::verb::post, - std::make_shared(session_, user_dao_, auth_dao_)} - } + typename RouteController::HTTPMethodsToExecutors{ + { + boost::beast::http::verb::post, + std::make_shared(session_, user_dao_, auth_dao_) + } + } ); routes_pathes_["/api/v1/Auth/Logout"] = std::make_unique( - typename RouteController::HTTPMethodsToExecutors{ - {boost::beast::http::verb::post, - std::make_shared(session_, auth_dao_)} - } + typename RouteController::HTTPMethodsToExecutors{ + { + boost::beast::http::verb::post, + std::make_shared(session_, auth_dao_) + } + } + ); + + routes_pathes_["api/v1/User/Medications"] = std::make_unique( + typename RouteController::HTTPMethodsToExecutors{ + { + boost::beast::http::verb::get, + std::make_shared() + } + } ); } @@ -73,7 +91,7 @@ public: boost::beast::string_view doc_root, Request&& req, Send&& send - ) + ) { const std::string& route = req.target(); const bool is_match_route = routes_pathes_.count(route); @@ -163,7 +181,7 @@ private: StringResponse SendBadRequest( Request&& req, boost::beast::string_view why - ) + ) { StringResponse res{ boost::beast::http::status::bad_request, req.version() @@ -179,7 +197,7 @@ private: StringResponse SendNotFound( Request&& req, boost::beast::string_view target - ) + ) { StringResponse res{ boost::beast::http::status::not_found, req.version() @@ -195,7 +213,7 @@ private: StringResponse SendServerError( Request&& req, boost::beast::string_view what - ) + ) { StringResponse res{ boost::beast::http::status::internal_server_error, req.version() diff --git a/src/endpoints_handlers/UserGetMedicationsExecutor.h b/src/endpoints_handlers/UserGetMedicationsExecutor.h new file mode 100644 index 0000000..ef3dea3 --- /dev/null +++ b/src/endpoints_handlers/UserGetMedicationsExecutor.h @@ -0,0 +1,35 @@ +#pragma once +#include + +#include +#include +#include + +#include "IExecutor.h" +#include "../DAO/IUserDAO.h" +#include "../exceptions/session_exception.h" + +namespace uad +{ +template +class UserGetMedicationsExecutor : public IExecutor +{ +public: + UserGetMedicationsExecutor() = default; + + boost::beast::http::response operator ()( + boost::beast::http::request>&& req + ) override + { + using namespace boost; + using namespace boost::json; + using namespace boost::beast; + using namespace std::string_literals; + + + http::response res{http::status::ok, req.version()}; + + return res; + } +}; +} diff --git a/src/entities/medication.h b/src/entities/medication.h new file mode 100644 index 0000000..4644577 --- /dev/null +++ b/src/entities/medication.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#include "../helpers/helpers.h" + +namespace uad +{ +struct medication +{ + std::string uuid; + std::string login; + std::string hashed_password; +}; +} diff --git a/src/main.cpp b/src/main.cpp index 8924612..925f75c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,8 +50,6 @@ int main(int argc, char* argv[]) InitLogs(); - // Добавление общих атрибутов (включая время) - uad::SetMySqlSession(new mysqlx::Session(mysql_credentials)); net::io_context ioc{threads}; @@ -61,7 +59,7 @@ int main(int argc, char* argv[]) net::signal_set signals(ioc, SIGINT, SIGTERM); signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); }); - BOOST_LOG_TRIVIAL(info) << "Приложение запущено2"; + BOOST_LOG_TRIVIAL(info) << "Приложение запущено"; std::vector v; v.reserve(threads - 1);