Commit a58a543b authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Add API for delete AuthenticationSubscription data

parent 4ad715ee
...@@ -64,6 +64,14 @@ void AuthenticationDataDocumentApi::setupRoutes() { ...@@ -64,6 +64,14 @@ void AuthenticationDataDocumentApi::setupRoutes() {
Routes::bind( Routes::bind(
&AuthenticationDataDocumentApi::create_auth_subs_data_handler, this)); &AuthenticationDataDocumentApi::create_auth_subs_data_handler, this));
Routes::Delete(
*router,
base + udr_cfg.nudr.api_version +
"/subscription-data/:ueId/authentication-data/"
"authentication-subscription",
Routes::bind(
&AuthenticationDataDocumentApi::delete_auth_subs_data_handler, this));
// Default handler, called when a route is not found // Default handler, called when a route is not found
router->addCustomHandler(Routes::bind( router->addCustomHandler(Routes::bind(
&AuthenticationDataDocumentApi:: &AuthenticationDataDocumentApi::
...@@ -128,6 +136,27 @@ void AuthenticationDataDocumentApi::create_auth_subs_data_handler( ...@@ -128,6 +136,27 @@ void AuthenticationDataDocumentApi::create_auth_subs_data_handler(
} }
} }
void AuthenticationDataDocumentApi::delete_auth_subs_data_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
try {
// Getting the path params
auto ueId = request.param(":ueId").as<std::string>();
try {
this->delete_auth_subs_data(ueId, response);
} 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 AuthenticationDataDocumentApi:: void AuthenticationDataDocumentApi::
authentication_data_document_api_default_handler( authentication_data_document_api_default_handler(
const Pistache::Rest::Request&, const Pistache::Rest::Request&,
......
...@@ -68,6 +68,9 @@ class AuthenticationDataDocumentApi { ...@@ -68,6 +68,9 @@ class AuthenticationDataDocumentApi {
void create_auth_subs_data_handler( void create_auth_subs_data_handler(
const Pistache::Rest::Request& request, const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response); Pistache::Http::ResponseWriter response);
void delete_auth_subs_data_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void authentication_data_document_api_default_handler( void authentication_data_document_api_default_handler(
const Pistache::Rest::Request& request, const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response); Pistache::Http::ResponseWriter response);
...@@ -105,6 +108,16 @@ class AuthenticationDataDocumentApi { ...@@ -105,6 +108,16 @@ class AuthenticationDataDocumentApi {
const oai::udr::model::AuthenticationSubscription& const oai::udr::model::AuthenticationSubscription&
authenticationSubscription, authenticationSubscription,
Pistache::Http::ResponseWriter& response) = 0; Pistache::Http::ResponseWriter& response) = 0;
/// <summary>
/// To remove the Authentication subscription data of a UE
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="ueId">UE id</param>
virtual void delete_auth_subs_data(
const std::string& ueId, Pistache::Http::ResponseWriter& response) = 0;
}; };
} // namespace oai::udr::api } // namespace oai::udr::api
......
...@@ -63,8 +63,19 @@ void AuthenticationDataDocumentApiImpl::create_auth_subs_data( ...@@ -63,8 +63,19 @@ void AuthenticationDataDocumentApiImpl::create_auth_subs_data(
code = static_cast<Pistache::Http::Code>(httpCode); code = static_cast<Pistache::Http::Code>(httpCode);
Logger::udr_server().debug("HTTP Response code %d.\n", code); Logger::udr_server().debug("HTTP Response code %d.\n", code);
response.send(code, responseData.dump().c_str()); response.send(code, responseData.dump().c_str());
}
void AuthenticationDataDocumentApiImpl::delete_auth_subs_data(
const std::string& ueId, Pistache::Http::ResponseWriter& response) {
nlohmann::json responseData = {};
Pistache::Http::Code code = {};
long httpCode = 0;
response.send(Pistache::Http::Code::Ok, "Do some magic\n"); m_udr_app->handle_delete_authentication_data(ueId, responseData, httpCode);
code = static_cast<Pistache::Http::Code>(httpCode);
Logger::udr_server().debug("HTTP Response code %d.\n", code);
response.send(code, responseData.dump().c_str());
} }
} // namespace api } // namespace api
......
...@@ -75,6 +75,8 @@ class AuthenticationDataDocumentApiImpl ...@@ -75,6 +75,8 @@ class AuthenticationDataDocumentApiImpl
const std::string& ueId, const std::string& ueId,
const AuthenticationSubscription& authenticationSubscription, const AuthenticationSubscription& authenticationSubscription,
Pistache::Http::ResponseWriter& response); Pistache::Http::ResponseWriter& response);
void delete_auth_subs_data(
const std::string& ueId, Pistache::Http::ResponseWriter& response);
}; };
} // namespace oai::udr::api } // namespace oai::udr::api
......
...@@ -57,6 +57,11 @@ bool cassandra_db::insert_authentication_subscription( ...@@ -57,6 +57,11 @@ bool cassandra_db::insert_authentication_subscription(
return true; return true;
} }
//------------------------------------------------------------------------------
bool cassandra_db::delete_authentication_subscription(const std::string& id) {
return true;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool cassandra_db::query_authentication_subscription( bool cassandra_db::query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) { const std::string& id, nlohmann::json& json_data) {
...@@ -70,11 +75,6 @@ bool cassandra_db::update_authentication_subscription( ...@@ -70,11 +75,6 @@ bool cassandra_db::update_authentication_subscription(
return true; return true;
} }
//------------------------------------------------------------------------------
bool cassandra_db::delete_authentication_subscription(const std::string& id) {
return true;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool cassandra_db::query_am_data( bool cassandra_db::query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id, const std::string& ue_id, const std::string& serving_plmn_id,
......
...@@ -41,14 +41,14 @@ class cassandra_db : public database_wrapper<cassandra_db> { ...@@ -41,14 +41,14 @@ class cassandra_db : public database_wrapper<cassandra_db> {
authentication_subscription, authentication_subscription,
nlohmann::json& json_data); nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_authentication_subscription( bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data); const std::string& id, nlohmann::json& json_data);
bool update_authentication_subscription( bool update_authentication_subscription(
const std::string& id, const nlohmann::json& json_data); const std::string& id, const nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_am_data( bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id, const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data); nlohmann::json& json_data);
......
...@@ -64,6 +64,10 @@ class database_wrapper : public database_wrapper_abstraction { ...@@ -64,6 +64,10 @@ class database_wrapper : public database_wrapper_abstraction {
return true; return true;
} }
bool delete_authentication_subscription(const std::string& id) override {
return true;
}
bool query_authentication_subscription( bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) override { const std::string& id, nlohmann::json& json_data) override {
return true; return true;
...@@ -76,10 +80,6 @@ class database_wrapper : public database_wrapper_abstraction { ...@@ -76,10 +80,6 @@ class database_wrapper : public database_wrapper_abstraction {
return true; return true;
} }
bool delete_authentication_subscription(const std::string& id) override {
return true;
}
bool query_am_data( bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id, const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) override { nlohmann::json& json_data) override {
......
...@@ -69,6 +69,14 @@ class database_wrapper_abstraction { ...@@ -69,6 +69,14 @@ class database_wrapper_abstraction {
const oai::udr::model::AuthenticationSubscription& const oai::udr::model::AuthenticationSubscription&
authentication_subscription, authentication_subscription,
nlohmann::json& json_data) = 0; nlohmann::json& json_data) = 0;
/*
* Delete an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @return true if successful, otherwise return false
*/
virtual bool delete_authentication_subscription(const std::string& id) = 0;
/* /*
* Query an item from the DB for the Authentication Subscription * Query an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity * @param [const std::string&] id: UE Identity
...@@ -91,13 +99,6 @@ class database_wrapper_abstraction { ...@@ -91,13 +99,6 @@ class database_wrapper_abstraction {
const std::vector<oai::udr::model::PatchItem>& patchItem, const std::vector<oai::udr::model::PatchItem>& patchItem,
nlohmann::json& json_data) = 0; nlohmann::json& json_data) = 0;
/*
* Delete an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @return true if successful, otherwise return false
*/
virtual bool delete_authentication_subscription(const std::string& id) = 0;
/* /*
* Query an item from the DB for AccessandMobilitySubscriptionData * Query an item from the DB for AccessandMobilitySubscriptionData
* @param [const std::string&] ue_id: UE Identity * @param [const std::string&] ue_id: UE Identity
......
...@@ -159,6 +159,26 @@ bool mysql_db::insert_authentication_subscription( ...@@ -159,6 +159,26 @@ bool mysql_db::insert_authentication_subscription(
return true; return true;
} }
//------------------------------------------------------------------------------
bool mysql_db::delete_authentication_subscription(const std::string& id) {
const std::string query =
"DELETE FROM AuthenticationSubscription WHERE ueid='" + id + "'";
Logger::udr_mysql().debug("MySQL Query %s: ", query.c_str());
if (mysql_real_query(
&mysql_connector, query.c_str(), (unsigned long) query.size())) {
Logger::udr_mysql().error(
"mysql_real_query failure! SQL Query %s", query.c_str());
return false;
}
Logger::udr_mysql().debug(
"Deleted AuthenticationSubscription (with UE ID %s) successfully",
id.c_str());
return true;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool mysql_db::query_authentication_subscription( bool mysql_db::query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) { const std::string& id, nlohmann::json& json_data) {
...@@ -321,11 +341,6 @@ bool mysql_db::update_authentication_subscription( ...@@ -321,11 +341,6 @@ bool mysql_db::update_authentication_subscription(
return true; return true;
} }
//------------------------------------------------------------------------------
bool mysql_db::delete_authentication_subscription(const std::string& id) {
return true;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool mysql_db::query_am_data( bool mysql_db::query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id, const std::string& ue_id, const std::string& serving_plmn_id,
......
...@@ -43,6 +43,8 @@ class mysql_db : public database_wrapper<mysql_db> { ...@@ -43,6 +43,8 @@ class mysql_db : public database_wrapper<mysql_db> {
authentication_subscription, authentication_subscription,
nlohmann::json& json_data); nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_authentication_subscription( bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data); const std::string& id, nlohmann::json& json_data);
...@@ -51,8 +53,6 @@ class mysql_db : public database_wrapper<mysql_db> { ...@@ -51,8 +53,6 @@ class mysql_db : public database_wrapper<mysql_db> {
const std::vector<oai::udr::model::PatchItem>& patchItem, const std::vector<oai::udr::model::PatchItem>& patchItem,
nlohmann::json& json_data); nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_am_data( bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id, const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data); nlohmann::json& json_data);
......
...@@ -187,7 +187,7 @@ void udr_app::handle_create_authentication_data( ...@@ -187,7 +187,7 @@ void udr_app::handle_create_authentication_data(
const std::string& ue_id, const std::string& ue_id,
const AuthenticationSubscription& authentication_subscription, const AuthenticationSubscription& authentication_subscription,
nlohmann::json& response_data, long& code) { nlohmann::json& response_data, long& code) {
Logger::udr_app().info("Crate an authentication subscription data of a UE"); Logger::udr_app().info("Create an authentication subscription data of a UE");
if (db_connector->insert_authentication_subscription( if (db_connector->insert_authentication_subscription(
ue_id, authentication_subscription, response_data)) { ue_id, authentication_subscription, response_data)) {
...@@ -200,6 +200,21 @@ void udr_app::handle_create_authentication_data( ...@@ -200,6 +200,21 @@ void udr_app::handle_create_authentication_data(
return; return;
} }
//------------------------------------------------------------------------------
void udr_app::handle_delete_authentication_data(
const std::string& ue_id, nlohmann::json& response_data, long& code) {
Logger::udr_app().info("Delete an authentication subscription data of a UE");
if (db_connector->delete_authentication_subscription(ue_id)) {
code = HTTP_STATUS_CODE_204_NO_CONTENT;
Logger::udr_app().info(
"Successful removed the authentication subscription data of a UE");
} else {
code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; // TODO
}
return;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void udr_app::handle_modify_authentication_subscription( void udr_app::handle_modify_authentication_subscription(
const std::string& ue_id, const std::vector<PatchItem>& patchItem, const std::string& ue_id, const std::vector<PatchItem>& patchItem,
......
...@@ -144,12 +144,22 @@ class udr_app { ...@@ -144,12 +144,22 @@ class udr_app {
* @param [long code] http_code: HTTP response code * @param [long code] http_code: HTTP response code
* @return void * @return void
*/ */
void handle_create_authentication_data( void handle_create_authentication_data(
const std::string& ue_id, const std::string& ue_id,
const AuthenticationSubscription& authentication_subscription, const AuthenticationSubscription& authentication_subscription,
nlohmann::json& response_data, long& code); nlohmann::json& response_data, long& code);
/*
* Handle a request to remove the AuthenticationSubscription
* (AuthenticationDataDocumentApiImpl)
* @param [const std::string&] ue_id: UE Identity
* @param [nlohmann::json&] response_data: Response in Json format
* @param [long code] code: HTTP response code
* @return void
*/
void handle_delete_authentication_data(
const std::string& ue_id, nlohmann::json& response_data, long& code);
/* /*
* Handle a request to modify AuthenticationSubscription * Handle a request to modify AuthenticationSubscription
* (AuthenticationSubscriptionDocumentApiImpl) * (AuthenticationSubscriptionDocumentApiImpl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment