Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Npcf_SMPolicyControl API
* Session Management Policy Control Service © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.1.alpha-5
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "SMPoliciesCollectionApi.h"
namespace oai {
namespace pcf {
namespace api {
using namespace oai::pcf::helpers;
using namespace oai::pcf::model;
const std::string SMPoliciesCollectionApi::base = "/npcf-smpolicycontrol/v1";
SMPoliciesCollectionApi::SMPoliciesCollectionApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: router(rtr)
{
}
void SMPoliciesCollectionApi::init() {
setupRoutes();
}
void SMPoliciesCollectionApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(*router, base + "/sm-policies", Routes::bind(&SMPoliciesCollectionApi::create_sm_policy_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(&SMPoliciesCollectionApi::sm_policies_collection_api_default_handler, this));
}
std::pair<Pistache::Http::Code, std::string> SMPoliciesCollectionApi::handleParsingException(const std::exception& ex) const noexcept
{
try {
throw;
} catch (nlohmann::detail::exception &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
// } catch (org::openapitools::server::helpers::ValidationException &e) {
// return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (std::exception &e) {
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}
std::pair<Pistache::Http::Code, std::string> SMPoliciesCollectionApi::handleOperationException(const std::exception& ex) const noexcept
{
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what());
}
void SMPoliciesCollectionApi::create_sm_policy_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
// Getting the body param
SmPolicyContextData smPolicyContextData;
try {
nlohmann::json::parse(request.body()).get_to(smPolicyContextData);
smPolicyContextData.validate();
} catch (std::exception &e) {
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
response.send(errorInfo.first, errorInfo.second);
return;
}
try {
this->create_sm_policy(smPolicyContextData, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleOperationException(e);
response.send(errorInfo.first, errorInfo.second);
return;
}
} catch (std::exception &e) {
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}
void SMPoliciesCollectionApi::sm_policies_collection_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace api
} // namespace pcf
} // namespace oai