Skip to content

Commit 929ad94

Browse files
authored
Merge pull request #256 from Targoman/mtcharts
create coalesce part of query in languageHelper
2 parents 0234360 + a6ad3d6 commit 929ad94

File tree

7 files changed

+130
-23
lines changed

7 files changed

+130
-23
lines changed

Interfaces/AAA/Accounting_Interfaces.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "Interfaces/AAA/Authorization.h"
2828
#include "Interfaces/Common/QtTypes.hpp"
2929
#include "Interfaces/Helpers/TokenHelper.h"
30+
#include "Interfaces/Helpers/LanguageHelper.h"
3031

3132
using namespace Targoman::API;
3233
using namespace Targoman::API::AAA;
@@ -186,11 +187,10 @@ ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBO
186187
})
187188
.leftJoin(tblAccountUnitsI18NBase::Name)
188189
.addCol(DBExpression::VALUE(QString("COALESCE("
189-
"JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.untName.\"%2\"')),"
190+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountUnitsI18NBase::Name, "untName") + ","
190191
"JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.untName.default')),"
191-
"%3.untName)")
192+
"%2.untName)")
192193
.arg(tblAccountUnitsI18NBase::Name)
193-
.arg(APICALLBOOM_PARAM.language())
194194
.arg(_alias.isEmpty() ? tblAccountUnitsBase::Name : _alias)
195195
),
196196
tblAccountUnitsBase::Fields::untName
@@ -296,16 +296,16 @@ ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICAL
296296
tblAccountProductsBase::Fields::prdDesc,
297297
})
298298
.leftJoin(tblAccountProductsI18NBase::Name)
299-
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.prdName.\"%2\"')), %3.prdName)")
300-
.arg(tblAccountProductsI18NBase::Name)
301-
.arg(APICALLBOOM_PARAM.language())
299+
.addCol(DBExpression::VALUE(QString("COALESCE("
300+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountProductsI18NBase::Name, "prdName") + ","
301+
"%1.prdName)")
302302
.arg(_alias.isEmpty() ? tblAccountProductsBase::Name : _alias)
303303
),
304304
tblAccountProductsBase::Fields::prdName
305305
)
306-
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.prdDesc.\"%2\"')), %3.prdDesc)")
307-
.arg(tblAccountProductsI18NBase::Name)
308-
.arg(APICALLBOOM_PARAM.language())
306+
.addCol(DBExpression::VALUE(QString("COALESCE("
307+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountProductsI18NBase::Name, "prdDesc") + ","
308+
"%1.prdDesc)")
309309
.arg(_alias.isEmpty() ? tblAccountProductsBase::Name : _alias)
310310
),
311311
tblAccountProductsBase::Fields::prdDesc
@@ -405,16 +405,16 @@ ORMSelectQuery intfAccountSaleables::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICA
405405
tblAccountSaleablesBase::Fields::slbDesc,
406406
})
407407
.leftJoin(tblAccountSaleablesI18NBase::Name)
408-
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.slbName.\"%2\"')), %3.slbName)")
409-
.arg(tblAccountSaleablesI18NBase::Name)
410-
.arg(APICALLBOOM_PARAM.language())
408+
.addCol(DBExpression::VALUE(QString("COALESCE("
409+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountSaleablesI18NBase::Name, "slbName") + ","
410+
"%1.slbName)")
411411
.arg(_alias.isEmpty() ? tblAccountSaleablesBase::Name : _alias)
412412
),
413413
tblAccountSaleablesBase::Fields::slbName
414414
)
415-
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.slbDesc.\"%2\"')), %3.slbDesc)")
416-
.arg(tblAccountSaleablesI18NBase::Name)
417-
.arg(APICALLBOOM_PARAM.language())
415+
.addCol(DBExpression::VALUE(QString("COALESCE("
416+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountSaleablesI18NBase::Name, "slbDesc") + ","
417+
"%1.slbDesc)")
418418
.arg(_alias.isEmpty() ? tblAccountSaleablesBase::Name : _alias)
419419
),
420420
tblAccountSaleablesBase::Fields::slbDesc

Interfaces/Helpers/LanguageHelper.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/******************************************************************************
2+
# TargomanAPI: REST API for Targoman
3+
#
4+
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
5+
#
6+
# TargomanAPI is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# TargomanAPI is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
15+
#
16+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
17+
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
18+
******************************************************************************/
19+
/**
20+
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
21+
* @author Kambiz Zandi <kambizzandi@gmail.com>
22+
*/
23+
24+
#include "LanguageHelper.h"
25+
26+
namespace Targoman::API::Helpers {
27+
28+
QString LanguageHelper::getI18NClauseForCoalesce(
29+
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
30+
const QString &_i18nTableName,
31+
const QString &_fieldName,
32+
const QString &_i18nDataFieldName
33+
) {
34+
QString FieldPath = "$";
35+
if (_fieldName.isEmpty() == false)
36+
FieldPath += "." + _fieldName;
37+
38+
QString Result = QString("JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '%3.\"%4\"'))")
39+
.arg(_i18nTableName)
40+
.arg(_i18nDataFieldName)
41+
.arg(FieldPath)
42+
.arg(APICALLBOOM_PARAM.language())
43+
;
44+
45+
if (APICALLBOOM_PARAM.language().contains("-"))
46+
Result += ","
47+
+ QString("JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '%3.%4'))")
48+
.arg(_i18nTableName)
49+
.arg(_i18nDataFieldName)
50+
.arg(FieldPath)
51+
.arg(APICALLBOOM_PARAM.language().split("-").first());
52+
53+
return Result;
54+
}
55+
56+
} //namespace Targoman::API::Helpers

Interfaces/Helpers/LanguageHelper.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/******************************************************************************
2+
# TargomanAPI: REST API for Targoman
3+
#
4+
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
5+
#
6+
# TargomanAPI is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# TargomanAPI is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
15+
#
16+
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
17+
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
18+
******************************************************************************/
19+
/**
20+
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
21+
* @author Kambiz Zandi <kambizzandi@gmail.com>
22+
*/
23+
24+
#ifndef TARGOMAN_API_LANGUAGEHELPER_H
25+
#define TARGOMAN_API_LANGUAGEHELPER_H
26+
27+
#include <QString>
28+
#include "../Server/APICallBoom.h"
29+
30+
namespace Targoman::API::Helpers {
31+
32+
using namespace Server;
33+
34+
class LanguageHelper
35+
{
36+
public:
37+
static QString getI18NClauseForCoalesce(
38+
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
39+
const QString &_i18nTableName,
40+
const QString &_fieldName,
41+
const QString &_i18nDataFieldName = "i18nData");
42+
};
43+
44+
} //namespace Targoman::API::Helpers
45+
46+
#endif // TARGOMAN_API_LANGUAGEHELPER_H

Interfaces/Interfaces.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ HEADERS += \
4545
API/intfModuleHelper.h \
4646
Helpers/IteratorHelper.hpp \
4747
Helpers/JSonHelper.h \
48+
Helpers/LanguageHelper.h \
4849
Helpers/TokenHelper.h \
4950
ORM/intfFAQ.h \
5051
ORM/intfMigrations.h \
@@ -86,6 +87,7 @@ HEADERS += \
8687
SOURCES += \
8788
API/intfModuleHelper.cpp \
8889
Helpers/JSonHelper.cpp \
90+
Helpers/LanguageHelper.cpp \
8991
Helpers/TokenHelper.cpp \
9092
ORM/intfFAQ.cpp \
9193
ORM/intfMigrations.cpp \

Interfaces/ORM/intfI18N.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
#include "Interfaces/AAA/Authorization.h"
2626
#include "Interfaces/AAA/AAADefs.hpp"
2727
#include "Interfaces/AAA/clsJWT.hpp"
28+
#include "Interfaces/Helpers/LanguageHelper.h"
2829

2930
using namespace Targoman::API::AAA;
3031

3132
namespace Targoman::API::ORM {
3233

34+
using namespace Helpers;
35+
3336
intfI18N::intfI18N(
3437
const QString &_module,
3538
const QString &_schema
@@ -50,12 +53,11 @@ QString intfI18N::translated(
5053
auto Data = this->makeSelectQuery(APICALLBOOM_PARAM)
5154
.addCol(tblI18N::Fields::i18nKey)
5255
.addCol(DBExpression::VALUE(QString("COALESCE("
53-
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.\"%3\"')),"
56+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblI18N::Name, "", tblI18N::Fields::i18nValue) + ","
5457
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.default')),"
55-
"'%4')")
58+
"'%3')")
5659
.arg(tblI18N::Name)
5760
.arg(tblI18N::Fields::i18nValue)
58-
.arg(APICALLBOOM_PARAM.language())
5961
.arg(_key)
6062
),
6163
"Translated")

ModuleHelpers/MT/Interfaces/intfMTCharts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "Interfaces/Helpers/TokenHelper.h"
3030
#include "intfMTAccounting.h"
3131
#include "intfMTModule.h"
32+
#include "Interfaces/Helpers/LanguageHelper.h"
3233

3334
using namespace Targoman::API;
3435
using namespace Targoman::API::AAA;
@@ -765,12 +766,11 @@ std::tuple<CreditUsageRemained_t, QMap<QString, QString>> baseintfMTCharts::getU
765766
auto I18NSelectQuery = I18N->makeSelectQuery(APICALLBOOM_PARAM)
766767
.addCol(tblI18N::Fields::i18nKey)
767768
.addCol(DBExpression::VALUE(QString("COALESCE("
768-
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.\"%3\"')),"
769+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblI18N::Name, "", tblI18N::Fields::i18nValue) + ","
769770
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.default'))"
770771
")")
771772
.arg(tblI18N::Name)
772773
.arg(tblI18N::Fields::i18nValue)
773-
.arg(APICALLBOOM_PARAM.language())
774774
),
775775
"Translated")
776776

Modules/Account/moduleSrc/ORM/PaymentGateways.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../Account.h"
2626
#include "Payment/PaymentLogic.h"
2727
#include "Interfaces/Helpers/URLHelper.h"
28+
#include "Interfaces/Helpers/LanguageHelper.h"
2829

2930
using namespace Targoman::API::AccountModule::Payment;
3031
using namespace Targoman::API::Helpers;
@@ -79,9 +80,9 @@ ORMSelectQuery PaymentGatewayTypes::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICAL
7980
Query
8081
.removeCol(tblPaymentGatewayTypes::Fields::pgtName)
8182
.leftJoin(tblPaymentGatewayTypesI18N::Name)
82-
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.pgtName.\"%2\"')), %3.pgtName)")
83-
.arg(tblPaymentGatewayTypesI18N::Name)
84-
.arg(APICALLBOOM_PARAM.language())
83+
.addCol(DBExpression::VALUE(QString("COALESCE("
84+
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblPaymentGatewayTypesI18N::Name, "pgtName") + ","
85+
"%1.pgtName)")
8586
.arg(_alias.isEmpty() ? tblPaymentGatewayTypes::Name : _alias)
8687
),
8788
tblPaymentGatewayTypes::Fields::pgtName

0 commit comments

Comments
 (0)