@@ -37,7 +37,7 @@ Service::Service(const std::string &name, const std::string &description,
3737 false ),
3838 Body::Service (name, description, cli_example, version, nullptr ),
3939 body_rest_endpoint_ (base_address + name + ' /' ),
40- path_param_ {} {
40+ cube_names_ {} {
4141 using Pistache::Rest::Routes::bind;
4242 auto router = core_->get_rest_server ()->get_router ();
4343
@@ -62,21 +62,11 @@ const std::string Service::Cube(const Pistache::Rest::Request &request) {
6262
6363void Service::ClearCubes () {
6464 auto k = ListKeyValues{};
65- for (const auto &cube_name : path_param_ .Values ()) {
65+ for (const auto &cube_name : cube_names_ .Values ()) {
6666 DeleteValue (cube_name, k);
6767 }
6868}
6969
70- std::vector<Response> Service::RequestValidate (
71- const Request &request,
72- [[maybe_unused]] const std::string &caller_name) const {
73- std::vector<Response> errors;
74- if (!path_param_.Validate (request.param (" :name" ).as <std::string>())) {
75- errors.push_back ({ErrorTag::kBadElement , ::strdup (" :name" )});
76- }
77- return errors;
78- }
79-
8070void Service::CreateReplaceUpdate (const std::string &name, nlohmann::json &body,
8171 ResponseWriter response, bool update,
8272 bool initialization) {
@@ -99,7 +89,7 @@ void Service::CreateReplaceUpdate(const std::string &name, nlohmann::json &body,
9989 if (!update && (resp.error_tag == ErrorTag::kOk ||
10090 resp.error_tag == ErrorTag::kCreated ||
10191 resp.error_tag == ErrorTag::kNoContent )) {
102- path_param_ .AddValue (name);
92+ cube_names_ .AddValue (name);
10393 }
10494 Server::ResponseGenerator::Generate (std::vector<Response>{resp},
10595 std::move (response));
@@ -136,6 +126,7 @@ void Service::post_body(const Request &request, ResponseWriter response) {
136126 std::move (response));
137127 return ;
138128 }
129+
139130 CreateReplaceUpdate (body[" name" ].get <std::string>(), body,
140131 std::move (response), false , true );
141132}
@@ -149,6 +140,15 @@ void Service::post(const Request &request, ResponseWriter response) {
149140 body = nlohmann::json::parse (request.body ());
150141 }
151142 body[" name" ] = name;
143+
144+ if (body.count (" service-name" )) {
145+ if (body[" service-name" ] != Name ()) {
146+ Server::ResponseGenerator::Generate ({{kInvalidValue , nullptr }},
147+ std::move (response));
148+ return ;
149+ }
150+ }
151+
152152 CreateReplaceUpdate (name, body, std::move (response), false , true );
153153}
154154
@@ -179,10 +179,13 @@ void Service::patch(const Request &request, ResponseWriter response) {
179179void Service::del (const Pistache::Rest::Request &request,
180180 Pistache::Http::ResponseWriter response) {
181181 auto name = request.param (" :name" ).as <std::string>();
182- if (ServiceController::exists_cube (name)) {
183- path_param_.RemoveValue (name);
182+ if (!ServiceController::exists_cube (name)) {
183+ Server::ResponseGenerator::Generate ({{kDataMissing , nullptr }},
184+ std::move (response));
185+ return ;
184186 }
185187
188+ cube_names_.RemoveValue (name);
186189 auto k = ListKeyValues{};
187190 auto res = DeleteValue (name, k);
188191 Server::ResponseGenerator::Generate (std::vector<Response>{res},
0 commit comments