IndividualApplicationDataSubscriptionDocumentApi.cpp 4.98 KB
Newer Older
yangjian's avatar
yangjian committed
1
/**
yangjian's avatar
yangjian committed
2 3 4 5 6 7 8 9 10 11 12
 * Nudr_DataRepository API OpenAPI file
 * Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB,
 * ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
 *
 * The version of the OpenAPI document: 2.1.2
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator
 * (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
 * the class manually.
 */
yangjian's avatar
yangjian committed
13 14 15 16 17 18 19 20 21 22 23 24

#include "IndividualApplicationDataSubscriptionDocumentApi.h"
#include "Helpers.h"

namespace org {
namespace openapitools {
namespace server {
namespace api {

using namespace org::openapitools::server::helpers;
using namespace org::openapitools::server::model;

yangjian's avatar
yangjian committed
25 26 27 28
IndividualApplicationDataSubscriptionDocumentApi::
    IndividualApplicationDataSubscriptionDocumentApi(
        std::shared_ptr<Pistache::Rest::Router> rtr) {
  router = rtr;
yangjian's avatar
yangjian committed
29 30
}

yangjian's avatar
yangjian committed
31
void IndividualApplicationDataSubscriptionDocumentApi::init() { setupRoutes(); }
yangjian's avatar
yangjian committed
32 33

void IndividualApplicationDataSubscriptionDocumentApi::setupRoutes() {
yangjian's avatar
yangjian committed
34
  using namespace Pistache::Rest;
yangjian's avatar
yangjian committed
35

yangjian's avatar
yangjian committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  Routes::Delete(
      *router, base + "/application-data/subs-to-notify/:subsId",
      Routes::bind(&IndividualApplicationDataSubscriptionDocumentApi::
                       delete_individual_application_data_subscription_handler,
                   this));
  Routes::Get(
      *router, base + "/application-data/subs-to-notify/:subsId",
      Routes::bind(&IndividualApplicationDataSubscriptionDocumentApi::
                       read_individual_application_data_subscription_handler,
                   this));
  Routes::Put(
      *router, base + "/application-data/subs-to-notify/:subsId",
      Routes::bind(&IndividualApplicationDataSubscriptionDocumentApi::
                       replace_individual_application_data_subscription_handler,
                   this));
yangjian's avatar
yangjian committed
51

yangjian's avatar
yangjian committed
52 53 54 55 56
  // Default handler, called when a route is not found
  router->addCustomHandler(Routes::bind(
      &IndividualApplicationDataSubscriptionDocumentApi::
          individual_application_data_subscription_document_api_default_handler,
      this));
yangjian's avatar
yangjian committed
57 58
}

yangjian's avatar
yangjian committed
59 60 61 62 63 64
void IndividualApplicationDataSubscriptionDocumentApi::
    delete_individual_application_data_subscription_handler(
        const Pistache::Rest::Request &request,
        Pistache::Http::ResponseWriter response) {
  // Getting the path params
  auto subsId = request.param(":subsId").as<std::string>();
yangjian's avatar
yangjian committed
65

yangjian's avatar
yangjian committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79
  try {
    this->delete_individual_application_data_subscription(subsId, response);
  } catch (nlohmann::detail::exception &e) {
    // send a 400 error
    response.send(Pistache::Http::Code::Bad_Request, e.what());
    return;
  } catch (Pistache::Http::HttpError &e) {
    response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
    return;
  } catch (std::exception &e) {
    // send a 500 error
    response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
    return;
  }
yangjian's avatar
yangjian committed
80
}
yangjian's avatar
yangjian committed
81 82 83 84 85 86
void IndividualApplicationDataSubscriptionDocumentApi::
    read_individual_application_data_subscription_handler(
        const Pistache::Rest::Request &request,
        Pistache::Http::ResponseWriter response) {
  // Getting the path params
  auto subsId = request.param(":subsId").as<std::string>();
yangjian's avatar
yangjian committed
87

yangjian's avatar
yangjian committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
  try {
    this->read_individual_application_data_subscription(subsId, response);
  } catch (nlohmann::detail::exception &e) {
    // send a 400 error
    response.send(Pistache::Http::Code::Bad_Request, e.what());
    return;
  } catch (Pistache::Http::HttpError &e) {
    response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
    return;
  } catch (std::exception &e) {
    // send a 500 error
    response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
    return;
  }
yangjian's avatar
yangjian committed
102
}
yangjian's avatar
yangjian committed
103 104 105 106 107 108
void IndividualApplicationDataSubscriptionDocumentApi::
    replace_individual_application_data_subscription_handler(
        const Pistache::Rest::Request &request,
        Pistache::Http::ResponseWriter response) {
  // Getting the path params
  auto subsId = request.param(":subsId").as<std::string>();
yangjian's avatar
yangjian committed
109

yangjian's avatar
yangjian committed
110
  // Getting the body param
yangjian's avatar
yangjian committed
111

yangjian's avatar
yangjian committed
112
  ApplicationDataSubs applicationDataSubs;
yangjian's avatar
yangjian committed
113

yangjian's avatar
yangjian committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  try {
    nlohmann::json::parse(request.body()).get_to(applicationDataSubs);
    this->replace_individual_application_data_subscription(
        subsId, applicationDataSubs, response);
  } catch (nlohmann::detail::exception &e) {
    // send a 400 error
    response.send(Pistache::Http::Code::Bad_Request, e.what());
    return;
  } catch (Pistache::Http::HttpError &e) {
    response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
    return;
  } catch (std::exception &e) {
    // send a 500 error
    response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
    return;
  }
yangjian's avatar
yangjian committed
130
}
yangjian's avatar
yangjian committed
131 132 133 134 135 136 137

void IndividualApplicationDataSubscriptionDocumentApi::
    individual_application_data_subscription_document_api_default_handler(
        const Pistache::Rest::Request &,
        Pistache::Http::ResponseWriter response) {
  response.send(Pistache::Http::Code::Not_Found,
                "The requested method does not exist");
yangjian's avatar
yangjian committed
138 139
}

yangjian's avatar
yangjian committed
140 141 142 143
} // namespace api
} // namespace server
} // namespace openapitools
} // namespace org