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() {
Routes::bind(
&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
router->addCustomHandler(Routes::bind(
&AuthenticationDataDocumentApi::
......@@ -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::
authentication_data_document_api_default_handler(
const Pistache::Rest::Request&,
......
......@@ -68,6 +68,9 @@ class AuthenticationDataDocumentApi {
void create_auth_subs_data_handler(
const Pistache::Rest::Request& request,
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(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
......@@ -105,6 +108,16 @@ class AuthenticationDataDocumentApi {
const oai::udr::model::AuthenticationSubscription&
authenticationSubscription,
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
......
......@@ -63,8 +63,19 @@ void AuthenticationDataDocumentApiImpl::create_auth_subs_data(
code = static_cast<Pistache::Http::Code>(httpCode);
Logger::udr_server().debug("HTTP Response code %d.\n", code);
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
......
......@@ -75,6 +75,8 @@ class AuthenticationDataDocumentApiImpl
const std::string& ueId,
const AuthenticationSubscription& authenticationSubscription,
Pistache::Http::ResponseWriter& response);
void delete_auth_subs_data(
const std::string& ueId, Pistache::Http::ResponseWriter& response);
};
} // namespace oai::udr::api
......
......@@ -57,6 +57,11 @@ bool cassandra_db::insert_authentication_subscription(
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::delete_authentication_subscription(const std::string& id) {
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) {
......@@ -70,11 +75,6 @@ bool cassandra_db::update_authentication_subscription(
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::delete_authentication_subscription(const std::string& id) {
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
......
......@@ -41,14 +41,14 @@ class cassandra_db : public database_wrapper<cassandra_db> {
authentication_subscription,
nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data);
bool update_authentication_subscription(
const std::string& id, const nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data);
......
......@@ -64,6 +64,10 @@ class database_wrapper : public database_wrapper_abstraction {
return true;
}
bool delete_authentication_subscription(const std::string& id) override {
return true;
}
bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) override {
return true;
......@@ -76,10 +80,6 @@ class database_wrapper : public database_wrapper_abstraction {
return true;
}
bool delete_authentication_subscription(const std::string& id) override {
return true;
}
bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data) override {
......
......@@ -69,6 +69,14 @@ class database_wrapper_abstraction {
const oai::udr::model::AuthenticationSubscription&
authentication_subscription,
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
* @param [const std::string&] id: UE Identity
......@@ -91,13 +99,6 @@ class database_wrapper_abstraction {
const std::vector<oai::udr::model::PatchItem>& patchItem,
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
* @param [const std::string&] ue_id: UE Identity
......
......@@ -159,6 +159,26 @@ bool mysql_db::insert_authentication_subscription(
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(
const std::string& id, nlohmann::json& json_data) {
......@@ -321,11 +341,6 @@ bool mysql_db::update_authentication_subscription(
return true;
}
//------------------------------------------------------------------------------
bool mysql_db::delete_authentication_subscription(const std::string& id) {
return true;
}
//------------------------------------------------------------------------------
bool mysql_db::query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
......
......@@ -43,6 +43,8 @@ class mysql_db : public database_wrapper<mysql_db> {
authentication_subscription,
nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data);
......@@ -51,8 +53,6 @@ class mysql_db : public database_wrapper<mysql_db> {
const std::vector<oai::udr::model::PatchItem>& patchItem,
nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_am_data(
const std::string& ue_id, const std::string& serving_plmn_id,
nlohmann::json& json_data);
......
......@@ -187,7 +187,7 @@ void udr_app::handle_create_authentication_data(
const std::string& ue_id,
const AuthenticationSubscription& authentication_subscription,
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(
ue_id, authentication_subscription, response_data)) {
......@@ -200,6 +200,21 @@ void udr_app::handle_create_authentication_data(
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(
const std::string& ue_id, const std::vector<PatchItem>& patchItem,
......
......@@ -144,12 +144,22 @@ class udr_app {
* @param [long code] http_code: HTTP response code
* @return void
*/
void handle_create_authentication_data(
const std::string& ue_id,
const AuthenticationSubscription& authentication_subscription,
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
* (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