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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ out
exportToOffice.sh

/temp
*.log

25 changes: 20 additions & 5 deletions App/Server/RESTAPIRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

#include <QMap>
#include <QMutex>
#include <QTextStream>

#include "RESTAPIRegistry.h"
#include "APICache.hpp"

#include "Interfaces/DBM/clsORMField.h"
#include "Interfaces/Helpers/RESTClientHelper.h"

namespace Targoman::API {

Expand Down Expand Up @@ -647,19 +649,29 @@ void RESTAPIRegistry::dumpAPIs()
QStringList Keys = APIs.keys();
Keys.sort(); //Qt::CaseSensitivity::CaseInsensitive);

qDebug().noquote().nospace() << endl << Targoman::API::Helpers::ClientConfigs::RESTServerAddress.value();

int index = 1;
foreach (const QString Name, Keys) {
bool IsLastAPI = (Name == Keys.last());

qDebug().noquote().nospace()
<< "[" << Name << "]";
<< "│" << endl
<< (IsLastAPI ? "└" : "├") << "── "
<< Name;

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

bool IsLastMethod = (Method == Methods.last());

qDebug().noquote().nospace()
<< QString::number(index++).leftJustified(4) << ": "
<< Method.toUpper() << " " << Name;
<< (IsLastAPI ? " " : "│") << " "
<< (IsLastMethod ? "└" : "├") << "── "
<< QString::number(index++) << ") "
<< Method.toUpper(); // << " " << Name;

if (API.APIObject->ParamTypesName.isEmpty() == false) {
int maxLen = 0;
Expand Down Expand Up @@ -690,8 +702,12 @@ void RESTAPIRegistry::dumpAPIs()
// dbg << "Invalid";
// }

bool IsLastParam = (ParamsIndex == API.APIObject->ParamTypesName.count()-1);

qDebug().noquote().nospace()
<< " "
<< (IsLastAPI ? " " : "│") << " "
<< (IsLastMethod ? " " : "│") << " "
<< (IsLastParam ? "└" : "├") << "── "
<< API.APIObject->ParamTypesName[ParamsIndex].leftJustified(maxLen)
<< " "
<< API.APIObject->ParamNames[ParamsIndex]
Expand All @@ -710,7 +726,6 @@ void RESTAPIRegistry::dumpAPIs()
}

}
qDebug() << "";
}
}

Expand Down
8 changes: 5 additions & 3 deletions App/Server/RESTServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ QStringList RESTServer::registeredAPIs(bool _showParams, bool _showTypes, bool _
return RESTAPIRegistry::registeredAPIs("", _showParams, _showTypes, _prettifyTypes);
}

/*
void RESTServer::registerUserDefinedType(const char* _typeName, intfAPIArgManipulator* _argManipulator) {
// TargomanInfo(9, "registering User Defined Type: (" << _typeName << ")");

Q_ASSERT_X(QMetaType::type(_typeName), QString("registerUserDefinedType typeName(%1)").arg(_typeName).toStdString().c_str(), "Seems that registering syntax is erroneous");

gUserDefinedTypesInfo.insert(QMetaType::type(_typeName) - TAPI_BASE_USER_DEFINED_TYPEID, _argManipulator);
}
*/

bool RESTServer::validateConnection(const QHostAddress& _peerAddress, quint16 _peerPort) {
enuIPBlackListStatus::Type IPBlackListStatus = enuIPBlackListStatus::Unknown;
Expand All @@ -210,8 +212,8 @@ RESTServer::RESTServer() :
} //namespace Server

/***********************************************************************************************/
void registerUserDefinedType(const char* _typeName, intfAPIArgManipulator* _argManipulator) {
Server::RESTServer::instance().registerUserDefinedType(_typeName, _argManipulator);
}
//void registerUserDefinedType(const char* _typeName, intfAPIArgManipulator* _argManipulator) {
// Server::RESTServer::instance().registerUserDefinedType(_typeName, _argManipulator);
//}

} //namespace Targoman::API
2 changes: 1 addition & 1 deletion App/Server/RESTServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RESTServer : public QObject
* @return a list of all APIs registered in the server
*/
QStringList registeredAPIs(bool _showParams = true, bool _showTypes = true, bool _prettifyTypes = true);
void registerUserDefinedType(const char* _typeName, Common::intfAPIArgManipulator* _argManipulator);
// void registerUserDefinedType(const char* _typeName, Common::intfAPIArgManipulator* _argManipulator);

private:
bool validateConnection(const QHostAddress& _peerAddress, quint16 _peerPort);
Expand Down
2 changes: 0 additions & 2 deletions App/Server/ServerConfigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ struct ServerConfigs
};
};

constexpr quint16 TAPI_BASE_USER_DEFINED_TYPEID = QMetaType::User + 3;

extern TAPI::stuStatistics gServerStats;

} //namespace Targoman::API::Server
Expand Down
4 changes: 4 additions & 0 deletions App/Server/appTargomanAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libTargomanCommon/Configuration/ConfigManager.h"

#include "Interfaces/API/intfPureModule.h"
#include "Interfaces/Helpers/SecurityHelper.h"
//#include "Interfaces/NLP/FormalityChecker.h"
//#include "Interfaces/NLP/TextProcessor.hpp"

Expand All @@ -54,6 +55,9 @@ appTargomanAPI::appTargomanAPI(QObject *parent) : QObject(parent) { ; }

void appTargomanAPI::slotExecute() {
try {
ServerCommonConfigs::InstanceID.setFromVariant(QString("TAPI-%1").arg(Helpers::SecurityHelper::UUIDtoMD5()));
TargomanDebug(0, "Instance-ID: " << ServerCommonConfigs::InstanceID.value())

QMap<QString, intfPureModule::stuDBInfo> RequiredDBs;

auto RegisterModule = [&RequiredDBs](intfPureModule *_module) -> bool {
Expand Down
21 changes: 0 additions & 21 deletions App/Server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,6 @@ using namespace Targoman::Common;
using namespace Targoman::API::Server;

int main(int _argc, char *_argv[]) {
/*
static const QVariant QNull = QVariant(QVariant::Line);
static const QVariant QInvalid = QVariant(QVariant::Invalid);
static const QVariant QRequired = QVariant(QVariant::RectF);
static const QVariant QAuto = QVariant(QVariant::PointF);

#define compare(_type) \
qDebug()<<#_type<<" == QNull :" <<(_type == QNull); \
qDebug()<<#_type<<" == QInvalid :" <<(_type == QInvalid); \
qDebug()<<#_type<<" == QRequired :" <<(_type == QRequired); \
qDebug()<<#_type<<" == QAuto :" <<(_type == QAuto); \
qDebug()<<#_type<<".isValid():"<<_type.isValid(); \
qDebug()<<"===========================";

compare(QNull);
compare(QInvalid);
compare(QRequired);
compare(QAuto);

exit(0);*/

try {
QCoreApplication App(_argc, _argv);

Expand Down
1 change: 1 addition & 0 deletions Interfaces/AAA/AAADefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ TARGOMAN_CREATE_CONSTEXPR(usrID);

namespace tblUser {
constexpr char Name[] = "tblUser";

namespace Relation {
constexpr char ExtraInfo[] = "extrainfo";
}
Expand Down
9 changes: 6 additions & 3 deletions Interfaces/AAA/Accounting_Defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ TARGOMAN_DEFINE_ENUM(enuDiscountType,
Percent = '%',
Currency = '$',
);
} //namespace Targoman::API::AAA

TAPI_DECLARE_METATYPE_ENUM(Targoman::API::AAA, enuVoucherStatus) // -> TAPI_REGISTER_TARGOMAN_ENUM() in Accounting_Interfaces.cpp
TAPI_DECLARE_METATYPE_ENUM(Targoman::API::AAA, enuDiscountType) // -> TAPI_REGISTER_TARGOMAN_ENUM() in Accounting_Interfaces.cpp

namespace Targoman::API::AAA {

//inline QString makeConfig(const QString& _name) { return "/zModule_Account/" + _name; }
inline QString makeConfig(const QString& _name) { return "/Module_Account/" + _name; }
Expand Down Expand Up @@ -385,7 +391,4 @@ TAPI_DECLARE_METATYPE(Targoman::API::AAA::OrderAdditives_t) // -> TAPI_REG

TAPI_DECLARE_METATYPE(Targoman::API::AAA::stuVoucherItemForTrustedAction) // -> TAPI_REGISTER_METATYPE() in Accounting_Interfaces.cpp

TAPI_DECLARE_METATYPE_ENUM(Targoman::API::AAA, enuVoucherStatus) // -> TAPI_REGISTER_TARGOMAN_ENUM() in Accounting_Interfaces.cpp
TAPI_DECLARE_METATYPE_ENUM(Targoman::API::AAA, enuDiscountType) // -> TAPI_REGISTER_TARGOMAN_ENUM() in Accounting_Interfaces.cpp

#endif // TARGOMAN_API_AAA_ACCOUNTING_DEFS_H
6 changes: 3 additions & 3 deletions Interfaces/AAA/Accounting_Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TAPI_REGISTER_METATYPE(
// qDebug() << "stuVoucherItem(1) ================================= round:" << _value.Round;
return _value.toJson().toVariantMap();
},
/* fromVariantLambda */ [](const QVariant& _value, const QByteArray& _paramName) -> stuVoucherItem {
/* fromVariantLambda */ [](const QVariant& _value, Q_DECL_UNUSED const QString& _paramName = "") -> stuVoucherItem {
// qDebug() << "stuVoucherItem(2) =================================" << _paramName << ":" << _value;
if (_value.isValid() == false) {
// qDebug() << "stuVoucherItem(2.1) =================================" << _paramName << ":" << _value;
Expand Down Expand Up @@ -81,7 +81,7 @@ TAPI_REGISTER_METATYPE(
/* namespace */ Targoman::API::AAA,
/* type */ stuPreVoucher,
/* toVariantLambda */ [](const stuPreVoucher& _value) -> QVariant { return _value.toJson().toVariantMap(); },
/* fromVariantLambda */ [](const QVariant& _value, const QByteArray& _paramName) -> stuPreVoucher {
/* fromVariantLambda */ [](const QVariant& _value, Q_DECL_UNUSED const QString& _paramName = "") -> stuPreVoucher {
if (_value.isValid() == false) {
return stuPreVoucher();
}
Expand Down Expand Up @@ -122,7 +122,7 @@ TAPI_REGISTER_METATYPE(
/* namespace */ Targoman::API::AAA,
/* type */ stuVoucherItemForTrustedAction,
/* toVariantLambda */ [](const stuVoucherItemForTrustedAction& _value) -> QVariant { return _value.toJson().toVariantMap(); },
/* fromVariantLambda */ [](const QVariant& _value, const QByteArray& _paramName) -> stuVoucherItemForTrustedAction {
/* fromVariantLambda */ [](const QVariant& _value, Q_DECL_UNUSED const QString& _paramName = "") -> stuVoucherItemForTrustedAction {
// qDebug() << "stuVoucherItemForTrustedAction(2) =================================" << _paramName << ":" << _value;
if (_value.isValid() == false) {
// qDebug() << "stuVoucherItemForTrustedAction(2.1) =================================" << _paramName << ":" << _value;
Expand Down
8 changes: 5 additions & 3 deletions Interfaces/AAA/Authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ QString renewExpiredJWT(
/*OUT*/ bool &_isRenewed
) {
clsJWT JWT(_JWTPayload);
QString SessionKey = JWT.session();
QStringList Services = JWT.privatePart().value("svc").toString().split(',', QString::SkipEmptyParts);

makeAAADAC(DAC);
QString SessionKey = JWT.session().trimmed();
if (SessionKey.isEmpty())
throw exHTTPUnauthorized("Session key not provided in jwt");

//check session
QString Qry = R"(
Expand All @@ -94,6 +94,7 @@ QString renewExpiredJWT(
ON tblUser.usrID = tblActiveSessions.ssn_usrID
WHERE ssnKey=?
)";
makeAAADAC(DAC);
QJsonDocument Result = DAC.execQuery({}, Qry, { SessionKey }).toJson(true);

if (Result.object().isEmpty())
Expand Down Expand Up @@ -138,6 +139,7 @@ QString renewExpiredJWT(
}

//-- else: renew -----
QStringList Services = JWT.privatePart().value("svc").toString().split(',', QString::SkipEmptyParts);
_isRenewed = true;
quint32 Duration = JWT.expireAt() - JWT.issuedAt();
QJsonObject UserInfo = DAC.callSP({},
Expand Down
53 changes: 32 additions & 21 deletions Interfaces/AAA/intfAccountingBasedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,10 @@ Targoman::API::AAA::stuPreVoucher intfAccountingBasedModule::apiPOSTaddToBasket(
}))

.leftJoin(SelectQuery(*this->AccountUserAssets)
.addCol(tblAccountUserAssetsBase::uas_cpnID)
.addCol(tblAccountUserAssetsBase::uas_vchID)
.addCols({
tblAccountUserAssetsBase::uas_cpnID,
tblAccountUserAssetsBase::uas_vchID,
})
.addCol(enuAggregation::COUNT, tblAccountUserAssetsBase::uasID, "_discountUsedCount")
.where({ tblAccountUserAssetsBase::uas_usrID, enuConditionOperator::Equal, CurrentUserID })
.andWhere({ tblAccountUserAssetsBase::uasStatus, enuConditionOperator::In, QString("'%1','%2'")
Expand Down Expand Up @@ -687,14 +689,16 @@ Targoman::API::AAA::stuPreVoucher intfAccountingBasedModule::apiPOSTaddToBasket(
//PreVoucherItem.Sign

CreateQuery qry = CreateQuery(*this->AccountUserAssets)
.addCol(tblAccountUserAssetsBase::uas_usrID)
.addCol(tblAccountUserAssetsBase::uas_slbID)
.addCol(tblAccountUserAssetsBase::uasQty)
// .addCol(tblAccountUserAssetsBase::uas_vchID)
.addCol(tblAccountUserAssetsBase::uasVoucherItemUUID)
// .addCol(tblAccountUserAssetsBase::uasPrefered)
// .addCol(tblAccountUserAssetsBase::uasOrderDateTime)
// .addCol(tblAccountUserAssetsBase::uasStatus)
.addCols({
tblAccountUserAssetsBase::uas_usrID,
tblAccountUserAssetsBase::uas_slbID,
tblAccountUserAssetsBase::uasQty,
// tblAccountUserAssetsBase::uas_vchID,
tblAccountUserAssetsBase::uasVoucherItemUUID,
// tblAccountUserAssetsBase::uasPrefered,
// tblAccountUserAssetsBase::uasOrderDateTime,
// tblAccountUserAssetsBase::uasStatus,
})
;

QVariantMap values;
Expand All @@ -710,9 +714,10 @@ Targoman::API::AAA::stuPreVoucher intfAccountingBasedModule::apiPOSTaddToBasket(
};

if (Discount3.ID > 0) {
qry
.addCol(tblAccountUserAssetsBase::uas_cpnID)
.addCol(tblAccountUserAssetsBase::uasDiscountAmount)
qry.addCols({
tblAccountUserAssetsBase::uas_cpnID,
tblAccountUserAssetsBase::uasDiscountAmount,
})
;

values.insert(tblAccountUserAssetsBase::uas_cpnID, Discount3.ID);
Expand Down Expand Up @@ -845,9 +850,11 @@ Targoman::API::AAA::stuPreVoucher intfAccountingBasedModule::apiPOSTupdateBasket

//check uasStatus
QVariantMap UserAssetInfo = SelectQuery(*this->AccountUserAssets)
.addCol(tblAccountUserAssetsBase::uasID)
.addCol(tblAccountUserAssetsBase::uas_slbID)
.addCol(tblAccountUserAssetsBase::uasStatus)
.addCols({
tblAccountUserAssetsBase::uasID,
tblAccountUserAssetsBase::uas_slbID,
tblAccountUserAssetsBase::uasStatus,
})
.where({ tblAccountUserAssetsBase::uasVoucherItemUUID, enuConditionOperator::Equal, PreVoucherItem.UUID })
.one();
TAPI::enuAuditableStatus::Type UserAssetStatus = TAPI::enuAuditableStatus::toEnum(UserAssetInfo.value(tblAccountUserAssetsBase::uasStatus, TAPI::enuAuditableStatus::Pending).toString());
Expand Down Expand Up @@ -877,8 +884,10 @@ Targoman::API::AAA::stuPreVoucher intfAccountingBasedModule::apiPOSTupdateBasket
UpdateQuery(*this->AccountUserAssets)
.set(tblAccountUserAssetsBase::
tblAccountUserAssetsBase::uasID)
.addCol(tblAccountUserAssetsBase::uas_slbID)
.addCol(tblAccountUserAssetsBase::uasStatus)
.addCols({
tblAccountUserAssetsBase::uas_slbID,
tblAccountUserAssetsBase::uasStatus,
})
.where({ tblAccountUserAssetsBase::uasID, enuConditionOperator::Equal, PreVoucherItem.OrderID })
.one();

Expand Down Expand Up @@ -1012,9 +1021,11 @@ bool intfAccountingBasedModule::cancelVoucherItem(
return false;

QVariantMap UserAssetInfo = SelectQuery(*this->AccountUserAssets)
.addCol(tblAccountUserAssetsBase::uasID)
.addCol(tblAccountUserAssetsBase::uas_slbID)
.addCol(tblAccountUserAssetsBase::uasStatus)
.addCols({
tblAccountUserAssetsBase::uasID,
tblAccountUserAssetsBase::uas_slbID,
tblAccountUserAssetsBase::uasStatus,
})
.where({ tblAccountUserAssetsBase::uasID, enuConditionOperator::Equal, _voucherItem.OrderID })
.one();

Expand Down
Loading