generated from Sithas/conan_template
База для ручки GetUserDiariesExecutor.h
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ public:
|
|||||||
|
|
||||||
virtual bool HasAuthorized(const std::string& auth_token) = 0;
|
virtual bool HasAuthorized(const std::string& auth_token) = 0;
|
||||||
|
|
||||||
virtual std::string_view GetLogin(const std::string& auth_token) = 0;
|
virtual std::string_view GetUUID(const std::string& auth_token) = 0;
|
||||||
|
|
||||||
virtual bool Logout(const std::string& user_token) = 0;
|
virtual bool Logout(const std::string& user_token) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace uad
|
|||||||
class IDiariesDAO
|
class IDiariesDAO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual std::vector<diary_dto> GetDiariesByLogin(const std::string& login) = 0;
|
virtual std::vector<diary_dto> GetDiariesByUserUUID(const std::string& login) = 0;
|
||||||
|
|
||||||
virtual ~IDiariesDAO() = default;
|
virtual ~IDiariesDAO() = default;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ bool MemoryAuthDAO::HasAuthorized(const std::string& auth_token)
|
|||||||
return auth_tokens_to_users_uuids_.count(auth_token) > 0;
|
return auth_tokens_to_users_uuids_.count(auth_token) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view MemoryAuthDAO::GetLogin(const std::string& auth_token)
|
std::string_view MemoryAuthDAO::GetUUID(const std::string& auth_token)
|
||||||
{
|
{
|
||||||
return auth_tokens_to_users_uuids_.at(auth_token);
|
return auth_tokens_to_users_uuids_.at(auth_token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
bool HasAuthorized(const std::string& auth_token) override;
|
bool HasAuthorized(const std::string& auth_token) override;
|
||||||
|
|
||||||
std::string_view GetLogin(const std::string& auth_token) override;
|
std::string_view GetUUID(const std::string& auth_token) override;
|
||||||
|
|
||||||
bool Logout(const std::string& auth_token) override;
|
bool Logout(const std::string& auth_token) override;
|
||||||
};
|
};
|
||||||
|
|||||||
+17
-19
@@ -6,31 +6,29 @@ MySqlDiariesDAO::MySqlDiariesDAO(mysqlx::Session& session) : session_(session)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<diary_dto> MySqlDiariesDAO::GetDiariesByLogin(const std::string& login)
|
std::vector<diary_dto> MySqlDiariesDAO::GetDiariesByUserUUID(const std::string& user_uuid)
|
||||||
{
|
{
|
||||||
static const std::string query = R"(
|
static const std::string query = R"(
|
||||||
SELECT
|
SELECT
|
||||||
d.uuid,
|
d.uuid,
|
||||||
UNIX_TIMESTAMP(d.time) * 1000 AS time_ms,
|
UNIX_TIMESTAMP(d.time) * 1000,
|
||||||
d.mania_level,
|
d.mania_level,
|
||||||
d.depression_level,
|
d.depression_level,
|
||||||
d.mood_level,
|
d.mood_level,
|
||||||
d.activity_level,
|
d.activity_level,
|
||||||
d.appetite_level,
|
d.appetite_level,
|
||||||
d.dream_level,
|
d.dream_level,
|
||||||
d.anxiety_level,
|
d.anxiety_level,
|
||||||
d.comment,
|
d.comment,
|
||||||
d.user_treatment_schemes_uuid
|
d.user_treatment_schemes_uuid
|
||||||
FROM up_and_down.users u
|
FROM up_and_down.diaries d
|
||||||
JOIN up_and_down.diaries d
|
WHERE d.user_uuid = ?
|
||||||
ON d.user_uuid = u.uuid
|
ORDER BY d.time;
|
||||||
WHERE u.login = ?
|
|
||||||
ORDER BY d.time ASC
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
mysqlx::SqlResult result = session_
|
mysqlx::SqlResult result = session_
|
||||||
.sql(query)
|
.sql(query)
|
||||||
.bind(login)
|
.bind(user_uuid)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
std::vector<diary_dto> diaries;
|
std::vector<diary_dto> diaries;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class MySqlDiariesDAO final : public IDiariesDAO
|
|||||||
public:
|
public:
|
||||||
explicit MySqlDiariesDAO(mysqlx::Session& session);
|
explicit MySqlDiariesDAO(mysqlx::Session& session);
|
||||||
|
|
||||||
std::vector<diary_dto> GetDiariesByLogin(const std::string& login) override;
|
std::vector<diary_dto> GetDiariesByUserUUID(const std::string& user_uuid) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -63,12 +63,61 @@ public:
|
|||||||
throw session_exception(http::status::unauthorized, "Unauthorized");
|
throw session_exception(http::status::unauthorized, "Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view user_login_ref = auth_dao_->GetLogin(auth_token);
|
std::string_view user_login_ref = auth_dao_->GetUUID(auth_token);
|
||||||
const std::string user_login{user_login_ref.begin(), user_login_ref.end()};
|
const std::string user_uuid{user_login_ref.begin(), user_login_ref.end()};
|
||||||
|
|
||||||
|
std::vector<diary_dto> diaries = diaries_dao_->GetDiariesByUserUUID(user_uuid);
|
||||||
|
|
||||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||||
|
value response_body;
|
||||||
|
|
||||||
|
response_body.emplace_object();
|
||||||
|
response_body.as_object().emplace("diaries", toJSONArray(diaries));
|
||||||
|
|
||||||
|
res.body() = serialize(response_body);
|
||||||
|
res.set(http::field::content_type, "application/json");
|
||||||
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::json::object ToJSON(const diary_dto& diary)
|
||||||
|
{
|
||||||
|
boost::json::object diary_json;
|
||||||
|
|
||||||
|
diary_json["uuid"] = diary.uuid;
|
||||||
|
diary_json["time"] = diary.time_ms;
|
||||||
|
diary_json["mania_level"] = diary.mania_level;
|
||||||
|
diary_json["depression_level"] = diary.depression_level;
|
||||||
|
diary_json["mood_level"] = diary.mood_level;
|
||||||
|
diary_json["activity_level"] = diary.activity_level;
|
||||||
|
diary_json["appetite_level"] = diary.appetite_level;
|
||||||
|
diary_json["dream_level"] = diary.dream_level;
|
||||||
|
diary_json["anxiety_level"] = diary.anxiety_level;
|
||||||
|
diary_json["comment"] = diary.comment;
|
||||||
|
diary_json["user_treatment_scheme_uuid"] =
|
||||||
|
diary.user_treatment_scheme_uuid;
|
||||||
|
|
||||||
|
return diary_json;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::json::array toJSONArray(const std::vector<diary_dto>& schemes)
|
||||||
|
{
|
||||||
|
using namespace boost;
|
||||||
|
using namespace boost::json;
|
||||||
|
using namespace boost::beast;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
|
json::array arr;
|
||||||
|
|
||||||
|
for (const auto& m : schemes)
|
||||||
|
{
|
||||||
|
arr.emplace_back(ToJSON(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(arr);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
throw session_exception(http::status::unauthorized, "Unauthorized");
|
throw session_exception(http::status::unauthorized, "Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view user_login_ref = auth_dao_->GetLogin(auth_token);
|
std::string_view user_login_ref = auth_dao_->GetUUID(auth_token);
|
||||||
const std::string user_uuid{user_login_ref.begin(), user_login_ref.end()};
|
const std::string user_uuid{user_login_ref.begin(), user_login_ref.end()};
|
||||||
|
|
||||||
static const std::string query = R"(
|
static const std::string query = R"(
|
||||||
|
|||||||
Reference in New Issue
Block a user