Commit f69a7d22 authored by liuyu's avatar liuyu

offer create and get record

parent 6fa10d20
......@@ -1457,6 +1457,10 @@ ProblemDetails.h
/home/liuyu/UDSF/src/impl/ProblemDetails.h
string
-
mysql/mysql.h
-
logger.hpp
/home/liuyu/UDSF/src/impl/logger.hpp
/home/liuyu/UDSF/src/impl/MetaSchemaCRUDApiImpl.cpp
MetaSchemaCRUDApiImpl.h
......@@ -1545,6 +1549,8 @@ RecordCRUDApiImpl.h
/home/liuyu/UDSF/src/impl/RecordCRUDApiImpl.h
logger.hpp
/home/liuyu/UDSF/src/impl/logger.hpp
list
-
/home/liuyu/UDSF/src/impl/RecordCRUDApiImpl.h
pistache/endpoint.h
......@@ -1815,6 +1821,8 @@ RecordMeta.h
/home/liuyu/UDSF/src/model/RecordMeta.h
/home/liuyu/UDSF/src/model/RecordMeta.h
set
-
string
-
map
......
......@@ -447,7 +447,40 @@ CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o
/home/liuyu/UDSF/build/ext/include/pistache/type_checkers.h
/home/liuyu/UDSF/build/ext/include/pistache/typeid.h
/home/liuyu/UDSF/build/ext/include/pistache/view.h
/home/liuyu/UDSF/build/ext/include/spdlog/async_logger.h
/home/liuyu/UDSF/build/ext/include/spdlog/common.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/async_log_helper.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/async_logger_impl.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/file_helper.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/log_msg.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/logger_impl.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/mpmc_blocking_q.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/null_mutex.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/os.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/pattern_formatter_impl.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/registry.h
/home/liuyu/UDSF/build/ext/include/spdlog/details/spdlog_impl.h
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/format.cc
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/format.h
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/ostream.cc
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/ostream.h
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/printf.cc
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/printf.h
/home/liuyu/UDSF/build/ext/include/spdlog/fmt/fmt.h
/home/liuyu/UDSF/build/ext/include/spdlog/formatter.h
/home/liuyu/UDSF/build/ext/include/spdlog/logger.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/android_sink.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/ansicolor_sink.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/base_sink.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/file_sinks.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/sink.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/stdout_sinks.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/syslog_sink.h
/home/liuyu/UDSF/build/ext/include/spdlog/sinks/wincolor_sink.h
/home/liuyu/UDSF/build/ext/include/spdlog/spdlog.h
/home/liuyu/UDSF/build/ext/include/spdlog/tweakme.h
/home/liuyu/UDSF/src/api/BlockCRUDApi.h
/home/liuyu/UDSF/src/common/logger.hpp
/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp
/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.h
/home/liuyu/UDSF/src/model/AccessTokenErr.h
......
......@@ -446,7 +446,40 @@ CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/pistache/type_checkers.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/pistache/typeid.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/pistache/view.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/async_logger.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/common.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/async_log_helper.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/async_logger_impl.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/file_helper.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/log_msg.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/logger_impl.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/mpmc_blocking_q.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/null_mutex.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/os.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/pattern_formatter_impl.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/registry.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/details/spdlog_impl.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/format.cc
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/format.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/ostream.cc
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/ostream.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/printf.cc
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/bundled/printf.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/fmt/fmt.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/formatter.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/logger.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/android_sink.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/ansicolor_sink.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/base_sink.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/file_sinks.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/sink.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/stdout_sinks.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/syslog_sink.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/sinks/wincolor_sink.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/spdlog.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/build/ext/include/spdlog/tweakme.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/src/api/BlockCRUDApi.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/src/common/logger.hpp
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.h
CMakeFiles/udsf.dir/home/liuyu/UDSF/src/impl/BlockCRUDApiImpl.cpp.o: /home/liuyu/UDSF/src/model/AccessTokenErr.h
......
No preview for this file type
{"meta": { "tages" : {"context_type" : ["gnb_context"], "modify_time" :["0202020"],"recordId" : ["460110123456789" ] } },
"blocks": [{"Content-ID": "userDefBinaryBlob", "Content-Type": "text/plain", "content": "QmxvY2sgY29udGVudA=="}, {"Content-Id": "userDefJsonBlob", "Content-Type": "application/json", "content": {"key": "ftsimpletype-999550000000002", "value": "A3E71A78377179B5B91A;imsi-999550000000123"}}]}
{"meta": { "tages" : {"context_type" : ["gnb_context"], "modify_time" :["0202020"],"recordId" : ["460110123456789" ] }},"blocks":[{"Content-ID":"gnb_global_id","Content-type":"text/plain","content":"012345"}]}
{"meta":{ "tags" :{"modify_time" : ["111"], "gnb_context" :["222"],"recordId" : ["460110123456789" ]} }, "blocks": [{"Content-ID": "userDefBinaryBlob", "Content-Type": "text/plain", "content": "QmxvY2sgY29udGVudA=="}] }
\ No newline at end of file
-- MySQL dump 10.13 Distrib 8.0.24, for Linux (x86_64)
--
-- Host: localhost Database: _123
-- ------------------------------------------------------
-- Server version 8.0.24
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `_456`
--
DROP TABLE IF EXISTS `_456`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `_456` (
`imsi` varchar(15) DEFAULT NULL,
`_key` varchar(32) DEFAULT NULL,
`OPc` varchar(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `_456`
--
LOCK TABLES `_456` WRITE;
/*!40000 ALTER TABLE `_456` DISABLE KEYS */;
INSERT INTO `_456` VALUES ('460110123456789','00112233445566778899AABBCCDDEEFF','000102030405060708090A0B0C0D0E0F'),('460112223456789','00112233445566778899AABBCCDDEEFF','000102030405060708090A0B0C0D0E0F');
/*!40000 ALTER TABLE `_456` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-04-26 18:25:53
......@@ -142,6 +142,8 @@ void BlockCRUDApi::get_block_handler(const Pistache::Rest::Request &request, Pis
auto recordId = request.param(":recordId").as<std::string>();
auto blockId = request.param(":blockId").as<std::string>();
Logger::udsf_server().info("--GET!--/%s/%s/records/%s",realmId.c_str(),storageId.c_str(),recordId.c_str());
// Getting the query params
auto supportedFeaturesQuery = request.query().get("supported-features");
Pistache::Optional<std::string> supportedFeatures;
......
......@@ -46,12 +46,13 @@ void RecordCRUDApi::setupRoutes() {
void RecordCRUDApi::create_or_modify_record_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
Logger::udsf_server().info("Record : GET!");
auto realmId = request.param(":realmId").as<std::string>();
auto storageId = request.param(":storageId").as<std::string>();
auto recordId = request.param(":recordId").as<std::string>();
Logger::udsf_server().info("--Put!--/%s/%s/records/%s",realmId.c_str(),storageId.c_str(),recordId.c_str());
// Getting the body param
Record record;
......@@ -77,8 +78,9 @@ void RecordCRUDApi::create_or_modify_record_handler(const Pistache::Rest::Reques
// Getting the header params
auto ifNoneMatch = request.headers().tryGetRaw("If-None-Match");
auto ifMatch = request.headers().tryGetRaw("If-Match");
std::cout<<request.body()<<std::endl;
try {
//{"meta": { "tags" : {"tag1" : ["value1"], "tag2" :["value2"] } }, "blocks": [{"Content-ID": "userDefBinaryBlob", "Content-Type": "text/plain", "content": "QmxvY2sgY29udGVudA=="}, {"Content-Id": "userDefJsonBlob", "Content-Type": "application/json", "content": {"key": "ftsimpletype-999550000000002", "value": "A3E71A78377179B5B91A;imsi-999550000000123"}}]}
nlohmann::json::parse(request.body()).get_to(record);
this->create_or_modify_record(realmId, storageId, recordId, record, ifNoneMatch, ifMatch, getPrevious, supportedFeatures, response);
} catch (nlohmann::detail::exception &e) {
......
......@@ -19,10 +19,11 @@ namespace api {
using namespace org::openapitools::server::model;
BlockCRUDApiImpl::BlockCRUDApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
BlockCRUDApiImpl::BlockCRUDApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr,MYSQL *mysql)
: BlockCRUDApi(rtr)
{ }
{
mysql_block = mysql;
}
//void BlockCRUDApiImpl::create_or_modify_block(const std::string &realmId, const std::string &storageId, const std::string &recordId, const std::string &blockId, const AnyType &body, const Pistache::Optional<bool> &getPrevious, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifMatch, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
// response.send(Pistache::Http::Code::Ok, "Do some magic\n");
//}
......@@ -30,10 +31,92 @@ void BlockCRUDApiImpl::delete_block(const std::string &realmId, const std::strin
response.send(Pistache::Http::Code::Ok, "Do some magic BlockCRUDApiImpl::delete_block\n");
}
void BlockCRUDApiImpl::get_block(const std::string &realmId, const std::string &storageId, const std::string &recordId, const std::string &blockId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic BlockCRUDApiImpl::get_block\n");
const std::string change_dabatase = "use "+ std::string("_" ) +realmId ;
printf("------------%s------------------\n",change_dabatase.c_str());
if(mysql_query(mysql_block, change_dabatase.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n",change_dabatase.c_str(), mysql_error(mysql_block));
return;
}
const std::string chose_block = "select "+blockId+ " from "+ std::string("_" )+ storageId + " where imsi="+ recordId;
if(mysql_query(mysql_block, chose_block.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n", chose_block,mysql_error(mysql_block));
return;
}
MYSQL_RES *result = mysql_store_result(mysql_block);
if (NULL == result)
{
printf("mysql_store_result failure!SQL(%s) error(%d):%s\n", chose_block,mysql_errno(mysql_block), mysql_error(mysql_block));
return;
}
int num_rows = mysql_num_rows(result);//2
printf("got:%d row:\n", (int)num_rows);
int num_fields = mysql_num_fields(result);//3
printf("number of fields:%d\n", (int)num_fields);
nlohmann::json json;
MYSQL_ROW row;
while (row = mysql_fetch_row(result))
{
unsigned long *lengths = mysql_fetch_lengths(result);
for (int i = 0; i < num_fields; i++)
{
char *filed = row[i];
unsigned int field_length = lengths[i];
json = {{blockId, filed}};
printf("column[%d],length[%d],data[%s]\n", i, field_length, filed ? filed : "null");
}
printf("\n");
}
mysql_free_result(result);
response.send(Pistache::Http::Code::Ok, json.dump());
}
void BlockCRUDApiImpl::get_block_list(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic BlockCRUDApiImpl::get_block_list\n");
const std::string change_dabatase = "use "+ std::string("_" ) +realmId ;
printf("------------%s------------------\n",change_dabatase.c_str());
if(mysql_query(mysql_block, change_dabatase.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n",change_dabatase.c_str(), mysql_error(mysql_block));
return;
}
const std::string chose_block = "select OPc,_key from "+ std::string("_" )+ storageId + " where imsi="+ recordId;
if(mysql_query(mysql_block, chose_block.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n", chose_block,mysql_error(mysql_block));
return;
}
MYSQL_RES *result = mysql_store_result(mysql_block);
if (NULL == result)
{
printf("mysql_store_result failure!SQL(%s) error(%d):%s\n", chose_block,mysql_errno(mysql_block), mysql_error(mysql_block));
return;
}
int num_rows = mysql_num_rows(result);//2
printf("got:%d row:\n", (int)num_rows);
int num_fields = mysql_num_fields(result);//3
printf("number of fields:%d\n", (int)num_fields);
nlohmann::json json;
MYSQL_FIELD *field = nullptr;
MYSQL_ROW row;
while (row = mysql_fetch_row(result))
{
unsigned long *lengths = mysql_fetch_lengths(result);
for (int i = 0; i < num_fields; i++)
{
char *filed = row[i];
unsigned int field_length = lengths[i];
field = mysql_fetch_field(result);
json[field->name] = filed;
printf("column[%d],length[%d],field[%s]:data[%s]\n", i, field_length, field->name,filed ? filed : "null");
}
printf("\n");
}
mysql_free_result(result);
response.send(Pistache::Http::Code::Ok, json.dump());
}
}
......
......@@ -33,7 +33,8 @@
#include "Inline_response_200.h"
#include "ProblemDetails.h"
#include <string>
#include <mysql/mysql.h>
#include "logger.hpp"
namespace org {
namespace openapitools {
namespace server {
......@@ -43,14 +44,15 @@ using namespace org::openapitools::server::model;
class BlockCRUDApiImpl : public org::openapitools::server::api::BlockCRUDApi {
public:
BlockCRUDApiImpl(std::shared_ptr<Pistache::Rest::Router>);
BlockCRUDApiImpl(std::shared_ptr<Pistache::Rest::Router>,MYSQL *mysql);
~BlockCRUDApiImpl() {}
//void create_or_modify_block(const std::string &realmId, const std::string &storageId, const std::string &recordId, const std::string &blockId, const AnyType &body, const Pistache::Optional<bool> &getPrevious, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifMatch, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
void delete_block(const std::string &realmId, const std::string &storageId, const std::string &recordId, const std::string &blockId, const Pistache::Optional<bool> &getPrevious, const Pistache::Optional<Pistache::Http::Header::Raw> &ifMatch, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
void get_block(const std::string &realmId, const std::string &storageId, const std::string &recordId, const std::string &blockId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
void get_block_list(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
private:
MYSQL *mysql_block;
};
}
......
......@@ -12,6 +12,7 @@
#include "RecordCRUDApiImpl.h"
#include "logger.hpp"
#include <list>
namespace org {
namespace openapitools {
namespace server {
......@@ -26,7 +27,73 @@ RecordCRUDApiImpl::RecordCRUDApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr
}
void RecordCRUDApiImpl::create_or_modify_record(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Record &record, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifMatch, const Pistache::Optional<bool> &getPrevious, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic RecordCRUDApiImpl::create_or_modify_record\n");
const std::string change_dabatase = "use " + realmId ;
Logger::udsf_server().info("------------%s------------------",change_dabatase.c_str());
if(mysql_query(mysql_record, change_dabatase.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n",change_dabatase.c_str(), mysql_error(mysql_record));
return;
}
std::map<std::string, std::set<std::string>> meta_map = record.getMeta().getTags();
std::map<std::string, std::set<std::string>>::iterator it_meta;
int i_meta=0;
std::string meta[meta_map.size()];
for(it_meta=meta_map.begin();it_meta!=meta_map.end();)
{
meta[i_meta] = it_meta->first;
meta_map.erase(it_meta++);
i_meta++;
}
std::map<std::string, std::string> blocks_map = record.getBlocks().at(0);
std::string block[blocks_map.size()];
std::map<std::string, std::string>::iterator it_block;
int i_block=0;
for(it_block=blocks_map.begin();it_block!=blocks_map.end();)
{
block[i_block] = it_block->first;
blocks_map.erase(it_block++);
i_block++;
}
std::string extrnal = "create table IF NOT EXISTS "+ storageId + "(";
for(int i=0;i<i_meta;i++)
{
extrnal = extrnal + meta[i] + " varchar(32)";
extrnal = extrnal + std::string(",") ;
}
for(int j=0;j<i_block;j++)
{
extrnal = extrnal + block[j] + " varchar(32)";
if(j==(i_block-1)){
break;
}
extrnal = extrnal + std::string(",") ;
}
const std::string create_table = extrnal + ")";
Logger::udsf_server().info("%s", create_table.c_str());
if(mysql_query(mysql_record, create_table.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n", create_table.c_str(),mysql_error(mysql_record));
return;
}
extrnal = "insert into "+ storageId + " values(\'";
for(int ii=0;ii<i_meta;ii++)
{
extrnal = extrnal +(*(record.getMeta().getTags().find(meta[ii])->second.begin())).c_str() + "\', \'";
}
for(int jj=0;jj<i_block;jj++)
{
extrnal = extrnal + record.getBlocks().at(0).find(block[jj])->second.c_str() +"\'";
if(jj==(i_block-1)){
break;
}
extrnal = extrnal + ", \'" ;
}
const std::string insert_record = extrnal + ")";
Logger::udsf_server().info("%s", insert_record.c_str());
if(mysql_query(mysql_record, insert_record.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n", insert_record.c_str(),mysql_error(mysql_record));
return;
}
response.send(Pistache::Http::Code::Created);
}
void RecordCRUDApiImpl::delete_record(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifMatch, const Pistache::Optional<bool> &getPrevious, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic RecordCRUDApiImpl::delete_record\n");
......@@ -35,16 +102,16 @@ void RecordCRUDApiImpl::get_meta(const std::string &realmId, const std::string &
response.send(Pistache::Http::Code::Ok, "Do some magic RecordCRUDApiImpl::get_meta\n");
}
void RecordCRUDApiImpl::get_record(const std::string &realmId, const std::string &storageId, const std::string &recordId, const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch, const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
const std::string change_dabatase = "use "+ realmId + std::string("_" ) + storageId ;
const std::string change_dabatase = "use " + realmId ;
printf("------------%s------------------\n",change_dabatase.c_str());
if(mysql_query(mysql_record, change_dabatase.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n",change_dabatase.c_str(), mysql_error(mysql_record));
return;
}
const std::string chose_record = "select * from "+ std::string("_" )+ recordId ;
const std::string chose_record = "select * from "+ storageId + " where RECORD_ID="+recordId ;
if(mysql_query(mysql_record, chose_record.c_str())){
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n", chose_record,mysql_error(mysql_record));
Logger::udsf_server().error("mysql_real_query failure!SQL(%s) error:%s\n", chose_record.c_str(),mysql_error(mysql_record));
return;
}
......@@ -59,7 +126,9 @@ void RecordCRUDApiImpl::get_record(const std::string &realmId, const std::string
printf("got:%d row:\n", (int)num_rows);
int num_fields = mysql_num_fields(result);//3
printf("number of fields:%d\n", (int)num_fields);
MYSQL_FIELD *field = nullptr;
nlohmann::json json;
MYSQL_ROW row;
while (row = mysql_fetch_row(result))
{
......@@ -68,13 +137,14 @@ void RecordCRUDApiImpl::get_record(const std::string &realmId, const std::string
{
char *filed = row[i];
unsigned int field_length = lengths[i];
printf("column[%d],length[%d],data[%s]\n", i, field_length, filed ? filed : "null");
field = mysql_fetch_field(result);
json[field->name] = filed;
printf("column[%d],length[%d],field[%s]:data[%s]\n", i, field_length, field->name,filed ? filed : "null");
}
printf("\n");
}
mysql_free_result(result);
nlohmann::json json;
json = {{"foo", "bar"}};
response.send(Pistache::Http::Code::Ok, json.dump());
}
void RecordCRUDApiImpl::search_record(const std::string &realmId, const std::string &storageId, const Pistache::Optional<int32_t> &limitRange, const Pistache::Optional<SearchExpression> &filter, const Pistache::Optional<bool> &countIndicator, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
......
......@@ -37,8 +37,8 @@ void to_json(nlohmann::json& j, const Record& o)
{
j = nlohmann::json();
j["meta"] = o.m_Meta;
// if(o.blocksIsSet() || !o.m_Blocks.empty())
// j["blocks"] = o.m_Blocks;
if(o.blocksIsSet() || !o.m_Blocks.empty())
j["blocks"] = o.m_Blocks;
}
void from_json(const nlohmann::json& j, Record& o)
......@@ -46,7 +46,7 @@ void from_json(const nlohmann::json& j, Record& o)
j.at("meta").get_to(o.m_Meta);
if(j.find("blocks") != j.end())
{
// j.at("blocks").get_to(o.m_Blocks);
j.at("blocks").get_to(o.m_Blocks);
o.m_BlocksIsSet = true;
}
}
......@@ -59,15 +59,15 @@ void Record::setMeta(RecordMeta const& value)
{
m_Meta = value;
}
// std::vector<AnyType>& Record::getBlocks()
// {
// return m_Blocks;
// }
//void Record::setBlocks(std::vector<AnyType> const& value)
//{
// m_Blocks = value;
// m_BlocksIsSet = true;
//}
std::vector<std::map<std::string, std::string>> Record::getBlocks() const
{
return m_Blocks;
}
void Record::setBlocks(std::vector<std::map<std::string, std::string>> const& value)
{
m_Blocks = value;
m_BlocksIsSet = true;
}
bool Record::blocksIsSet() const
{
return m_BlocksIsSet;
......
......@@ -29,6 +29,12 @@ namespace openapitools {
namespace server {
namespace model {
// struct block{
// std::string Content_id ;
// std::string Content_type;
// std::string caontent;
// };
/// <summary>
/// Definition of a Record
/// </summary>
......@@ -51,8 +57,8 @@ public:
/// <summary>
/// list of opaque Block&#39;s in this Record
/// </summary>
// std::vector<AnyType>& getBlocks();
// void setBlocks(std::vector<AnyType> const& value);
std::vector<std::map<std::string, std::string>> getBlocks() const;
void setBlocks(std::vector<std::map<std::string, std::string>> const& value);
bool blocksIsSet() const;
void unsetBlocks();
......@@ -61,7 +67,7 @@ public:
protected:
RecordMeta m_Meta;
//std::vector<AnyType> m_Blocks;
std::vector< std::map<std::string, std::string>> m_Blocks;
bool m_BlocksIsSet;
};
......
......@@ -44,8 +44,8 @@ void to_json(nlohmann::json& j, const RecordMeta& o)
j["ttl"] = o.m_Ttl;
if(o.callbackReferenceIsSet())
j["callbackReference"] = o.m_CallbackReference;
// if(o.tagsIsSet() || !o.m_Tags.empty())
// j["tags"] = o.m_Tags;
if(o.tagsIsSet() || !o.m_Tags.empty())
j["tags"] = o.m_Tags;
}
void from_json(const nlohmann::json& j, RecordMeta& o)
......@@ -62,7 +62,7 @@ void from_json(const nlohmann::json& j, RecordMeta& o)
}
if(j.find("tags") != j.end())
{
// j.at("tags").get_to(o.m_Tags);
j.at("tags").get_to(o.m_Tags);
o.m_TagsIsSet = true;
}
}
......@@ -101,15 +101,15 @@ void RecordMeta::unsetCallbackReference()
{
m_CallbackReferenceIsSet = false;
}
// std::map<std::string, Set<std::string>>& RecordMeta::getTags()
// {
// return m_Tags;
// }
// void RecordMeta::setTags(std::map<std::string, Set<std::strmakeing>> const& value)
// {
// m_Tags = value;
// m_TagsIsSet = true;
// }
std::map<std::string, std::set<std::string>>& RecordMeta::getTags()
{
return m_Tags;
}
void RecordMeta::setTags(std::map<std::string, std::set<std::string>> const& value)
{
m_Tags = value;
m_TagsIsSet = true;
}
bool RecordMeta::tagsIsSet() const
{
return m_TagsIsSet;
......
......@@ -19,7 +19,7 @@
#define RecordMeta_H_
//#include "Set.h"
#include <set>
#include <string>
#include <map>
#include <vector>
......@@ -61,8 +61,8 @@ public:
/// <summary>
/// A dictionary of {\&quot;tagName\&quot;: [ \&quot;tagValue\&quot;, ...] }. A tag name can be used to retrieve a Record. The tagValue are unique.
/// </summary>
//std::map<std::string, Set<std::string>>& getTags();
//void setTags(std::map<std::string, Set<std::string>> const& value);
std::map<std::string, std::set<std::string>>& getTags();
void setTags(std::map<std::string, std::set<std::string>> const& value);
bool tagsIsSet() const;
void unsetTags();
......@@ -73,7 +73,7 @@ protected:
bool m_TtlIsSet;
std::string m_CallbackReference;
bool m_CallbackReferenceIsSet;
//std::map<std::string, Set<std::string>> m_Tags;
std::map<std::string, std::set<std::string>> m_Tags;
bool m_TagsIsSet;
};
......
......@@ -36,7 +36,7 @@ UDSFApiServer::UDSFApiServer(Pistache::Address address, MYSQL *mysql)
m_router = std::make_shared<Pistache::Rest::Router>();
m_BlockCRUDApiserver =
std::make_shared<BlockCRUDApiImpl>(m_router);
std::make_shared<BlockCRUDApiImpl>(m_router,mysql);
m_MetaSchemaCRUDApiserver =
std::make_shared<MetaSchemaCRUDApiImpl>(m_router);
m_NotificationSubscriptionCRUDApiserver =
......
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