@@ -67,9 +67,8 @@ void Service::ClearCubes() {
6767 }
6868}
6969
70- void Service::CreateReplaceUpdate (const std::string &name, nlohmann::json &body,
71- ResponseWriter response, bool update,
72- bool initialization) {
70+ std::vector<Response>
71+ Service::CreateReplaceUpdate (const std::string &name, nlohmann::json &body, bool update, bool initialization) {
7372 if (update || !ServiceController::exists_cube (name)) {
7473 auto op = OperationType (update, initialization);
7574 auto k = ListKeyValues{};
@@ -80,9 +79,7 @@ void Service::CreateReplaceUpdate(const std::string &name, nlohmann::json &body,
8079
8180 auto body_errors = BodyValidate (name, k, jbody, initialization);
8281 if (!body_errors.empty ()) {
83- Server::ResponseGenerator::Generate (std::move (body_errors),
84- std::move (response));
85- return ;
82+ return std::move (body_errors);
8683 }
8784
8885 auto resp = WriteValue (name, body, k, op);
@@ -91,12 +88,9 @@ void Service::CreateReplaceUpdate(const std::string &name, nlohmann::json &body,
9188 resp.error_tag == ErrorTag::kNoContent )) {
9289 cube_names_.AddValue (name);
9390 }
94- Server::ResponseGenerator::Generate (std::vector<Response>{resp},
95- std::move (response));
91+ return std::vector<Response>{resp};
9692 } else {
97- Server::ResponseGenerator::Generate (
98- std::vector<Response>{{ErrorTag::kDataExists , nullptr }},
99- std::move (response));
93+ return std::vector<Response>{{ErrorTag::kDataExists , nullptr }};
10094 }
10195}
10296
@@ -127,8 +121,8 @@ void Service::post_body(const Request &request, ResponseWriter response) {
127121 return ;
128122 }
129123
130- CreateReplaceUpdate (body[" name" ].get <std::string>(), body,
131- std::move (response ), false , true );
124+ auto resp = CreateReplaceUpdate (body[" name" ].get <std::string>(), body, false , true );
125+ Server:: ResponseGenerator::Generate ( std::move (resp ), std::move (response) );
132126}
133127
134128void Service::post (const Request &request, ResponseWriter response) {
@@ -149,7 +143,8 @@ void Service::post(const Request &request, ResponseWriter response) {
149143 }
150144 }
151145
152- CreateReplaceUpdate (name, body, std::move (response), false , true );
146+ auto resp = CreateReplaceUpdate (name, body, false , true );
147+ Server:: ResponseGenerator::Generate (std::move (resp), std::move (response));
153148}
154149
155150void Service::put (const Request &request, ResponseWriter response) {
@@ -161,7 +156,8 @@ void Service::put(const Request &request, ResponseWriter response) {
161156 body = nlohmann::json::parse (request.body ());
162157 }
163158 body[" name" ] = name;
164- CreateReplaceUpdate (name, body, std::move (response), false , true );
159+ auto resp = CreateReplaceUpdate (name, body, false , true );
160+ Server:: ResponseGenerator::Generate (std::move (resp), std::move (response));
165161}
166162
167163void Service::patch (const Request &request, ResponseWriter response) {
@@ -173,7 +169,8 @@ void Service::patch(const Request &request, ResponseWriter response) {
173169 body = nlohmann::json::parse (request.body ());
174170 }
175171 body[" name" ] = name;
176- CreateReplaceUpdate (name, body, std::move (response), true , false );
172+ auto resp = CreateReplaceUpdate (name, body, true , false );
173+ Server:: ResponseGenerator::Generate (std::move (resp), std::move (response));
177174}
178175
179176void Service::del (const Pistache::Rest::Request &request,
@@ -201,8 +198,8 @@ void Service::patch_body(const Request &request, ResponseWriter response) {
201198 std::move (response));
202199 return ;
203200 }
204- CreateReplaceUpdate (body[" name" ].get <std::string>(), body,
205- std::move (response ), true , false );
201+ auto resp = CreateReplaceUpdate (body[" name" ].get <std::string>(), body, true , false );
202+ Server:: ResponseGenerator::Generate ( std::move (resp ), std::move (response) );
206203}
207204
208205void Service::options_body (const Request &request, ResponseWriter response) {
0 commit comments