From 203ae876bb4ac7edb320ea64d2fd9ba441e0c671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Sat, 30 Aug 2025 08:04:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthRegistrationExecutor.h | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/endpoints_handlers/AuthRegistrationExecutor.h b/src/endpoints_handlers/AuthRegistrationExecutor.h index 2bc2636..fc65224 100644 --- a/src/endpoints_handlers/AuthRegistrationExecutor.h +++ b/src/endpoints_handlers/AuthRegistrationExecutor.h @@ -30,9 +30,13 @@ public: using namespace boost; using namespace boost::json; using namespace boost::beast; + using namespace std::string_literals; auto body = req.body(); value req_json; + value response_body; + + response_body.emplace_object(); try { @@ -41,8 +45,9 @@ public: catch (const system::system_error& err) { http::response res{http::status::bad_request, req.version()}; + response_body.as_object().emplace("Result", "cannot deserialize json"); - res.body() = "{ \"Result\": \"cannot deserialize json\"}"; + res.body() = serialize(response_body); res.set(http::field::content_type, "application/json"); res.content_length(res.body().size()); @@ -56,7 +61,12 @@ public: { http::response res{http::status::unprocessable_entity, req.version()}; - res.body() = "{ \"Result\": \"validations failed\"}"; + response_body.as_object().emplace( + "Result", + "Validations failed. Login should have length from 3 to 50. Password from 5 characters length." + ); + + res.body() = serialize(response_body); res.set(http::field::content_type, "application/json"); res.content_length(res.body().size()); @@ -67,7 +77,12 @@ public: { http::response res{http::status::conflict, req.version()}; - res.body() = "{ \"Result\": \"user with login " + login + " exists\" }"; + response_body.as_object().emplace( + "Result", + "user with login "s + login + " exists"s + ); + + res.body() = serialize(response_body); res.set(http::field::content_type, "application/json"); res.content_length(res.body().size()); @@ -83,7 +98,12 @@ public: http::status::created, req.version() }; - res.body() = "{ \"Result\": \"ok\"}"; + response_body.as_object().emplace( + "Result", + "OK.Created." + ); + + res.body() = serialize(response_body); res.set(http::field::content_type, "application/json"); res.content_length(res.body().size());