generated from Sithas/conan_template
Post Diary
This commit is contained in:
+2
-1
@@ -13,7 +13,7 @@ set(Boost_USE_MULTITHREADED ON)
|
|||||||
set(Boost_INCLUDE_DIR ${BOOST_ROOT})
|
set(Boost_INCLUDE_DIR ${BOOST_ROOT})
|
||||||
set(Boost_LIBRARY_DIR "${BOOST_ROOT}/stage/lib")
|
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)
|
if (Boost_FOUND)
|
||||||
include_directories(${Boost_INCLUDE_DIR})
|
include_directories(${Boost_INCLUDE_DIR})
|
||||||
endif ()
|
endif ()
|
||||||
@@ -77,6 +77,7 @@ target_link_libraries(App PRIVATE Boost::boost
|
|||||||
Boost::log
|
Boost::log
|
||||||
Boost::system
|
Boost::system
|
||||||
Boost::filesystem
|
Boost::filesystem
|
||||||
|
Boost::url
|
||||||
Threads::Threads
|
Threads::Threads
|
||||||
mysql::concpp)
|
mysql::concpp)
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/url.hpp>
|
||||||
#include <mysqlx/xdevapi.h>
|
#include <mysqlx/xdevapi.h>
|
||||||
#include <mysqlx/common/api.h>
|
#include <mysqlx/common/api.h>
|
||||||
|
|
||||||
@@ -157,6 +160,8 @@ public:
|
|||||||
Send&& send
|
Send&& send
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
namespace urls = boost::urls;
|
||||||
|
|
||||||
const std::string& route = req.target();
|
const std::string& route = req.target();
|
||||||
const bool is_match_route = routes_pathes_.count(route);
|
const bool is_match_route = routes_pathes_.count(route);
|
||||||
|
|
||||||
@@ -178,21 +183,25 @@ public:
|
|||||||
}
|
}
|
||||||
catch (const session_exception& e)
|
catch (const session_exception& e)
|
||||||
{
|
{
|
||||||
boost::beast::http::response<ResponseType> res{e.code, req.version()};
|
return send(SendSessionExceptionError(std::move(req), e));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 &&
|
if (req.method() != boost::beast::http::verb::get &&
|
||||||
req.method() != boost::beast::http::verb::head)
|
req.method() != boost::beast::http::verb::head)
|
||||||
return send(SendBadRequest(std::move(req), "Unknown boost::beast::HTTP-method"));
|
return send(SendBadRequest(std::move(req), "Unknown boost::beast::HTTP-method"));
|
||||||
@@ -289,5 +298,20 @@ private:
|
|||||||
res.prepare_payload();
|
res.prepare_payload();
|
||||||
return res;
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user