Post Diary

This commit is contained in:
2026-01-25 10:02:15 +03:00
parent 7ff1bf10f8
commit 199659266f
2 changed files with 37 additions and 12 deletions
+2 -1
View File
@@ -13,7 +13,7 @@ set(Boost_USE_MULTITHREADED ON)
set(Boost_INCLUDE_DIR ${BOOST_ROOT})
set(Boost_LIBRARY_DIR "${BOOST_ROOT}/stage/lib")
find_package(Boost 1.88.0 REQUIRED COMPONENTS filesystem json log system filesystem)
find_package(Boost 1.88.0 REQUIRED COMPONENTS filesystem json log system filesystem url)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif ()
@@ -77,6 +77,7 @@ target_link_libraries(App PRIVATE Boost::boost
Boost::log
Boost::system
Boost::filesystem
Boost::url
Threads::Threads
mysql::concpp)
+35 -11
View File
@@ -1,3 +1,6 @@
#pragma once
#include <boost/url.hpp>
#include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h>
@@ -157,6 +160,8 @@ public:
Send&& send
)
{
namespace urls = boost::urls;
const std::string& route = req.target();
const bool is_match_route = routes_pathes_.count(route);
@@ -178,21 +183,25 @@ public:
}
catch (const session_exception& e)
{
boost::beast::http::response<ResponseType> res{e.code, req.version()};
boost::json::value response_body;
response_body.emplace_object();
response_body.as_object().emplace("Result", e.what());
res.body() = serialize(response_body);
res.set(boost::beast::http::field::content_type, "application/json");
res.content_length(res.body().size());
return send(std::move(res));
return send(SendSessionExceptionError(std::move(req), e));
}
}
}
// urls::url_view parsed_view = urls::parse_uri_reference("/api/v1/Diaries/123").value();
// auto segs = parsed_view.segments();
// std::vector<std::string_view> parts;
//
// for (auto s : segs)
// parts.push_back(s);
//
// if (parts.size() == 4 &&
// parts[0] == "api" &&
// parts[2] == "Diaries")
// {
// std::string uuid = std::string(parts[3]);
// }
if (req.method() != boost::beast::http::verb::get &&
req.method() != boost::beast::http::verb::head)
return send(SendBadRequest(std::move(req), "Unknown boost::beast::HTTP-method"));
@@ -289,5 +298,20 @@ private:
res.prepare_payload();
return res;
}
boost::beast::http::response<ResponseType> SendSessionExceptionError(Request&& req, const session_exception& e)
{
boost::beast::http::response<ResponseType> res{e.code, req.version()};
boost::json::value response_body;
response_body.emplace_object();
response_body.as_object().emplace("Result", e.what());
res.body() = serialize(response_body);
res.set(boost::beast::http::field::content_type, "application/json");
res.content_length(res.body().size());
return res;
}
};
}