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 @@ -36,6 +36,7 @@ out
*.autosave
*~
.migrations
.dbdiff*

# Qt
Makefile*
Expand Down
6 changes: 5 additions & 1 deletion App/Server/RESTAPIRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ void RESTAPIRegistry::dumpAPIs()
<< (IsLastAPI ? " " : "│") << " "
<< (IsLastMethod ? "└" : "├") << "──"
<< "(" << QString::number(MethodsIndex++) << ") "
<< Method.toUpper(); // << " " << Name;
<< Method.toUpper() // << " " << Name
<< (API.APIObject->requiresJWT() ? " (JWT)" : "")
;

if (API.APIObject->ParamTypesName.isEmpty() == false) {
int maxLen = 0;
Expand Down Expand Up @@ -726,6 +728,8 @@ void RESTAPIRegistry::dumpAPIs()
<< API.APIObject->ParamNames[ParamsIndex]
<< " = "
<< DefVal
<< " [" << (DefVal.isNull() ? "Null" : "Not Null") << "]"
<< " [" << (DefVal.isValid() ? "Valid" : "Invalid") << "]"
<< (ParamsIndex < API.APIObject->ParamTypesName.count()-1 ? "," : "")
;
}
Expand Down
1 change: 1 addition & 0 deletions Modules/Account/functionalTest/testAccount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ private slots:
{ "password", "123" },
})
},
{ "pgw_curID", 1 },
{ "pgwAllowedDomainName", "dev.test" },
});
// qDebug() << Result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/* Migration File: m20220525_170624_AAA_dbdiffof_dev_AAA.sql */
/* CAUTION: don't forget to use {{dbprefix}} for schemas */

USE `{{dbprefix}}{{Schema}}`;

/************************************************************\
| binlog.000078 --start-position=24048 |
\************************************************************/

CREATE TABLE `tblCurrency` (
`curID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`curName` VARCHAR(128) NOT NULL,
`curSymbol` VARCHAR(32) NOT NULL,
`curRate` FLOAT UNSIGNED NULL,
`curStatus` CHAR(1) NOT NULL DEFAULT 'A' COMMENT 'A:Active, D:Deactive, R:Removed',
`_InvalidatedAt` INT NULL,
`curCreationDateTime` DATETIME NULL,
`curCreatedBy_usrID` BIGINT UNSIGNED NULL DEFAULT NULL,
`curUpdatedBy_usrID` BIGINT UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`curID`)
)
COLLATE='utf8mb4_general_ci'
/*!*/;

ALTER TABLE `tblCurrency`
CHANGE COLUMN `_InvalidatedAt` `_InvalidatedAt` INT(10) UNSIGNED NULL DEFAULT 0 AFTER `curStatus`,
CHANGE COLUMN `curCreationDateTime` `curCreationDateTime` DATETIME NULL DEFAULT CURRENT_TIMESTAMP AFTER `_InvalidatedAt`
/*!*/;

ALTER TABLE `tblCurrency`
CHANGE COLUMN `curCreatedBy_usrID` `curCreatedBy_usrID` BIGINT(20) UNSIGNED NOT NULL AFTER `curCreationDateTime`,
CHANGE COLUMN `curUpdatedBy_usrID` `curUpdatedBy_usrID` BIGINT(20) UNSIGNED NOT NULL AFTER `curCreatedBy_usrID`
/*!*/;

ALTER TABLE `tblCurrency`
ADD CONSTRAINT `FK_tblCurrency_tblUser` FOREIGN KEY (`curCreatedBy_usrID`) REFERENCES `tblUser` (`usrID`) ON UPDATE NO ACTION ON DELETE NO ACTION,
ADD CONSTRAINT `FK_tblCurrency_tblUser_2` FOREIGN KEY (`curUpdatedBy_usrID`) REFERENCES `tblUser` (`usrID`) ON UPDATE NO ACTION ON DELETE NO ACTION
/*!*/;

ALTER TABLE `tblCurrency`
ADD COLUMN `curIsDefault` BIT NOT NULL AFTER `curRate`
/*!*/;

ALTER TABLE `tblCurrency`
CHANGE COLUMN `curRate` `curRate` FLOAT UNSIGNED NULL DEFAULT NULL AFTER `curSymbol`,
CHANGE COLUMN `curIsDefault` `curIsDefault` BIT(1) NOT NULL DEFAULT 0 AFTER `curRate`,
CHANGE COLUMN `curCreatedBy_usrID` `curCreatedBy_usrID` BIGINT(20) UNSIGNED NULL AFTER `curCreationDateTime`,
CHANGE COLUMN `curUpdatedBy_usrID` `curUpdatedBy_usrID` BIGINT(20) UNSIGNED NULL AFTER `curCreatedBy_usrID`
/*!*/;

DROP PROCEDURE IF EXISTS `spCurrency_SetAsDefault`
/*!*/;

DELIMITER ;;

CREATE PROCEDURE `spCurrency_SetAsDefault`(
IN `iUserID` BIGINT UNSIGNED,
IN `iCurID` INT UNSIGNED
)
BEGIN
DECLARE vErr VARCHAR(500);
DECLARE vCurIsDefault INT;

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1 vErr = MESSAGE_TEXT;

INSERT INTO tblActionLogs
SET tblActionLogs.atlBy_usrID = iUserID,
tblActionLogs.atlType = 'spCurrency_SetAsDefault.Error',
tblActionLogs.atlDescription = JSON_OBJECT(
"err", vErr,
"iUserID", iUserID,
"iCurID", iCurID
)
;

-- ROLLBACK;
RESIGNAL;
END;

SELECT tblCurrency.curIsDefault
INTO vCurIsDefault
FROM tblCurrency
WHERE tblCurrency.curID = iCurID
;

IF ISNULL(vCurIsDefault) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = '401:Currency not found';
END IF;

IF (vCurIsDefault = 1) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = '401:Currency already is default';
END IF;

UPDATE tblCurrency
SET tblCurrency.curIsDefault = 1
, tblCurrency.curUpdatedBy_usrID = iUserID
WHERE tblCurrency.curID = iCurID
;

END
/*!*/;;

DELIMITER ;

ALTER TABLE `tblCurrency`
CHANGE COLUMN `curRate` `curRate` FLOAT UNSIGNED NOT NULL AFTER `curSymbol`
/*!*/;

INSERT INTO tblCurrency(`curID`, `curName`, `curSymbol`, `curRate`, `curIsDefault`) VALUES
(1, 'ریال ایران', 'IRR', 1.0, 1),
(2, 'تومان ایران', 'IRT', 0.1, 0)
;

ALTER TABLE `tblCurrency`
ADD INDEX `curStatus__InvalidatedAt` (`curStatus`, `_InvalidatedAt`)
/*!*/;

ALTER TABLE `tblCurrency`
ADD INDEX `curIsDefault` (`curIsDefault`)
/*!*/;

ALTER TABLE `tblPaymentGateways`
ADD COLUMN `pgw_curID` INT UNSIGNED NULL DEFAULT NULL AFTER `pgwMetaInfo`
/*!*/;

ALTER TABLE `tblPaymentGateways`
ADD CONSTRAINT `FK_tblPaymentGateways_tblCurrency` FOREIGN KEY (`pgw_curID`) REFERENCES `tblCurrency` (`curID`) ON UPDATE NO ACTION ON DELETE NO ACTION
/*!*/;

UPDATE `tblPaymentGateways`
SET `pgw_curID` = 1
WHERE `pgw_curID` IS NULL
;

ALTER TABLE `tblPaymentGateways`
CHANGE COLUMN `pgw_curID` `pgw_curID` INT(10) UNSIGNED NOT NULL AFTER `pgwMetaInfo`;
/*!*/;
4 changes: 4 additions & 0 deletions Modules/Account/moduleSrc/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "ORM/UserWallets.h"
#include "ORM/WalletTransactions.h"
#include "ORM/Auth.h"
#include "ORM/Currency.h"
#include "Payment/PaymentLogic.h"
#include "Payment/intfPaymentGateway.h"
//#include "Interfaces/ORM/APIQueryBuilders.h"
Expand Down Expand Up @@ -163,6 +164,7 @@ Account::Account() :
this->addSubModule(&WalletTransactions::instance());
this->addSubModule(&WalletsBalanceHistory::instance());
this->addSubModule(&Auth::instance());
this->addSubModule(&Currency::instance());

if (Account::InvalidPasswordsFile.value().size()) {
QFile InputFile(Account::InvalidPasswordsFile.value());
Expand Down Expand Up @@ -1693,6 +1695,7 @@ QVariant IMPL_REST_POST(Account, fixtureSetup, (
{ "password", "123" },
})
},
{ tblPaymentGateways::pgw_curID, 1 },
{ tblPaymentGateways::pgwAllowedDomainName, "dev.test" },
};
quint32 PaymentGatewayID = CreateQuery(ORM::PaymentGateways::instance())
Expand All @@ -1702,6 +1705,7 @@ QVariant IMPL_REST_POST(Account, fixtureSetup, (
tblPaymentGateways::pgwType,
tblPaymentGateways::pgwDriver,
tblPaymentGateways::pgwMetaInfo,
tblPaymentGateways::pgw_curID,
tblPaymentGateways::pgwAllowedDomainName,
// tblPaymentGateways::pgwTransactionFeeValue,
// tblPaymentGateways::pgwTransactionFeeType,
Expand Down
82 changes: 82 additions & 0 deletions Modules/Account/moduleSrc/ORM/Currency.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#include "Currency.h"
//#include "User.h"

TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::AccountModule, enuCurrencyStatus);

namespace Targoman::API::AccountModule::ORM {

Currency::Currency() :
intfSQLBasedModule(
AAASchema,
tblCurrency::Name,
tblCurrency::Private::ORMFields,
tblCurrency::Private::Relations,
tblCurrency::Private::Indexes
) { ; }

QVariant IMPL_ANONYMOUSE_ORMGET(Currency) {
return this->Select(*this, GET_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

quint64 IMPL_ORMCREATE(Currency) {
Authorization::checkPriv(_APICALLBOOM.getJWT(), this->privOn(EHTTP_DELETE, this->moduleBaseName()));

return this->Create(*this, CREATE_METHOD_ARGS_CALL_INTERNAL_BOOM2USER);
}

bool IMPL_ORMUPDATE(Currency) {
Authorization::checkPriv(_APICALLBOOM.getJWT(), this->privOn(EHTTP_PATCH, this->moduleBaseName()));

return this->Update(*this, UPDATE_METHOD_ARGS_CALL_INTERNAL_BOOM2USER);
}

bool IMPL_ORMDELETE(Currency) {
Authorization::checkPriv(_APICALLBOOM.getJWT(), this->privOn(EHTTP_DELETE, this->moduleBaseName()));

return this->DeleteByPks(*this, DELETE_METHOD_ARGS_CALL_INTERNAL_BOOM2USER);
}

/**
* @callby:
* operator
* owner
*/
bool IMPL_REST_UPDATE(Currency, setAsDefault, (
APICALLBOOM_TYPE_JWT_IMPL &APICALLBOOM_PARAM,
quint32 _curID
)) {
Authorization::checkPriv(_APICALLBOOM.getJWT(), { this->moduleBaseName() + ":canChangeDefault" });

this->callSP("spCurrency_SetAsDefault",
{
{ "iUserID", _APICALLBOOM.getUserID() },
{ "iCurID", _curID },
});

return true;
}

} //namespace Targoman::API::AccountModule::ORM
Loading