From 199659266f39ba831e62d45aa6246296f896ba75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Sun, 25 Jan 2026 10:02:15 +0300 Subject: [PATCH] Post Diary --- CMakeLists.txt | 3 +- src/endpoints_handlers/RootExecutor.h | 46 ++++++++++++++++++++------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43b4b0a..8deff64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index 3327fb8..e460fb7 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -1,3 +1,6 @@ +#pragma once + +#include #include #include @@ -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 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 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 SendSessionExceptionError(Request&& req, const session_exception& e) + { + boost::beast::http::response 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; + } }; }