generated from Sithas/conan_template
База для ручки GetUserDiariesExecutor.h
This commit is contained in:
@@ -63,12 +63,61 @@ public:
|
||||
throw session_exception(http::status::unauthorized, "Unauthorized");
|
||||
}
|
||||
|
||||
std::string_view user_login_ref = auth_dao_->GetLogin(auth_token);
|
||||
const std::string user_login{user_login_ref.begin(), user_login_ref.end()};
|
||||
std::string_view user_login_ref = auth_dao_->GetUUID(auth_token);
|
||||
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()};
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user