Commit ec554974 authored by yangjian's avatar yangjian

Update SMFSelectionSubscriptionData: add database

parent b724ff91
cmake_minimum_required (VERSION 3.2)
project(api-server)
project(udr)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" )
......
......@@ -35,13 +35,14 @@ Once compiled run the server:
```bash
cd build
./api-server
./udr
```
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [pistache](http://pistache.io/quickstart): Please download the `Pistache` project and
put the "include" folder and the generated "*.so" file into external/include/ and external/lib/ after compilation
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model/nlohmann folder
put it under the external/include/nlohmann folder
## Namespaces
org.openapitools.server.api
......
......@@ -19,13 +19,66 @@ namespace api {
using namespace org::openapitools::server::model;
SMFSelectionSubscriptionDataDocumentApiImpl::SMFSelectionSubscriptionDataDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
SMFSelectionSubscriptionDataDocumentApiImpl::SMFSelectionSubscriptionDataDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr, MYSQL *mysql)
: SMFSelectionSubscriptionDataDocumentApi(rtr)
{ }
{
mysql_WitcommUDRDB = mysql;
}
void SMFSelectionSubscriptionDataDocumentApiImpl::query_smf_select_data(const std::string &ueId, const std::string &servingPlmnId, const Pistache::Optional<std::vector<std::string>> &fields, const Pistache::Optional<std::string> &supportedFeatures, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "query_smf_select_data\n");
//response.send(Pistache::Http::Code::Ok, "query_smf_select_data\n");
//servingPlmnId pattern: "^[0-9]{5,6}$"
MYSQL_RES *res = NULL;
MYSQL_ROW row;
MYSQL_FIELD* field = nullptr;
nlohmann::json j;
SmfSelectionSubscriptionData smfselectionsubscriptiondata;
const std::string query = "select * from SmfSelectionSubscriptionData WHERE ueid="+ueId;
if (mysql_real_query(mysql_WitcommUDRDB,query.c_str(), (unsigned long)query.size()))
{
std::cout << "mysql_real_query failure!" << std::endl;
return;
}
res = mysql_store_result(mysql_WitcommUDRDB);
if(res == NULL)
{
std::cout << "mysql_store_result failure!" << std::endl;
return;
}
row = mysql_fetch_row(res);
if(row != NULL)
{
for (int i = 0; field = mysql_fetch_field(res); i++)
{
if(!strcmp("supportedFeatures", field->name) && row[i] != NULL)
{
smfselectionsubscriptiondata.setSupportedFeatures(row[i]);
}
else if(!strcmp("subscribedSnssaiInfos", field->name) && row[i] != NULL)
{
// SmfSelectionSubscriptionData.setSubscribedSnssaiInfos(std :: map < std :: string, SnssaiInfo > const & value);
}
else if(!strcmp("sharedSnssaiInfosId", field->name) && row[i] != NULL)
{
smfselectionsubscriptiondata.setSharedSnssaiInfosId(row[i]);
}
}
to_json(j,smfselectionsubscriptiondata);
response.send(Pistache::Http::Code::Ok, j.dump());
}
else
{
std::cout << "SmfSelectionSubscriptionData no data!" << std::endl;
}
mysql_free_result(res);
}
}
......
......@@ -32,6 +32,8 @@
#include "SmfSelectionSubscriptionData.h"
#include <string>
#include <mysql/mysql.h>
namespace org {
namespace openapitools {
namespace server {
......@@ -41,11 +43,13 @@ using namespace org::openapitools::server::model;
class SMFSelectionSubscriptionDataDocumentApiImpl : public org::openapitools::server::api::SMFSelectionSubscriptionDataDocumentApi {
public:
SMFSelectionSubscriptionDataDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router>);
SMFSelectionSubscriptionDataDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router>, MYSQL *mysql);
~SMFSelectionSubscriptionDataDocumentApiImpl() {}
void query_smf_select_data(const std::string &ueId, const std::string &servingPlmnId, const Pistache::Optional<std::vector<std::string>> &fields, const Pistache::Optional<std::string> &supportedFeatures, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, Pistache::Http::ResponseWriter &response);
private:
MYSQL *mysql_WitcommUDRDB;
};
}
......
......@@ -311,7 +311,7 @@ int main() {
SMFRegistrationDocumentApiserver.init();
SMFRegistrationsCollectionApiImpl SMFRegistrationsCollectionApiserver(router);
SMFRegistrationsCollectionApiserver.init();
SMFSelectionSubscriptionDataDocumentApiImpl SMFSelectionSubscriptionDataDocumentApiserver(router);
SMFSelectionSubscriptionDataDocumentApiImpl SMFSelectionSubscriptionDataDocumentApiserver(router, &mysql);
SMFSelectionSubscriptionDataDocumentApiserver.init();
SMSF3GPPRegistrationDocumentApiImpl SMSF3GPPRegistrationDocumentApiserver(router);
SMSF3GPPRegistrationDocumentApiserver.init();
......
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