База для ручки PostUserMedicationsExecutor.h

This commit is contained in:
2026-01-08 12:05:50 +03:00
parent 1cb1a9d0eb
commit 8e1db614bf
@@ -40,9 +40,9 @@ public:
using namespace std::string_view_literals; using namespace std::string_view_literals;
constexpr std::string_view auth_prefix = "Bearer "sv; constexpr std::string_view auth_prefix = "Bearer "sv;
static const std::string invalid_token_message = "GET /api/v1/User/Medications - Response 401: Unauthorized"s; static const std::string invalid_token_message = "POST /api/v1/User/Medications - Response 401: Unauthorized"s;
BOOST_LOG_TRIVIAL(info) << "GET /api/v1/User/Medications - Request"; BOOST_LOG_TRIVIAL(info) << "POST /api/v1/User/Medications - Request";
if (req[http::field::authorization].size() <= auth_prefix.size()) if (req[http::field::authorization].size() <= auth_prefix.size())
{ {
@@ -59,15 +59,6 @@ public:
} }
http::response<ResponseType> res{http::status::ok, req.version()}; http::response<ResponseType> res{http::status::ok, req.version()};
const std::vector<medication> medications = medications_dao_->GetAll();
value response_body;
response_body.emplace_object();
response_body.as_object().emplace("medications", toJSONArray(medications));
res.body() = serialize(response_body);
res.set(http::field::content_type, "application/json");
res.content_length(res.body().size());
return res; return res;
} }
@@ -83,23 +74,5 @@ private:
{ "is_urgent", m.is_urgent } { "is_urgent", m.is_urgent }
}; };
} }
boost::json::array toJSONArray(const std::vector<medication>& medications)
{
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 : medications)
{
arr.emplace_back(ToJSON(m));
}
return arr;
}
}; };
} }