/** * OpenAPI Petstore * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 * * * NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT. * https://openapi-generator.tech * Do not edit the class manually. */ #include #include #include #include #include "StoreApi.h" namespace org { namespace openapitools { namespace server { namespace api { using namespace org::openapitools::server::model; StoreApi::StoreApi() { std::shared_ptr spStoreApiStoreOrderOrderIdResource = std::make_shared(); this->publish(spStoreApiStoreOrderOrderIdResource); std::shared_ptr spStoreApiStoreInventoryResource = std::make_shared(); this->publish(spStoreApiStoreInventoryResource); std::shared_ptr spStoreApiStoreOrderResource = std::make_shared(); this->publish(spStoreApiStoreOrderResource); } StoreApi::~StoreApi() {} void StoreApi::startService(int const& port) { std::shared_ptr settings = std::make_shared(); settings->set_port(port); settings->set_root("/v2"); this->start(settings); } void StoreApi::stopService() { this->stop(); } StoreApiStoreOrderOrderIdResource::StoreApiStoreOrderOrderIdResource() { this->set_path("/store/order/{orderId: .*}/"); this->set_method_handler("DELETE", std::bind(&StoreApiStoreOrderOrderIdResource::DELETE_method_handler, this, std::placeholders::_1)); this->set_method_handler("GET", std::bind(&StoreApiStoreOrderOrderIdResource::GET_method_handler, this, std::placeholders::_1)); } StoreApiStoreOrderOrderIdResource::~StoreApiStoreOrderOrderIdResource() { } void StoreApiStoreOrderOrderIdResource::DELETE_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Getting the path params const std::string orderId = request->get_path_parameter("orderId", ""); // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 400) { session->close(400, "Invalid ID supplied", { {"Connection", "close"} }); return; } if (status_code == 404) { session->close(404, "Order not found", { {"Connection", "close"} }); return; } } void StoreApiStoreOrderOrderIdResource::GET_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Getting the path params const int64_t orderId = request->get_path_parameter("orderId", 0L); // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 200) { std::shared_ptr response = NULL; session->close(200, "successful operation", { {"Connection", "close"} }); return; } if (status_code == 400) { session->close(400, "Invalid ID supplied", { {"Connection", "close"} }); return; } if (status_code == 404) { session->close(404, "Order not found", { {"Connection", "close"} }); return; } } StoreApiStoreInventoryResource::StoreApiStoreInventoryResource() { this->set_path("/store/inventory/"); this->set_method_handler("GET", std::bind(&StoreApiStoreInventoryResource::GET_method_handler, this, std::placeholders::_1)); } StoreApiStoreInventoryResource::~StoreApiStoreInventoryResource() { } void StoreApiStoreInventoryResource::GET_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 200) { session->close(200, "successful operation", { {"Connection", "close"} }); return; } } StoreApiStoreOrderResource::StoreApiStoreOrderResource() { this->set_path("/store/order/"); this->set_method_handler("POST", std::bind(&StoreApiStoreOrderResource::POST_method_handler, this, std::placeholders::_1)); } StoreApiStoreOrderResource::~StoreApiStoreOrderResource() { } void StoreApiStoreOrderResource::POST_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Body params are present, therefore we have to fetch them int content_length = request->get_header("Content-Length", 0); session->fetch(content_length, [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) { const auto request = session->get_request(); std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); /** * Get body params or form params here from the requestBody string */ // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 200) { session->close(200, "successful operation", { {"Connection", "close"} }); return; } if (status_code == 400) { session->close(400, "Invalid Order", { {"Connection", "close"} }); return; } }); } } } } }