generated from Sithas/conan_template
111 lines
2.6 KiB
C++
111 lines
2.6 KiB
C++
#include "MySQLDiariesDAO.h"
|
||
|
||
namespace uad
|
||
{
|
||
MySqlDiariesDAO::MySqlDiariesDAO(mysqlx::Session& session) : session_(session)
|
||
{
|
||
}
|
||
|
||
std::vector<diary_dto> MySqlDiariesDAO::GetDiariesByUserUUID(const std::string& user_uuid)
|
||
{
|
||
static const std::string query = R"(
|
||
SELECT
|
||
d.uuid,
|
||
UNIX_TIMESTAMP(d.time) * 1000,
|
||
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.diaries d
|
||
WHERE d.user_uuid = ?
|
||
ORDER BY d.time;
|
||
)";
|
||
|
||
mysqlx::SqlResult result = session_
|
||
.sql(query)
|
||
.bind(user_uuid)
|
||
.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].get<std::string>();
|
||
|
||
dto.user_treatment_scheme_uuid = row[10].get<std::string>();
|
||
|
||
diaries.push_back(std::move(dto));
|
||
}
|
||
|
||
return diaries;
|
||
}
|
||
|
||
void MySqlDiariesDAO::СreateDiary(const std::string& user_uuid, const diary_dto& dto) const
|
||
{
|
||
auto stmt = session_.sql(R"(
|
||
INSERT INTO `up_and_down`.`diaries` (
|
||
uuid,
|
||
user_uuid,
|
||
time,
|
||
mania_level,
|
||
depression_level,
|
||
mood_level,
|
||
activity_level,
|
||
appetite_level,
|
||
dream_level,
|
||
anxiety_level,
|
||
comment,
|
||
user_treatment_schemes_uuid
|
||
) VALUES (
|
||
?,
|
||
?,
|
||
FROM_UNIXTIME(? / 1000),
|
||
?,
|
||
?,
|
||
?,
|
||
?,
|
||
?,
|
||
?,
|
||
?,
|
||
?,
|
||
?
|
||
)
|
||
)");
|
||
|
||
stmt.bind(
|
||
dto.uuid,
|
||
user_uuid,
|
||
dto.time_ms,
|
||
dto.mania_level,
|
||
dto.depression_level,
|
||
dto.mood_level,
|
||
dto.activity_level,
|
||
dto.appetite_level,
|
||
dto.dream_level,
|
||
dto.anxiety_level,
|
||
dto.comment,
|
||
dto.user_treatment_scheme_uuid
|
||
);
|
||
|
||
stmt.execute();
|
||
}
|
||
}
|