Skip to content
Snippets Groups Projects
Commit a4359844 authored by Stefan Spettel's avatar Stefan Spettel
Browse files

refact(pcf): Move route constants into api_defs.h

parent 8551d378
No related branches found
No related tags found
1 merge request!29Add HTTP/2 support
......@@ -35,6 +35,7 @@ include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config)
file(GLOB PCF_API_SERVER_src_files
${PCF_API_SERVER_DIR}/pcf-api-server.cpp
${PCF_API_SERVER_DIR}/pcf-http2-server.cpp
${PCF_API_SERVER_DIR}/api_defs.cpp
${PCF_API_SERVER_DIR}/model/*.cpp
${PCF_API_SERVER_DIR}/api/*.cpp
${PCF_API_SERVER_DIR}/impl/*.cpp
......
......@@ -13,17 +13,14 @@
#include "IndividualSMPolicyDocumentApi.h"
#include "Helpers.h"
#include "api_defs.h"
#include "pcf_config.hpp"
namespace oai {
namespace pcf {
namespace api {
namespace oai::pcf::api {
using namespace oai::model::common::helpers;
using namespace oai::pcf::model;
const std::string IndividualSMPolicyDocumentApi::base =
"/npcf-smpolicycontrol/v1";
IndividualSMPolicyDocumentApi::IndividualSMPolicyDocumentApi(
const std::shared_ptr<Pistache::Rest::Router>& rtr)
: router(rtr) {}
......@@ -34,17 +31,16 @@ void IndividualSMPolicyDocumentApi::init() {
void IndividualSMPolicyDocumentApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(
*router, base + "/sm-policies/:smPolicyId/delete",
*router, sm_policies::get_route() + "/:smPolicyId/delete",
Routes::bind(
&IndividualSMPolicyDocumentApi::delete_sm_policy_handler, this));
Routes::Get(
*router, base + "/sm-policies/:smPolicyId",
*router, sm_policies::get_route() + "/:smPolicyId",
Routes::bind(
&IndividualSMPolicyDocumentApi::get_sm_policy_handler, this));
Routes::Post(
*router, base + "/sm-policies/:smPolicyId/update",
*router, sm_policies::get_route() + "/:smPolicyId/update",
Routes::bind(
&IndividualSMPolicyDocumentApi::update_sm_policy_handler, this));
......@@ -183,6 +179,4 @@ void IndividualSMPolicyDocumentApi::
Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace api
} // namespace pcf
} // namespace oai
} // namespace oai::pcf::api
......@@ -33,9 +33,7 @@
#include "SmPolicyUpdateContextData.h"
#include <string>
namespace oai {
namespace pcf {
namespace api {
namespace oai::pcf::api {
using namespace oai::pcf::model;
......@@ -46,8 +44,6 @@ class IndividualSMPolicyDocumentApi {
virtual ~IndividualSMPolicyDocumentApi() = default;
void init();
static const std::string base;
private:
void setupRoutes();
......@@ -121,8 +117,6 @@ class IndividualSMPolicyDocumentApi {
Pistache::Http::ResponseWriter& response) = 0;
};
} // namespace api
} // namespace pcf
} // namespace oai
#endif /* IndividualSMPolicyDocumentApi_H_ */
......@@ -12,6 +12,8 @@
*/
#include "SMPoliciesCollectionApi.h"
#include "api_defs.h"
#include "pcf_config.hpp"
namespace oai {
namespace pcf {
......@@ -32,7 +34,7 @@ void SMPoliciesCollectionApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(
*router, SM_POLICIES_API_BASE + "/sm-policies",
*router, sm_policies::get_route(),
Routes::bind(&SMPoliciesCollectionApi::create_sm_policy_handler, this));
// Default handler, called when a route is not found
......
......@@ -39,8 +39,6 @@ namespace api {
using namespace oai::model::common::helpers;
using namespace oai::pcf::model;
static const std::string SM_POLICIES_API_BASE = "/npcf-smpolicycontrol/v1"; ;
class SMPoliciesCollectionApi {
public:
explicit SMPoliciesCollectionApi(
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file api_defs.h
\brief
\author Stefan Spettel
\company phine.tech
\date 2023
\email: stefan.spettel@phine.tech
*/
#include "api_defs.h"
#include "pcf_config.hpp"
extern std::unique_ptr<oai::pcf::config::pcf_config> pcf_cfg;
namespace oai::pcf::api {
std::string sm_policies::get_route() {
return API_BASE + pcf_cfg->sbi.get_api_version() + sm_policies::CREATE_ROUTE;
}
} // namespace oai::pcf::api
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file api_defs.h
\brief
\author Stefan Spettel
\company phine.tech
\date 2023
\email: stefan.spettel@phine.tech
*/
#pragma once
#include <string>
namespace oai::pcf::api {
class sm_policies {
public:
static inline const std::string API_BASE = "/npcf-smpolicycontrol/";
static inline const std::string CREATE_ROUTE = "/sm-policies";
static std::string get_route();
};
} // namespace oai::pcf::api
\ No newline at end of file
......@@ -34,6 +34,8 @@
#include "SmPolicyDecision.h"
#include "SMPoliciesCollectionApi.h"
#include "logger.hpp"
#include "api_defs.h"
#include "pcf_config.hpp"
namespace oai::pcf::api {
......@@ -59,9 +61,8 @@ api_response sm_policies_collection_api_handler::create_sm_policy(
switch (res) {
case status_code::CREATED:
http_code = http_status_code_e::HTTP_STATUS_CODE_201_CREATED;
location =
m_address + SM_POLICIES_API_BASE + "/sm-policies/" + association_id;
http_code = http_status_code_e::HTTP_STATUS_CODE_201_CREATED;
location = m_address + sm_policies::get_route() + association_id;
content_type = "application/json";
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment