2017-06-02 08:40:07 +02:00
/**
2018-05-08 10:44:51 +02:00
* 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.
2017-06-02 08:40:07 +02:00
*
2019-05-30 16:45:28 +02:00
* The version of the OpenAPI document: 1.0.0
2018-05-08 10:44:51 +02:00
*
2017-06-02 08:40:07 +02:00
*
2021-10-13 07:57:40 +02:00
* NOTE: This class is auto generated by OpenAPI-Generator unset.
2018-05-08 10:44:51 +02:00
* https://openapi-generator.tech
2017-06-02 08:40:07 +02:00
* Do not edit the class manually.
*/
# include <corvusoft/restbed/byte.hpp>
# include <corvusoft/restbed/string.hpp>
# include <corvusoft/restbed/settings.hpp>
# include <corvusoft/restbed/request.hpp>
2021-10-13 07:57:40 +02:00
# include <corvusoft/restbed/uri.hpp>
# include <boost/property_tree/ptree.hpp>
# include <boost/property_tree/json_parser.hpp>
# include <boost/lexical_cast.hpp>
# include <boost/algorithm/string.hpp>
2017-06-02 08:40:07 +02:00
# include "StoreApi.h"
2018-05-08 22:10:40 +08:00
namespace org {
namespace openapitools {
2017-06-02 08:40:07 +02:00
namespace server {
namespace api {
2018-05-08 22:10:40 +08:00
using namespace org : : openapitools : : server : : model ;
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
StoreApiException : : StoreApiException ( int status_code , std : : string what )
: m_status ( status_code ) ,
m_what ( what )
{
}
int StoreApiException : : getStatus ( ) const
{
return m_status ;
}
const char * StoreApiException : : what ( ) const noexcept
{
return m_what . c_str ( ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
template < class MODEL_T >
std : : shared_ptr < MODEL_T > extractJsonModelBodyParam ( const std : : string & bodyContent )
{
std : : stringstream sstream ( bodyContent ) ;
boost : : property_tree : : ptree pt ;
boost : : property_tree : : json_parser : : read_json ( sstream , pt ) ;
2020-10-27 08:35:10 +01:00
2021-10-13 07:57:40 +02:00
auto model = std : : make_shared < MODEL_T > ( pt ) ;
return model ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
template < class MODEL_T >
std : : vector < std : : shared_ptr < MODEL_T > > extractJsonArrayBodyParam ( const std : : string & bodyContent )
{
std : : stringstream sstream ( bodyContent ) ;
boost : : property_tree : : ptree pt ;
boost : : property_tree : : json_parser : : read_json ( sstream , pt ) ;
auto arrayRet = std : : vector < std : : shared_ptr < MODEL_T > > ( ) ;
for ( const auto & child : pt ) {
arrayRet . emplace_back ( std : : make_shared < MODEL_T > ( child . second ) ) ;
}
return arrayRet ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
template < class KEY_T , class VAL_T >
std : : string convertMapResponse ( const std : : map < KEY_T , VAL_T > & map )
2017-06-02 08:40:07 +02:00
{
2021-10-13 07:57:40 +02:00
boost : : property_tree : : ptree pt ;
for ( const auto & kv : map ) {
pt . push_back ( boost : : property_tree : : ptree : : value_type (
boost : : lexical_cast < std : : string > ( kv . first ) ,
boost : : property_tree : : ptree (
boost : : lexical_cast < std : : string > ( kv . second ) ) ) ) ;
}
std : : stringstream sstream ;
write_json ( sstream , pt ) ;
std : : string result = sstream . str ( ) ;
return result ;
}
StoreApiStoreOrderOrderIdResource : : StoreApiStoreOrderOrderIdResource ( const std : : string & context /* = "/v2" */ )
{
this - > set_path ( context + " /store/order/{orderId: .*}/ " ) ;
2017-06-02 08:40:07 +02:00
this - > set_method_handler ( " DELETE " ,
2021-10-13 07:57:40 +02:00
std : : bind ( & StoreApiStoreOrderOrderIdResource : : handler_DELETE_internal , this ,
2017-06-02 08:40:07 +02:00
std : : placeholders : : _1 ) ) ;
this - > set_method_handler ( " GET " ,
2021-10-13 07:57:40 +02:00
std : : bind ( & StoreApiStoreOrderOrderIdResource : : handler_GET_internal , this ,
2017-06-02 08:40:07 +02:00
std : : placeholders : : _1 ) ) ;
}
2017-07-10 18:37:08 +02:00
StoreApiStoreOrderOrderIdResource : : ~ StoreApiStoreOrderOrderIdResource ( )
2017-06-02 08:40:07 +02:00
{
}
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreOrderOrderIdResource : : handleStoreApiException ( const StoreApiException & e )
{
return std : : make_pair < int , std : : string > ( e . getStatus ( ) , e . what ( ) ) ;
2019-05-30 16:45:28 +02:00
}
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreOrderOrderIdResource : : handleStdException ( const std : : exception & e )
{
return std : : make_pair < int , std : : string > ( 500 , e . what ( ) ) ;
2019-05-30 16:45:28 +02:00
}
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreOrderOrderIdResource : : handleUnspecifiedException ( )
{
return std : : make_pair < int , std : : string > ( 500 , " Unknown exception occurred " ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
void StoreApiStoreOrderOrderIdResource : : setResponseHeader ( const std : : shared_ptr < restbed : : Session > & session , const std : : string & header )
{
session - > set_header ( header , " " ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
void StoreApiStoreOrderOrderIdResource : : returnResponse ( const std : : shared_ptr < restbed : : Session > & session , const int status , const std : : string & result , const std : : string & contentType )
{
session - > close ( status , result , { { " Connection " , " close " } , { " Content-Type " , contentType } } ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
void StoreApiStoreOrderOrderIdResource : : defaultSessionClose ( const std : : shared_ptr < restbed : : Session > & session , const int status , const std : : string & result )
{
session - > close ( status , result , { { " Connection " , " close " } } ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
void StoreApiStoreOrderOrderIdResource : : handler_DELETE_internal ( const std : : shared_ptr < restbed : : Session > session )
{
const auto request = session - > get_request ( ) ;
// Getting the path params
const std : : string orderId = getPathParam_orderId ( request ) ;
int status_code = 500 ;
std : : string result = " " ;
try {
status_code =
handler_DELETE ( orderId ) ;
}
catch ( const StoreApiException & e ) {
std : : tie ( status_code , result ) = handleStoreApiException ( e ) ;
}
catch ( const std : : exception & e ) {
std : : tie ( status_code , result ) = handleStdException ( e ) ;
}
catch ( . . . ) {
std : : tie ( status_code , result ) = handleUnspecifiedException ( ) ;
}
if ( status_code = = 400 ) {
const constexpr auto contentType = " text/plain " ;
returnResponse ( session , 400 , result . empty ( ) ? " Invalid ID supplied " : result , contentType ) ;
return ;
}
if ( status_code = = 404 ) {
const constexpr auto contentType = " text/plain " ;
returnResponse ( session , 404 , result . empty ( ) ? " Order not found " : result , contentType ) ;
return ;
}
defaultSessionClose ( session , status_code , result ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
// x-extension
void StoreApiStoreOrderOrderIdResource : : handler_GET_internal ( const std : : shared_ptr < restbed : : Session > session ) {
const auto request = session - > get_request ( ) ;
// Getting the path params
const int64_t orderId = getPathParam_orderId_x_extension ( request ) ;
int status_code = 500 ;
std : : shared_ptr < Order > resultObject = std : : make_shared < Order > ( ) ;
std : : string result = " " ;
try {
std : : tie ( status_code , resultObject ) =
handler_GET ( orderId ) ;
}
catch ( const StoreApiException & e ) {
std : : tie ( status_code , result ) = handleStoreApiException ( e ) ;
}
catch ( const std : : exception & e ) {
std : : tie ( status_code , result ) = handleStdException ( e ) ;
}
catch ( . . . ) {
std : : tie ( status_code , result ) = handleUnspecifiedException ( ) ;
}
if ( status_code = = 200 ) {
result = resultObject - > toJsonString ( ) ;
const constexpr auto contentType = " application/json " ;
returnResponse ( session , 200 , result . empty ( ) ? " successful operation " : result , contentType ) ;
return ;
}
if ( status_code = = 400 ) {
const constexpr auto contentType = " text/plain " ;
returnResponse ( session , 400 , result . empty ( ) ? " Invalid ID supplied " : result , contentType ) ;
return ;
}
if ( status_code = = 404 ) {
const constexpr auto contentType = " text/plain " ;
returnResponse ( session , 404 , result . empty ( ) ? " Order not found " : result , contentType ) ;
return ;
}
defaultSessionClose ( session , status_code , result ) ;
}
2018-10-07 19:54:06 +02:00
2021-10-13 07:57:40 +02:00
int StoreApiStoreOrderOrderIdResource : : handler_DELETE (
std : : string const & orderId )
{
throw StoreApiException ( 501 , " Not implemented " ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : shared_ptr < Order > > StoreApiStoreOrderOrderIdResource : : handler_GET (
int64_t const & orderId )
{
throw StoreApiException ( 501 , " Not implemented " ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
std : : string StoreApiStoreOrderOrderIdResource : : extractBodyContent ( const std : : shared_ptr < restbed : : Session > & session ) {
const auto request = session - > get_request ( ) ;
int content_length = request - > get_header ( " Content-Length " , 0 ) ;
std : : string bodyContent ;
session - > fetch ( content_length ,
[ & bodyContent ] ( const std : : shared_ptr < restbed : : Session > session ,
const restbed : : Bytes & body ) {
bodyContent = restbed : : String : : format (
" %.*s \n " , ( int ) body . size ( ) , body . data ( ) ) ;
} ) ;
return bodyContent ;
}
StoreApiStoreInventoryResource : : StoreApiStoreInventoryResource ( const std : : string & context /* = "/v2" */ )
{
this - > set_path ( context + " /store/inventory/ " ) ;
this - > set_method_handler ( " GET " ,
std : : bind ( & StoreApiStoreInventoryResource : : handler_GET_internal , this ,
std : : placeholders : : _1 ) ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
StoreApiStoreInventoryResource : : ~ StoreApiStoreInventoryResource ( )
{
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreInventoryResource : : handleStoreApiException ( const StoreApiException & e )
{
return std : : make_pair < int , std : : string > ( e . getStatus ( ) , e . what ( ) ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreInventoryResource : : handleStdException ( const std : : exception & e )
{
return std : : make_pair < int , std : : string > ( 500 , e . what ( ) ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreInventoryResource : : handleUnspecifiedException ( )
{
return std : : make_pair < int , std : : string > ( 500 , " Unknown exception occurred " ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
void StoreApiStoreInventoryResource : : setResponseHeader ( const std : : shared_ptr < restbed : : Session > & session , const std : : string & header )
2017-06-02 08:40:07 +02:00
{
2021-10-13 07:57:40 +02:00
session - > set_header ( header , " " ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
void StoreApiStoreInventoryResource : : returnResponse ( const std : : shared_ptr < restbed : : Session > & session , const int status , const std : : string & result , const std : : string & contentType )
2017-06-02 08:40:07 +02:00
{
2021-10-13 07:57:40 +02:00
session - > close ( status , result , { { " Connection " , " close " } , { " Content-Type " , contentType } } ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
void StoreApiStoreInventoryResource : : defaultSessionClose ( const std : : shared_ptr < restbed : : Session > & session , const int status , const std : : string & result )
{
session - > close ( status , result , { { " Connection " , " close " } } ) ;
2019-05-30 16:45:28 +02:00
}
2021-10-13 07:57:40 +02:00
void StoreApiStoreInventoryResource : : handler_GET_internal ( const std : : shared_ptr < restbed : : Session > session )
{
const auto request = session - > get_request ( ) ;
2019-05-30 16:45:28 +02:00
2017-06-02 08:40:07 +02:00
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
int status_code = 500 ;
std : : map < std : : string , int32_t > resultObject = std : : map < std : : string , int32_t > ( ) ;
std : : string result = " " ;
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
try {
std : : tie ( status_code , resultObject ) =
handler_GET ( ) ;
}
catch ( const StoreApiException & e ) {
std : : tie ( status_code , result ) = handleStoreApiException ( e ) ;
}
catch ( const std : : exception & e ) {
std : : tie ( status_code , result ) = handleStdException ( e ) ;
}
catch ( . . . ) {
std : : tie ( status_code , result ) = handleUnspecifiedException ( ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
if ( status_code = = 200 ) {
2022-08-27 12:10:28 +02:00
result = resultObject - > toJsonString ( ) ;
2021-10-13 07:57:40 +02:00
result = convertMapResponse ( resultObject ) ;
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
const constexpr auto contentType = " application/json " ;
returnResponse ( session , 200 , result . empty ( ) ? " successful operation " : result , contentType ) ;
return ;
}
defaultSessionClose ( session , status_code , result ) ;
}
2019-05-30 16:45:28 +02:00
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : map < std : : string , int32_t > > StoreApiStoreInventoryResource : : handler_GET (
)
{
throw StoreApiException ( 501 , " Not implemented " ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
std : : string StoreApiStoreInventoryResource : : extractBodyContent ( const std : : shared_ptr < restbed : : Session > & session ) {
const auto request = session - > get_request ( ) ;
int content_length = request - > get_header ( " Content-Length " , 0 ) ;
std : : string bodyContent ;
session - > fetch ( content_length ,
[ & bodyContent ] ( const std : : shared_ptr < restbed : : Session > session ,
const restbed : : Bytes & body ) {
bodyContent = restbed : : String : : format (
" %.*s \n " , ( int ) body . size ( ) , body . data ( ) ) ;
} ) ;
return bodyContent ;
}
StoreApiStoreOrderResource : : StoreApiStoreOrderResource ( const std : : string & context /* = "/v2" */ )
2017-06-02 08:40:07 +02:00
{
2021-10-13 07:57:40 +02:00
this - > set_path ( context + " /store/order/ " ) ;
2017-06-02 08:40:07 +02:00
this - > set_method_handler ( " POST " ,
2021-10-13 07:57:40 +02:00
std : : bind ( & StoreApiStoreOrderResource : : handler_POST_internal , this ,
2017-06-02 08:40:07 +02:00
std : : placeholders : : _1 ) ) ;
}
2017-07-10 18:37:08 +02:00
StoreApiStoreOrderResource : : ~ StoreApiStoreOrderResource ( )
2017-06-02 08:40:07 +02:00
{
}
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreOrderResource : : handleStoreApiException ( const StoreApiException & e )
{
return std : : make_pair < int , std : : string > ( e . getStatus ( ) , e . what ( ) ) ;
2019-05-30 16:45:28 +02:00
}
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreOrderResource : : handleStdException ( const std : : exception & e )
{
return std : : make_pair < int , std : : string > ( 500 , e . what ( ) ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : string > StoreApiStoreOrderResource : : handleUnspecifiedException ( )
{
return std : : make_pair < int , std : : string > ( 500 , " Unknown exception occurred " ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
void StoreApiStoreOrderResource : : setResponseHeader ( const std : : shared_ptr < restbed : : Session > & session , const std : : string & header )
{
session - > set_header ( header , " " ) ;
}
void StoreApiStoreOrderResource : : returnResponse ( const std : : shared_ptr < restbed : : Session > & session , const int status , const std : : string & result , const std : : string & contentType )
{
session - > close ( status , result , { { " Connection " , " close " } , { " Content-Type " , contentType } } ) ;
}
void StoreApiStoreOrderResource : : defaultSessionClose ( const std : : shared_ptr < restbed : : Session > & session , const int status , const std : : string & result )
{
session - > close ( status , result , { { " Connection " , " close " } } ) ;
}
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
void StoreApiStoreOrderResource : : handler_POST_internal ( const std : : shared_ptr < restbed : : Session > session )
{
const auto request = session - > get_request ( ) ;
std : : string bodyContent = extractBodyContent ( session ) ;
// Get body params or form params here from the body content string
2022-08-27 12:10:28 +02:00
auto order = extractJsonModelBodyParam < Order > ( bodyContent ) ;
2021-10-13 07:57:40 +02:00
int status_code = 500 ;
std : : shared_ptr < Order > resultObject = std : : make_shared < Order > ( ) ;
std : : string result = " " ;
try {
std : : tie ( status_code , resultObject ) =
2022-08-27 12:10:28 +02:00
handler_POST ( order ) ;
2021-10-13 07:57:40 +02:00
}
catch ( const StoreApiException & e ) {
std : : tie ( status_code , result ) = handleStoreApiException ( e ) ;
}
catch ( const std : : exception & e ) {
std : : tie ( status_code , result ) = handleStdException ( e ) ;
}
catch ( . . . ) {
std : : tie ( status_code , result ) = handleUnspecifiedException ( ) ;
}
if ( status_code = = 200 ) {
result = resultObject - > toJsonString ( ) ;
const constexpr auto contentType = " application/json " ;
returnResponse ( session , 200 , result . empty ( ) ? " successful operation " : result , contentType ) ;
return ;
}
if ( status_code = = 400 ) {
const constexpr auto contentType = " text/plain " ;
returnResponse ( session , 400 , result . empty ( ) ? " Invalid Order " : result , contentType ) ;
return ;
}
defaultSessionClose ( session , status_code , result ) ;
}
2017-06-02 08:40:07 +02:00
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
std : : pair < int , std : : shared_ptr < Order > > StoreApiStoreOrderResource : : handler_POST (
2022-08-27 12:10:28 +02:00
std : : shared_ptr < Order > const & order )
2021-10-13 07:57:40 +02:00
{
throw StoreApiException ( 501 , " Not implemented " ) ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
std : : string StoreApiStoreOrderResource : : extractBodyContent ( const std : : shared_ptr < restbed : : Session > & session ) {
const auto request = session - > get_request ( ) ;
int content_length = request - > get_header ( " Content-Length " , 0 ) ;
std : : string bodyContent ;
session - > fetch ( content_length ,
[ & bodyContent ] ( const std : : shared_ptr < restbed : : Session > session ,
const restbed : : Bytes & body ) {
bodyContent = restbed : : String : : format (
" %.*s \n " , ( int ) body . size ( ) , body . data ( ) ) ;
} ) ;
return bodyContent ;
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
StoreApi : : StoreApi ( std : : shared_ptr < restbed : : Service > const & restbedService )
: m_service ( restbedService )
{
}
2019-05-30 16:45:28 +02:00
2021-10-13 07:57:40 +02:00
StoreApi : : ~ StoreApi ( ) { }
2017-06-02 08:40:07 +02:00
2021-10-13 07:57:40 +02:00
void StoreApi : : setStoreApiStoreOrderOrderIdResource ( std : : shared_ptr < StoreApiStoreOrderOrderIdResource > spStoreApiStoreOrderOrderIdResource ) {
m_spStoreApiStoreOrderOrderIdResource = spStoreApiStoreOrderOrderIdResource ;
m_service - > publish ( m_spStoreApiStoreOrderOrderIdResource ) ;
}
void StoreApi : : setStoreApiStoreInventoryResource ( std : : shared_ptr < StoreApiStoreInventoryResource > spStoreApiStoreInventoryResource ) {
m_spStoreApiStoreInventoryResource = spStoreApiStoreInventoryResource ;
m_service - > publish ( m_spStoreApiStoreInventoryResource ) ;
}
void StoreApi : : setStoreApiStoreOrderResource ( std : : shared_ptr < StoreApiStoreOrderResource > spStoreApiStoreOrderResource ) {
m_spStoreApiStoreOrderResource = spStoreApiStoreOrderResource ;
m_service - > publish ( m_spStoreApiStoreOrderResource ) ;
2017-06-02 08:40:07 +02:00
}
2021-10-13 07:57:40 +02:00
void StoreApi : : publishDefaultResources ( ) {
if ( ! m_spStoreApiStoreOrderOrderIdResource ) {
setStoreApiStoreOrderOrderIdResource ( std : : make_shared < StoreApiStoreOrderOrderIdResource > ( ) ) ;
}
if ( ! m_spStoreApiStoreInventoryResource ) {
setStoreApiStoreInventoryResource ( std : : make_shared < StoreApiStoreInventoryResource > ( ) ) ;
}
if ( ! m_spStoreApiStoreOrderResource ) {
setStoreApiStoreOrderResource ( std : : make_shared < StoreApiStoreOrderResource > ( ) ) ;
}
}
std : : shared_ptr < restbed : : Service > StoreApi : : service ( ) {
return m_service ;
}
2017-06-02 08:40:07 +02:00
}
}
}
}