2 Commits

7 changed files with 151 additions and 1 deletions
+4
View File
@@ -64,6 +64,10 @@ add_executable(App ./src/main.cpp
src/DAO/MySQLUserTreatmentSchemesDAO.cpp src/DAO/MySQLUserTreatmentSchemesDAO.cpp
src/DAO/MySQLUserTreatmentSchemesDAO.h src/DAO/MySQLUserTreatmentSchemesDAO.h
src/endpoints_handlers/GetUserTreatmentSchemeExecutor.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 target_link_libraries(App PRIVATE Boost::boost
+3 -1
View File
@@ -24,6 +24,8 @@
- ~~Заменить internal_server_error на bad_request и перепроверить коды ошибок~~ - ~~Заменить internal_server_error на bad_request и перепроверить коды ошибок~~
- ~~Создание и удаление вспомогательных классов должно быть вынесено в фикстуру~~ - ~~Создание и удаление вспомогательных классов должно быть вынесено в фикстуру~~
- ~~К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов~~ - ~~К следующему занятию сделать ручку из кейса 3 + восстановить фикстуры из тестов~~
- Попробовать nodiscard к executoru
- Найти слабые места в C++ -- std::forward, universal reference
# UseCase'ы приложения: # UseCase'ы приложения:
@@ -193,7 +195,7 @@ null
"dream_level": 6, "dream_level": 6,
"anxiety_level": 7, "anxiety_level": 7,
"comment": "Накрыл психоз. Выпил одну таблетку аминазина" "comment": "Накрыл психоз. Выпил одну таблетку аминазина"
"treatment_scheme_uuid": bf6d1555-39e9-4d73-8928-4763627f4dd5 "user_treatment_scheme_uuid": bf6d1555-39e9-4d73-8928-4763627f4dd5
} }
] ]
} }
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <vector>
#include <string>
#include "./../dtos/diary_dto.h"
namespace uad
{
class IDiariesDAO
{
public:
virtual std::vector<diary_dto> GetDiariesByLogin(const std::string& login) = 0;
virtual ~IDiariesDAO() = default;
};
}
+64
View File
@@ -0,0 +1,64 @@
#include "MySQLDiariesDAO.h"
namespace uad
{
MySqlDiariesDAO::MySqlDiariesDAO(mysqlx::Session& session) : session_(session)
{
}
std::vector<diary_dto> 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<diary_dto> diaries;
diaries.reserve(result.count());
for (const mysqlx::Row& row : result)
{
diary_dto dto;
dto.uuid = row[0].get<std::string>();
dto.time_ms = row[1].get<std::int64_t>();
dto.mania_level = row[2].get<int>();
dto.depression_level = row[3].get<int>();
dto.mood_level = row[4].get<int>();
dto.activity_level = row[5].get<int>();
dto.appetite_level = row[6].get<int>();
dto.dream_level = row[7].get<int>();
dto.anxiety_level = row[8].get<int>();
dto.comment =
row[9].isNull() ? "" : row[9].get<std::string>();
dto.user_treatment_scheme_uuid =
row[10].isNull() ? "" : row[10].get<std::string>();
diaries.push_back(std::move(dto));
}
return diaries;
}
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include <vector>
#include <string>
#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<diary_dto> GetDiariesByLogin(const std::string& login) override;
};
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include <string>
#include <cstdint>
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;
};
}
+21
View File
@@ -13,4 +13,25 @@ public:
) = 0; ) = 0;
virtual ~IExecutor() = default; virtual ~IExecutor() = default;
}; };
// class IAuthorizable : public IExecutor
// {
// IExecutor& next_executor_;
// public:
// IAuthorizable(IExecutor& next_executor): next_executor_(next_executor)
// {
//
// }
//
// boost::beast::http::response<ResponseType> operator ()(
// boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
// ) override
// {
// // Логика проверки авторизации
// // передать управление следующему executorу - возврат req
// // посмотреть chain of responsibility, composite
// // выбрасывать исключение здесь
// return next_executor_(req);
// }
// };
} }