generated from Sithas/conan_template
Постановка нового маршрута
This commit is contained in:
@@ -39,6 +39,7 @@ add_executable(App ./src/main.cpp
|
|||||||
./src/db/mysql_connector.h
|
./src/db/mysql_connector.h
|
||||||
./src/DAO/IUserDAO.h
|
./src/DAO/IUserDAO.h
|
||||||
./src/entities/user.h
|
./src/entities/user.h
|
||||||
|
./src/entities/medication.h
|
||||||
./src/DAO/MySQLUserDAO.cpp
|
./src/DAO/MySQLUserDAO.cpp
|
||||||
./src/DAO/MySQLUserDAO.h
|
./src/DAO/MySQLUserDAO.h
|
||||||
./src/endpoints_handlers/IExecutor.h
|
./src/endpoints_handlers/IExecutor.h
|
||||||
@@ -54,6 +55,8 @@ add_executable(App ./src/main.cpp
|
|||||||
src/log/Log.h
|
src/log/Log.h
|
||||||
src/log/Log.cpp
|
src/log/Log.cpp
|
||||||
tests/fixtures/AuthFixture.h
|
tests/fixtures/AuthFixture.h
|
||||||
|
src/endpoints_handlers/UserGetMedicationsExecutor.h
|
||||||
|
src/DAO/IMedicationsDAO.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(App PRIVATE Boost::boost
|
target_link_libraries(App PRIVATE Boost::boost
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
- Возможно, сделать тесты на CI/CD - приоритет - низкий
|
- Возможно, сделать тесты на CI/CD - приоритет - низкий
|
||||||
- ~~Заменить internal_server_error на bad_request и перепроверить коды ошибок~~
|
- ~~Заменить internal_server_error на bad_request и перепроверить коды ошибок~~
|
||||||
- ~~Создание и удаление вспомогательных классов должно быть вынесено в фикстуру~~
|
- ~~Создание и удаление вспомогательных классов должно быть вынесено в фикстуру~~
|
||||||
- К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов
|
- ~~К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов~~
|
||||||
|
|
||||||
# UseCase'ы приложения:
|
# UseCase'ы приложения:
|
||||||
|
|
||||||
@@ -321,13 +321,7 @@ null
|
|||||||
"treatment_name": "Bipolar I Scheme Urgent",
|
"treatment_name": "Bipolar I Scheme Urgent",
|
||||||
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
||||||
"medications": [
|
"medications": [
|
||||||
{
|
"eda5a5f7-167a-44b9-900d-c5c6acfc249b"
|
||||||
"uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b",
|
|
||||||
"name": "Aminazin",
|
|
||||||
"dose": 100,
|
|
||||||
"unit": "mg",
|
|
||||||
"is_urgent": true
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -414,13 +408,7 @@ null
|
|||||||
"treatment_name": "Bipolar I Scheme Urgent",
|
"treatment_name": "Bipolar I Scheme Urgent",
|
||||||
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
||||||
"medications": [
|
"medications": [
|
||||||
{
|
"eda5a5f7-167a-44b9-900d-c5c6acfc249b"
|
||||||
"uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b",
|
|
||||||
"name": "Aminazin",
|
|
||||||
"dose": 100,
|
|
||||||
"unit": "mg",
|
|
||||||
"is_urgent": true
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -504,20 +492,8 @@ null
|
|||||||
"treatment_name": "Bipolar I Scheme Urgent",
|
"treatment_name": "Bipolar I Scheme Urgent",
|
||||||
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
||||||
"medications": [
|
"medications": [
|
||||||
{
|
"eca5a5f7-167a-44b9-900d-c5c6acfc249b",
|
||||||
"uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b",
|
"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
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -531,27 +507,14 @@ null
|
|||||||
"treatment_name": "Bipolar I Scheme Urgent",
|
"treatment_name": "Bipolar I Scheme Urgent",
|
||||||
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
|
||||||
"medications": [
|
"medications": [
|
||||||
{
|
"eca5a5f7-167a-44b9-900d-c5c6acfc249b",
|
||||||
"uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b",
|
"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
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
##### Errors
|
##### Errors
|
||||||
* `400 BAD_REQUEST` — сервер не смог десереализовать JSON
|
* `400 BAD_REQUEST` — сервер не смог десереализовать JSON
|
||||||
* `400 BAD_REQUEST` — Обязательные поля заполнены неправильно
|
* `400 BAD_REQUEST` — Обязательные поля заполнены неправильно
|
||||||
* `409 SCHEME_ALREADYEXISTS` - такая схема уже существует
|
|
||||||
### 10. Используемые сущности ДБ
|
### 10. Используемые сущности ДБ
|
||||||
* user_treatment_schemes(uuid, user_uuid, treatment_name, instructions)
|
* user_treatment_schemes(uuid, user_uuid, treatment_name, instructions)
|
||||||
* medications(uuid, name, dose, unit, is_urgent)
|
* medications(uuid, name, dose, unit, is_urgent)
|
||||||
|
|||||||
@@ -85,12 +85,13 @@ CREATE TABLE `up_and_down`.`diaries` (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE `up_and_down`.`medications` (
|
CREATE TABLE `up_and_down`.`medications` (
|
||||||
`uuid` CHAR(36) NOT NULL,
|
`uuid` CHAR(36) NOT NULL,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
`dose` int8 NOT NULL,
|
`dose` int8 NOT NULL,
|
||||||
`unit` CHAR(30),
|
`unit` CHAR(30),
|
||||||
`is_urgent` BOOL NOT NULL,
|
`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` (
|
CREATE TABLE `up_and_down`.`treatment_schemes` (
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../entities/medication.h"
|
||||||
|
|
||||||
|
namespace uad
|
||||||
|
{
|
||||||
|
class IMedicationsDAO
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual std::vector<medication> GetAll() = 0;
|
||||||
|
|
||||||
|
virtual std::string Create(medication) = 0;
|
||||||
|
|
||||||
|
virtual ~IMedicationsDAO() = default;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "AuthRegistrationExecutor.h"
|
#include "AuthRegistrationExecutor.h"
|
||||||
#include "AuthLoginExecutor.h"
|
#include "AuthLoginExecutor.h"
|
||||||
#include "AuthLogoutExecutor.h"
|
#include "AuthLogoutExecutor.h"
|
||||||
|
#include "UserGetMedicationsExecutor.h"
|
||||||
#include "../DAO/IUserDAO.h"
|
#include "../DAO/IUserDAO.h"
|
||||||
#include "../DAO/IAuthDAO.h"
|
#include "../DAO/IAuthDAO.h"
|
||||||
#include "./../helpers/helpers.h"
|
#include "./../helpers/helpers.h"
|
||||||
@@ -24,6 +25,8 @@ class RootExecutor
|
|||||||
Body, Allocator, boost::beast::http::string_body>;
|
Body, Allocator, boost::beast::http::string_body>;
|
||||||
using RouteAuthLogoutExecutor = AuthLogoutExecutor<
|
using RouteAuthLogoutExecutor = AuthLogoutExecutor<
|
||||||
Body, Allocator, boost::beast::http::string_body>;
|
Body, Allocator, boost::beast::http::string_body>;
|
||||||
|
using RouteUserGetMedicationsExecutor = UserGetMedicationsExecutor<
|
||||||
|
Body, Allocator, boost::beast::http::string_body>;
|
||||||
using IRouteController = IController<Body, Allocator, boost::beast::http::string_body>;
|
using IRouteController = IController<Body, Allocator, boost::beast::http::string_body>;
|
||||||
using RouteController = Controller<Body, Allocator, boost::beast::http::string_body>;
|
using RouteController = Controller<Body, Allocator, boost::beast::http::string_body>;
|
||||||
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
|
using RoutesPathes = std::unordered_map<std::string, std::unique_ptr<IRouteController>>;
|
||||||
@@ -46,26 +49,41 @@ public:
|
|||||||
session_(session), user_dao_(user_dao), auth_dao_(auth_dao)
|
session_(session), user_dao_(user_dao), auth_dao_(auth_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{
|
||||||
{boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(
|
{
|
||||||
session_,
|
boost::beast::http::verb::post, std::make_shared<RouteAuthRegistrationExecutor>(
|
||||||
user_dao_
|
session_,
|
||||||
)}
|
user_dao_
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
routes_pathes_["/api/v1/Auth/Login"] = std::make_unique<RouteController>(
|
routes_pathes_["/api/v1/Auth/Login"] = std::make_unique<RouteController>(
|
||||||
typename RouteController::HTTPMethodsToExecutors{
|
typename RouteController::HTTPMethodsToExecutors{
|
||||||
{boost::beast::http::verb::post,
|
{
|
||||||
std::make_shared<RouteAuthLoginExecutor>(session_, user_dao_, auth_dao_)}
|
boost::beast::http::verb::post,
|
||||||
}
|
std::make_shared<RouteAuthLoginExecutor>(session_, user_dao_, auth_dao_)
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
routes_pathes_["/api/v1/Auth/Logout"] = std::make_unique<RouteController>(
|
routes_pathes_["/api/v1/Auth/Logout"] = std::make_unique<RouteController>(
|
||||||
typename RouteController::HTTPMethodsToExecutors{
|
typename RouteController::HTTPMethodsToExecutors{
|
||||||
{boost::beast::http::verb::post,
|
{
|
||||||
std::make_shared<RouteAuthLogoutExecutor>(session_, auth_dao_)}
|
boost::beast::http::verb::post,
|
||||||
}
|
std::make_shared<RouteAuthLogoutExecutor>(session_, auth_dao_)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
routes_pathes_["api/v1/User/Medications"] = std::make_unique<RouteController>(
|
||||||
|
typename RouteController::HTTPMethodsToExecutors{
|
||||||
|
{
|
||||||
|
boost::beast::http::verb::get,
|
||||||
|
std::make_shared<RouteUserGetMedicationsExecutor>()
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +91,7 @@ public:
|
|||||||
boost::beast::string_view doc_root,
|
boost::beast::string_view doc_root,
|
||||||
Request&& req,
|
Request&& req,
|
||||||
Send&& send
|
Send&& send
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const std::string& route = req.target();
|
const std::string& route = req.target();
|
||||||
const bool is_match_route = routes_pathes_.count(route);
|
const bool is_match_route = routes_pathes_.count(route);
|
||||||
@@ -163,7 +181,7 @@ private:
|
|||||||
StringResponse SendBadRequest(
|
StringResponse SendBadRequest(
|
||||||
Request&& req,
|
Request&& req,
|
||||||
boost::beast::string_view why
|
boost::beast::string_view why
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
StringResponse res{
|
StringResponse res{
|
||||||
boost::beast::http::status::bad_request, req.version()
|
boost::beast::http::status::bad_request, req.version()
|
||||||
@@ -179,7 +197,7 @@ private:
|
|||||||
StringResponse SendNotFound(
|
StringResponse SendNotFound(
|
||||||
Request&& req,
|
Request&& req,
|
||||||
boost::beast::string_view target
|
boost::beast::string_view target
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
StringResponse res{
|
StringResponse res{
|
||||||
boost::beast::http::status::not_found, req.version()
|
boost::beast::http::status::not_found, req.version()
|
||||||
@@ -195,7 +213,7 @@ private:
|
|||||||
StringResponse SendServerError(
|
StringResponse SendServerError(
|
||||||
Request&& req,
|
Request&& req,
|
||||||
boost::beast::string_view what
|
boost::beast::string_view what
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
StringResponse res{
|
StringResponse res{
|
||||||
boost::beast::http::status::internal_server_error, req.version()
|
boost::beast::http::status::internal_server_error, req.version()
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
#include <boost/json.hpp>
|
||||||
|
#include <mysqlx/xdevapi.h>
|
||||||
|
|
||||||
|
#include "IExecutor.h"
|
||||||
|
#include "../DAO/IUserDAO.h"
|
||||||
|
#include "../exceptions/session_exception.h"
|
||||||
|
|
||||||
|
namespace uad
|
||||||
|
{
|
||||||
|
template <class Body, class Allocator, class ResponseType>
|
||||||
|
class UserGetMedicationsExecutor : public IExecutor<Body, Allocator, ResponseType>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UserGetMedicationsExecutor() = default;
|
||||||
|
|
||||||
|
boost::beast::http::response<ResponseType> operator ()(
|
||||||
|
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||||
|
) override
|
||||||
|
{
|
||||||
|
using namespace boost;
|
||||||
|
using namespace boost::json;
|
||||||
|
using namespace boost::beast;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
|
||||||
|
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../helpers/helpers.h"
|
||||||
|
|
||||||
|
namespace uad
|
||||||
|
{
|
||||||
|
struct medication
|
||||||
|
{
|
||||||
|
std::string uuid;
|
||||||
|
std::string login;
|
||||||
|
std::string hashed_password;
|
||||||
|
};
|
||||||
|
}
|
||||||
+1
-3
@@ -50,8 +50,6 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
InitLogs();
|
InitLogs();
|
||||||
|
|
||||||
// Добавление общих атрибутов (включая время)
|
|
||||||
|
|
||||||
uad::SetMySqlSession(new mysqlx::Session(mysql_credentials));
|
uad::SetMySqlSession(new mysqlx::Session(mysql_credentials));
|
||||||
|
|
||||||
net::io_context ioc{threads};
|
net::io_context ioc{threads};
|
||||||
@@ -61,7 +59,7 @@ int main(int argc, char* argv[])
|
|||||||
net::signal_set signals(ioc, SIGINT, SIGTERM);
|
net::signal_set signals(ioc, SIGINT, SIGTERM);
|
||||||
signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); });
|
signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); });
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "Приложение запущено2";
|
BOOST_LOG_TRIVIAL(info) << "Приложение запущено";
|
||||||
|
|
||||||
std::vector<std::thread> v;
|
std::vector<std::thread> v;
|
||||||
v.reserve(threads - 1);
|
v.reserve(threads - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user