From f06d22febfbe52c8b1b2dded9aafdac6d357fa74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Wed, 7 Jan 2026 10:48:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D1=80=D1=83=D1=87=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20GetAllMedications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/endpoints_handlers/RootExecutor.h | 2 +- .../UserGetMedicationsExecutor.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/endpoints_handlers/RootExecutor.h b/src/endpoints_handlers/RootExecutor.h index 3d0e2fb..0555657 100644 --- a/src/endpoints_handlers/RootExecutor.h +++ b/src/endpoints_handlers/RootExecutor.h @@ -80,7 +80,7 @@ public: } ); - routes_pathes_["api/v1/User/Medications"] = std::make_unique( + routes_pathes_["/api/v1/User/Medications"] = std::make_unique( typename RouteController::HTTPMethodsToExecutors{ { boost::beast::http::verb::get, diff --git a/src/endpoints_handlers/UserGetMedicationsExecutor.h b/src/endpoints_handlers/UserGetMedicationsExecutor.h index 90c3398..4c8288a 100644 --- a/src/endpoints_handlers/UserGetMedicationsExecutor.h +++ b/src/endpoints_handlers/UserGetMedicationsExecutor.h @@ -36,6 +36,23 @@ public: using namespace boost::json; using namespace boost::beast; using namespace std::string_literals; + using namespace std::string_view_literals; + + constexpr std::string_view auth_prefix = "Bearer "sv; + + BOOST_LOG_TRIVIAL(info) << "GET /api/v1/User/Medications - Request"; + + if (req[http::field::authorization].begin() == req[http::field::authorization].end()) + { + BOOST_LOG_TRIVIAL(info) << "GET /api/v1/User/Medications - Response 401: Unauthorized"; + throw session_exception(http::status::unauthorized, "Unauthorized"); + } + + const std::string auth_string = {*req[http::field::authorization].begin()}; + + const std::string auth_token = {auth_string.begin() + auth_prefix.size(), auth_string.end()}; + + if (auth_dao_->HasAuthorized(auth_token)) {} http::response res{http::status::ok, req.version()};