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
2 changes: 2 additions & 0 deletions Interfaces/Interfaces.pro
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ PRIVATE_HEADERS += \

HEADERS += \
Helpers/IteratorHelper.hpp \
ORM/intfFAQ.h \
ORM/intfMigrations.h \
Server/APICallBoom.h \
Server/ServerCommon.h \
Expand Down Expand Up @@ -77,6 +78,7 @@ HEADERS += \
ObjectStorage/ObjectStorageManager.h

SOURCES += \
ORM/intfFAQ.cpp \
ORM/intfMigrations.cpp \
Server/APICallBoom.cpp \
Server/ServerCommon.cpp \
Expand Down
101 changes: 101 additions & 0 deletions Interfaces/ORM/intfFAQ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/******************************************************************************
# 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 "intfFAQ.h"
#include "Interfaces/AAA/Authorization.h"
#include "Interfaces/AAA/AAADefs.hpp"
#include "Interfaces/AAA/clsJWT.hpp"

using namespace Targoman::API::AAA;

namespace Targoman::API::ORM {

/*********************************************************\
|** intfFaqQuestions *************************************|
\*********************************************************/
intfFaqQuestions::intfFaqQuestions(
const QString& _module,
const QString& _schema
) :
intfSQLBasedModule(
_module,
_schema,
tblFaqQuestions::Name,
tblFaqQuestions::Private::ORMFields,
tblFaqQuestions::Private::Relations(_schema),
tblFaqQuestions::Private::Indexes
) { ; }

QVariant IMPL_ANONYMOUSE_ORMGET(intfFaqQuestions) {
return this->Select(GET_METHOD_ARGS_CALL_INTERNAL_BOOM);
}
quint32 IMPL_ORMCREATE(intfFaqQuestions) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_PUT, this->moduleBaseName()));
return this->Create(CREATE_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

bool IMPL_ORMUPDATE(intfFaqQuestions) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_PATCH, this->moduleBaseName()));
return this->Update(UPDATE_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

bool IMPL_ORMDELETE(intfFaqQuestions) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_DELETE, this->moduleBaseName()));
return this->DeleteByPks(DELETE_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

/*********************************************************\
|** intfFaqAnswers ***************************************|
\*********************************************************/
intfFaqAnswers::intfFaqAnswers(
const QString& _module,
const QString& _schema
) :
intfSQLBasedModule(
_module,
_schema,
tblFaqAnswers::Name,
tblFaqAnswers::Private::ORMFields,
tblFaqAnswers::Private::Relations(_schema),
tblFaqAnswers::Private::Indexes
) { ; }

QVariant IMPL_ANONYMOUSE_ORMGET(intfFaqAnswers) {
return this->Select(GET_METHOD_ARGS_CALL_INTERNAL_BOOM);
}
quint32 IMPL_ORMCREATE(intfFaqAnswers) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_PUT, this->moduleBaseName()));
return this->Create(CREATE_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

bool IMPL_ORMUPDATE(intfFaqAnswers) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_PATCH, this->moduleBaseName()));
return this->Update(UPDATE_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

bool IMPL_ORMDELETE(intfFaqAnswers) {
Authorization::checkPriv(APICALLBOOM_PARAM, this->privOn(EHTTP_DELETE, this->moduleBaseName()));
return this->DeleteByPks(DELETE_METHOD_ARGS_CALL_INTERNAL_BOOM);
}

} //namespace Targoman::API::ORM
197 changes: 197 additions & 0 deletions Interfaces/ORM/intfFAQ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/******************************************************************************
# 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>
*/

#ifndef TARGOMAN_API_FAQ_H
#define TARGOMAN_API_FAQ_H

#include "Interfaces/API/intfSQLBasedModule.h"

namespace Targoman::API::ORM {

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"

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

namespace Fields {
TARGOMAN_CREATE_CONSTEXPR(qsnID);
TARGOMAN_CREATE_CONSTEXPR(qsnBody);
}

namespace Relation {
// constexpr char AAA[] = "aaa";
}

namespace Private {
const QList<clsORMField> ORMFields = {
//ColName Type Validation Default UpBy Sort Filter Self Virt PK
{ Fields::qsnID, ORM_PRIMARYKEY_32 },
{ Fields::qsnBody, S(QString), QFV, QRequired, UPAdmin },

};

inline const QList<stuRelation> Relations(Q_DECL_UNUSED const QString& _schema) {
return {
//Col Reference Table ForeignCol
};
};

const QList<stuDBIndex> Indexes = {
};

} //namespace Private

TAPI_DEFINE_STRUCT(DTO,
SF_quint16 (qsnID),
SF_QString (qsnBody)
);
}

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

namespace Fields {
TARGOMAN_CREATE_CONSTEXPR(ansID);
TARGOMAN_CREATE_CONSTEXPR(ans_qsnID);
TARGOMAN_CREATE_CONSTEXPR(ansBody);
}

namespace Relation {
constexpr char Question[] = "question";
}

namespace Private {
const QList<clsORMField> ORMFields = {
//ColName Type Validation Default UpBy Sort Filter Self Virt PK
{ Fields::ansID, ORM_PRIMARYKEY_32 },
{ Fields::ans_qsnID, S(quint16), QFV, QRequired, UPAdmin },
{ Fields::ansBody, S(QString), QFV, QRequired, UPAdmin },
};

inline const QList<stuRelation> Relations(Q_DECL_UNUSED const QString& _schema) {
return {
//Col Reference Table ForeignCol
{ Relation::Question,
{ Fields::ans_qsnID, R(_schema, tblFaqQuestions::Name), tblFaqQuestions::Fields::qsnID } },
};
};

const QList<stuDBIndex> Indexes = {
};

} //namespace Private

TAPI_DEFINE_STRUCT(DTO,
SF_quint16 (ansID),
SF_quint16 (ans_qsnID),
SF_QString (ansBody)
);
}

#pragma GCC diagnostic pop

class intfFaqQuestions : public intfSQLBasedModule
{
Q_OBJECT

public:
intfFaqQuestions(
const QString& _module,
const QString& _schema
);

private slots:
QVariant ANONYMOUSE_ORMGET("Get Faq Questions")
quint32 ORMCREATE("Create a new Faq Question")
bool ORMUPDATE("Update Faq Question")
bool ORMDELETE("Delete a Faq Question")
};

class intfFaqAnswers : public intfSQLBasedModule
{
Q_OBJECT

public:
intfFaqAnswers(
const QString& _module,
const QString& _schema
);

private slots:
QVariant ANONYMOUSE_ORMGET("Get Faq Answers")
quint32 ORMCREATE("Create a new Faq Answer")
bool ORMUPDATE("Update Faq Answer")
bool ORMDELETE("Delete a Faq Answer")
};

} //namespace Targoman::API::ORM

/****************************************************/
//put this macro before module class definition (.h)
#define TARGOMAN_FAQ_PREPARENT \
class FaqQuestions; \
class FaqAnswers;

//put this macro after module class definition (.h)
#define TARGOMAN_FAQ_POSTPARENT(_module, _schema) \
class FaqQuestions : public Targoman::API::ORM::intfFaqQuestions \
{ \
Q_OBJECT \
TARGOMAN_DEFINE_API_SUBMODULE_WO_CTOR(_module, FaqQuestions) \
public: \
FaqQuestions() : \
intfFaqQuestions( \
Targoman::Common::demangle(typeid(_module).name()).split("::").last(), \
_schema \
) \
{ ; } \
}; \
class FaqAnswers : public Targoman::API::ORM::intfFaqAnswers \
{ \
Q_OBJECT \
TARGOMAN_DEFINE_API_SUBMODULE_WO_CTOR(_module, FaqAnswers) \
public: \
FaqAnswers() : \
intfFaqAnswers( \
Targoman::Common::demangle(typeid(_module).name()).split("::").last(), \
_schema \
) \
{ ; } \
};

//put this macro inside module class definition (.h) after TARGOMAN_DEFINE_API_MODULE
#define TARGOMAN_API_DEFINE_FAQ(_module, _schema) \
protected: \
QScopedPointer<FaqQuestions> _FaqQuestions; \
QScopedPointer<FaqAnswers> _FaqAnswers;

//put this macro into module class constructor (.cpp)
#define TARGOMAN_API_IMPLEMENT_FAQ(_module, _schema) \
this->_FaqQuestions.reset(&FaqQuestions::instance()); \
this->_FaqAnswers.reset(&FaqAnswers::instance()); \
this->addSubModule(this->_FaqQuestions.data()); \
this->addSubModule(this->_FaqAnswers.data());

/****************************************************/
#endif // TARGOMAN_API_FAQ_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Migration File: m20220725_093105_Interfaces_FAQ_init_schema.sql */
/* CAUTION: don't forget to use {{dbprefix}} for schemas */

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

CREATE TABLE `tblFaqQuestions` (
`qsnID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`qsnBody` TEXT NOT NULL COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`qsnID`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `tblFaqAnswers` (
`ansID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`ans_qsnID` INT(10) UNSIGNED NOT NULL,
`ansBody` TEXT NOT NULL COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`ansID`) USING BTREE,
INDEX `FK_tblFaqAnswers_tblFaqQuestions` (`ans_qsnID`) USING BTREE,
CONSTRAINT `FK_tblFaqAnswers_tblFaqQuestions` FOREIGN KEY (`ans_qsnID`) REFERENCES `tblFaqQuestions` (`qsnID`) ON UPDATE NO ACTION ON DELETE CASCADE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;
1 change: 1 addition & 0 deletions Modules/Account/moduleSrc/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Account::Account() :
TARGOMAN_API_IMPLEMENT_MIGRATIONS(Account, AAASchema)
TARGOMAN_API_IMPLEMENT_ACTIONLOG(Account, AAASchema)
TARGOMAN_API_IMPLEMENT_OBJECTSTORAGE(Account, AAASchema)
TARGOMAN_API_IMPLEMENT_FAQ(Account, AAASchema)

this->addSubModule(&ActiveSessions::instance());
this->addSubModule(&APITokens::instance());
Expand Down
4 changes: 4 additions & 0 deletions Modules/Account/moduleSrc/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "ORM/Voucher.h"
#include "Classes/Defs.hpp"
#include "Payment/PaymentLogic.h"
#include "Interfaces/ORM/intfFAQ.h"

namespace Targoman::API::AccountModule {

Expand All @@ -45,6 +46,7 @@ namespace Targoman::API::AccountModule {
TARGOMAN_MIGRATIONS_PREPARENT;
TARGOMAN_ACTIONLOG_PREPARENT;
TARGOMAN_OBJECTSTORAGE_PREPARENT;
TARGOMAN_FAQ_PREPARENT;

class Account : public intfSQLBasedWithActionLogsModule
{
Expand All @@ -56,6 +58,7 @@ class Account : public intfSQLBasedWithActionLogsModule
TARGOMAN_API_DEFINE_MIGRATIONS(Account, AAASchema);
TARGOMAN_API_DEFINE_ACTIONLOG(Account, AAASchema);
TARGOMAN_API_DEFINE_OBJECTSTORAGE(Account, AAASchema);
TARGOMAN_API_DEFINE_FAQ(Account, AAASchema);

public:
static Targoman::Common::Configuration::tmplConfigurable<FilePath_t> InvalidPasswordsFile;
Expand Down Expand Up @@ -526,6 +529,7 @@ private slots:
TARGOMAN_MIGRATIONS_POSTPARENT(Account, AAASchema);
TARGOMAN_ACTIONLOG_POSTPARENT(Account, AAASchema);
TARGOMAN_OBJECTSTORAGE_POSTPARENT(Account, AAASchema);
TARGOMAN_FAQ_POSTPARENT(Account, AAASchema);

} //namespace Targoman::API::AccountModule

Expand Down
1 change: 1 addition & 0 deletions Modules/Advert/moduleSrc/Advert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Advert::Advert() :
TARGOMAN_API_IMPLEMENT_MIGRATIONS(Advert, AdvertSchema)
TARGOMAN_API_IMPLEMENT_ACTIONLOG(Advert, AdvertSchema)
TARGOMAN_API_IMPLEMENT_OBJECTSTORAGE(Advert, AdvertSchema)
TARGOMAN_API_IMPLEMENT_FAQ(Advert, AdvertSchema)

this->addSubModule(AccountUnits.data());
// this->addSubModule(AccountUnitsTranslate.data());
Expand Down
Loading