Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions App/Server/OpenAPIGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ QJsonObject OpenAPIGenerator::retrieveJson(
QJsonObject PathsObject;
QJsonArray TagsArray;

#ifdef QT_DEBUG
foreach (const QString &Key, RESTAPIRegistry::Registry.keys()) {
QString PathString = Key.split(" ").last();
QString HTTPMethod = Key.split(" ").first().toLower();
QStringList PKInPathStorage;

clsAPIObject* APIObject = RESTAPIRegistry::Registry.value(Key);

qDebug().noquote().nospace()
<< Key << endl
<< " ParamNames: [" << APIObject->ParamNames.count() << "] " << APIObject->ParamNames.join(", ") << endl
<< " ParamTypesName: [" << APIObject->ParamTypesName.count() << "] " << APIObject->ParamTypesName.join(", ") << endl
<< " DefaultValues: [" << APIObject->BaseMethod.DefaultValues.count() << "] " << APIObject->BaseMethod.DefaultValues << endl
<< (APIObject->BaseMethod.DefaultValues.count() != APIObject->ParamNames.count()
? " ******************** ERROR IN COUNTERS ********************"
: "")
;
}
#endif

foreach (const QString &Key, RESTAPIRegistry::Registry.keys()) {
QString PathString = Key.split(" ").last();
QString HTTPMethod = Key.split(" ").first().toLower();
Expand Down
138 changes: 118 additions & 20 deletions App/Server/RESTAPIRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,24 +435,6 @@ QMap<QString, QString> RESTAPIRegistry::extractMethods(
return Methods;
}

QStringList RESTAPIRegistry::registeredAPIs(const QString& _module, bool _showParams, bool _showTypes, bool _prettifyTypes) {
if (_showParams == false) {
#ifdef TARGOMAN_API_ENABLE_WEBSOCKET
QStringList Methods = RESTAPIRegistry::Registry.keys();
Methods.append(RESTAPIRegistry::WSRegistry.keys());
return Methods;
#else
return RESTAPIRegistry::Registry.keys();
#endif
}

QMap<QString, QString> Methods = RESTAPIRegistry::extractMethods(RESTAPIRegistry::Registry, _module, _showTypes, _prettifyTypes);
#ifdef TARGOMAN_API_ENABLE_WEBSOCKET
Methods.unite(RESTAPIRegistry::extractMethods(RESTAPIRegistry::WSRegistry, _module, _showTypes, _prettifyTypes));
#endif
return Methods.values();
}

QString RESTAPIRegistry::isValidType(int _typeID, bool _validate4Input) {
if (_typeID == 0 || _typeID == QMetaType::User) // || _typeID == QMetaType::User)
return "is not registered with Qt MetaTypes";
Expand Down Expand Up @@ -594,7 +576,6 @@ void RESTAPIRegistry::addRegistryEntry(
}
}


int RESTAPIRegistry::getTagSeconds(const QMetaMethod& _method, const char* _type) {
if (_method.tag() == nullptr || _method.tag()[0] == '\0')
return 0;
Expand All @@ -616,6 +597,124 @@ int RESTAPIRegistry::getTagSeconds(const QMetaMethod& _method, const char* _type
return 0;
}

QStringList RESTAPIRegistry::registeredAPIs(const QString& _module, bool _showParams, bool _showTypes, bool _prettifyTypes) {
if (_showParams == false) {
#ifdef TARGOMAN_API_ENABLE_WEBSOCKET
QStringList Methods = RESTAPIRegistry::Registry.keys();
Methods.append(RESTAPIRegistry::WSRegistry.keys());
return Methods;
#else
return RESTAPIRegistry::Registry.keys();
#endif
}

QMap<QString, QString> Methods = RESTAPIRegistry::extractMethods(RESTAPIRegistry::Registry, _module, _showTypes, _prettifyTypes);
#ifdef TARGOMAN_API_ENABLE_WEBSOCKET
Methods.unite(RESTAPIRegistry::extractMethods(RESTAPIRegistry::WSRegistry, _module, _showTypes, _prettifyTypes));
#endif
return Methods.values();
}

void RESTAPIRegistry::dumpAPIs()
{
// TargomanInfo(5, "\n" + RESTAPIRegistry::registeredAPIs("", true, true).join("\n"));

struct stuAPIKey {
QString Method;
clsAPIObject* APIObject;

stuAPIKey() { ; }

stuAPIKey(const stuAPIKey &_other) :
Method(_other.Method),
APIObject(_other.APIObject) { ; }

stuAPIKey(QString _method, clsAPIObject* _apiObject) :
Method(_method),
APIObject(_apiObject) { ; }
};

QHash<QString, QHash<QString, stuAPIKey>> APIs;
foreach (const QString Key, RESTAPIRegistry::Registry.keys()) {

QString Name = Key.split(" ").last();
QString Method = Key.split(" ").first().toLower();
clsAPIObject* APIObject = RESTAPIRegistry::Registry.value(Key);

APIs[Name].insert(Method, stuAPIKey(Method, APIObject));
}

QStringList Keys = APIs.keys();
Keys.sort(); //Qt::CaseSensitivity::CaseInsensitive);

int index = 1;
foreach (const QString Name, Keys) {
qDebug().noquote().nospace()
<< "[" << Name << "]";

QStringList Methods = APIs[Name].keys();
Methods.sort(); //Qt::CaseSensitivity::CaseInsensitive);
foreach (const QString Method, Methods) {
stuAPIKey &API = APIs[Name][Method];

qDebug().noquote().nospace()
<< QString::number(index++).leftJustified(4) << ": "
<< Method.toUpper() << " " << Name;

if (API.APIObject->ParamTypesName.isEmpty() == false) {
int maxLen = 0;

for (int ParamsIndex = 0; ParamsIndex < API.APIObject->ParamTypesName.count(); ParamsIndex++) {
maxLen = max(maxLen, API.APIObject->ParamTypesName[ParamsIndex].length());
}

for (int ParamsIndex = 0; ParamsIndex < API.APIObject->ParamTypesName.count(); ParamsIndex++) {
QVariant DefVal = API.APIObject->BaseMethod.DefaultValues[ParamsIndex];

// bool DefValIsValid = false;
// QString DefValStr;
// qvariant.cpp#4160:
// if (DefVal.userType() != QMetaType::UnknownType) {
// dbg << QMetaType::typeName(typeId) << ", ";
// bool userStream = false;
// bool canConvertToString = false;
// if (typeId >= QMetaType::User) {
// userStream = QMetaType::debugStream(dbg, constData(v.d), typeId);
// canConvertToString = v.canConvert<QString>();
// }
// if (!userStream && canConvertToString)
// dbg << v.toString();
// else if (!userStream)
// handlerManager[typeId]->debugStream(dbg, v);
// } else {
// dbg << "Invalid";
// }

qDebug().noquote().nospace()
<< " "
<< API.APIObject->ParamTypesName[ParamsIndex].leftJustified(maxLen)
<< " "
<< API.APIObject->ParamNames[ParamsIndex]
<< " = "
<< DefVal
<< (ParamsIndex < API.APIObject->ParamTypesName.count()-1 ? "," : "")
;
}
// << " ParamTypesName: [" << API.APIObject->ParamTypesName.count() << "] " << API.APIObject->ParamTypesName.join(", ") << endl
// << " ParamNames: [" << API.APIObject->ParamNames.count() << "] " << API.APIObject->ParamNames.join(", ") << endl
// << " DefaultValues: [" << API.APIObject->BaseMethod.DefaultValues.count() << "] " << API.APIObject->BaseMethod.DefaultValues
// << (API.APIObject->BaseMethod.DefaultValues.count() != API.APIObject->ParamNames.count()
// ? " ******************** ERROR IN COUNTERS ********************"
// : "")
// ;
}

}
qDebug() << "";
}
}

/****************************************************/
Cache_t InternalCache::Cache;
QMutex InternalCache::Lock;

Expand All @@ -625,7 +724,6 @@ QHash<QString, clsAPIObject*> RESTAPIRegistry::Registry;
QHash<QString, clsAPIObject*> RESTAPIRegistry::WSRegistry;
#endif

/****************************************************/
intfCacheConnector::~intfCacheConnector() { ; }

void intfCacheConnector::setKeyVal(const QString& _key, const QVariant& _value, qint32 _ttl) {
Expand Down
6 changes: 4 additions & 2 deletions App/Server/RESTAPIRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class RESTAPIRegistry {
static void registerRESTAPI(intfPureModule* _module, const QMetaMethod& _method);
static QStringList registeredAPIs(const QString& _module, bool _showParams = false, bool _showTypes = false, bool _prettifyTypes = true);

static void dumpAPIs();

private:
static inline QString isValidType(int _typeID, bool _validate4Input);
static void validateMethodInputAndOutput(const QMetaMethod& _method);
Expand All @@ -70,10 +72,10 @@ class RESTAPIRegistry {
static QMap<QString, QString> extractMethods(QHash<QString, clsAPIObject*>& _registry, const QString& _module, bool _showTypes, bool _prettifyTypes);

private:
static QHash<QString, clsAPIObject*> Registry;
static QHash<QString, clsAPIObject*> Registry;

#ifdef TARGOMAN_API_ENABLE_WEBSOCKET
static QHash<QString, clsAPIObject*> WSRegistry;
static QHash<QString, clsAPIObject*> WSRegistry;
#endif

friend class OpenAPIGenerator;
Expand Down
3 changes: 2 additions & 1 deletion App/Server/appTargomanAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ void appTargomanAPI::slotExecute() {

OpenAPIGenerator::retrieveJson();

TargomanInfo(5, "\n" + RESTAPIRegistry::registeredAPIs("", true, true).join("\n"));
RESTAPIRegistry::dumpAPIs();

} catch (Targoman::Common::exTargomanBase& e) {
TargomanLogError(e.what());
QCoreApplication::exit(-1);
Expand Down
2 changes: 1 addition & 1 deletion App/Server/appTargomanAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class appTargomanAPI : public QObject

public:
explicit appTargomanAPI(QObject *parent = nullptr);

public slots:
void slotExecute();
};
Expand Down
4 changes: 3 additions & 1 deletion App/Server/clsAPIObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,19 @@ QVariant clsAPIObject::invoke(
if (ParamNotFound && this->ParamTypesName.at(i) == PARAM_ORMFIELDS) {
ParamNotFound = false;
TAPI::ORMFields_t ORMFields;

foreach (const QString& Arg, _args)
ORMFields.insert(Arg.mid(0,Arg.indexOf('=')), parseArgValue(Arg.mid(0,Arg.indexOf('=')), QUrl::fromPercentEncoding(Arg.mid(Arg.indexOf('=') + 1).toUtf8())));

foreach (auto BodyArg, _bodyArgs)
ORMFields.insert(BodyArg.first, parseArgValue(BodyArg.first, BodyArg.second));

ArgumentValue = ORMFields;
}

if (ParamNotFound)
foreach (const QString& Arg, _args) {
if (Arg.startsWith(this->ParamNames.at(i)+ '=')) {
if (Arg.startsWith(this->ParamNames.at(i) + '=')) {
ParamNotFound = false;
ArgumentValue = parseArgValue(this->ParamNames.at(i), QUrl::fromPercentEncoding(Arg.mid(Arg.indexOf('=') + 1).toUtf8()));
break;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Advert/functionalTest/testAdvert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ private slots:
{ "preVoucher", {} },
{ "gatewayType", "_DeveloperTest" },
{ "domain", "dev.test" },
{ "walletID", 9988 },
// { "walletID", 9988 },
{ "paymentVerifyCallback", "http://www.a.com" },
}
);
Expand Down Expand Up @@ -576,7 +576,7 @@ private slots:
{ "preVoucher", this->LastPreVoucher.toJson().toVariantMap() },
{ "gatewayType", "_DeveloperTest" },
{ "domain", "dev.test" },
{ "walletID", 9988 },
// { "walletID", 9988 },
{ "paymentVerifyCallback", "http://www.a.com" },
}
);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Advert/moduleSrc/Advert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ QVariant Advert::apiPOSTfixtureSetup(
{ "preVoucher", LastPreVoucher.toJson().toVariantMap() },
{ "gatewayType", "_DeveloperTest" },
{ "domain", "dev.test" },
{ "walletID", 9988 },
// { "walletID", 9988 },
{ "paymentVerifyCallback", "http://www.a.com" },
}
);
Expand Down