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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Migration File: m20220401_200609_Ticketing_create_table_department_and_unit.sql */

CREATE TABLE `tblDepartments` (
`depID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`depName` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci',
`depCreationDateTime` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`depCreatedBy_usrID` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (`depID`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

CREATE TABLE `tblUnits` (
`untID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`unt_depID` INT(10) UNSIGNED NOT NULL,
`untName` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci',
`untCreationDateTime` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
`untCreatedBy_usrID` BIGINT(20) UNSIGNED NOT NULL,
PRIMARY KEY (`untID`) USING BTREE,
INDEX `FK_tblUnits_tblDepartments` (`unt_depID`) USING BTREE,
CONSTRAINT `FK_tblUnits_tblDepartments` FOREIGN KEY (`unt_depID`) REFERENCES `dev_Ticketing`.`tblDepartments` (`depID`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

ALTER TABLE `tblTickets`
ADD COLUMN `tkt_untID` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `tkt_svcID`;

ALTER TABLE `tblTickets`
ADD CONSTRAINT `FK_tblTickets_tblUnits` FOREIGN KEY (`tkt_untID`) REFERENCES `tblUnits` (`untID`) ON UPDATE NO ACTION ON DELETE NO ACTION;

75 changes: 75 additions & 0 deletions Modules/Ticketing/moduleSrc/ORM/Departments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/******************************************************************************
# 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 "Departments.h"
#include "Interfaces/AAA/AAA.hpp"
#include "Defs.hpp"

using namespace Targoman::API::ORM;

namespace Targoman::API::TicketingModule::ORM {

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
Departments::Departments() :
intfSQLBasedModule(
TicketingSchema,
tblDepartments::Name,
{///< ColName Type Validation Default UpBy Sort Filter Self Virt PK
{ tblDepartments::depID, ORM_PRIMARYKEY_32 },
{ tblDepartments::depName, S(QString), QFV, QRequired, UPNone },
{ tblDepartments::depCreationDateTime, ORM_CREATED_ON },
{ tblDepartments::depCreatedBy_usrID, ORM_CREATED_BY },
},
{///< Col Reference Table ForeignCol Rename LeftJoin
ORM_RELATION_OF_CREATOR(tblDepartments::depCreatedBy_usrID),
}
)
{}

QVariant Departments::apiGET(GET_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_GET, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->Select(*this, GET_METHOD_CALL_ARGS_INTERNAL_CALL);
}

quint32 Departments::apiCREATE(CREATE_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_PUT, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->Create(*this, CREATE_METHOD_CALL_ARGS_INTERNAL_CALL);
}

bool Departments::apiUPDATE(UPDATE_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_PATCH, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->Update(*this, UPDATE_METHOD_CALL_ARGS_INTERNAL_CALL);
}

bool Departments::apiDELETE(DELETE_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_DELETE, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->DeleteByPks(*this, DELETE_METHOD_CALL_ARGS_INTERNAL_CALL);
}

} //namespace Targoman::API::TicketingModule::ORM
61 changes: 61 additions & 0 deletions Modules/Ticketing/moduleSrc/ORM/Departments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/******************************************************************************
# 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_MODULES_TICKETING_ORM_DEPARTMENTS_H
#define TARGOMAN_API_MODULES_TICKETING_ORM_DEPARTMENTS_H

#include "Interfaces/API/intfSQLBasedModule.h"

namespace Targoman::API::TicketingModule {

//structures and enumes goes here

namespace ORM {

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace tblDepartments {
constexpr char Name[] = "tblDepartments";
TARGOMAN_CREATE_CONSTEXPR(depID);
TARGOMAN_CREATE_CONSTEXPR(depName);
TARGOMAN_CREATE_CONSTEXPR(depCreationDateTime);
TARGOMAN_CREATE_CONSTEXPR(depCreatedBy_usrID);
}
#pragma GCC diagnostic pop

class Departments : public intfSQLBasedModule
{
Q_OBJECT
TARGOMAN_DEFINE_API_SUBMODULE(Ticketing, Departments)

private slots:
QVariant ORMGET("Get departments")
quint32 ORMCREATE("Create a new department")
bool ORMUPDATE("Update department")
bool ORMDELETE("Delete a department")
};

} //namespace ORM
} //namespace Targoman::API::TicketingModule

#endif // TARGOMAN_API_MODULES_TICKETING_ORM_DEPARTMENTS_H
11 changes: 11 additions & 0 deletions Modules/Ticketing/moduleSrc/ORM/Tickets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "Interfaces/AAA/AAA.hpp"
#include "Defs.hpp"
//#include "Interfaces/ORM/APIQueryBuilders.h"
#include "Units.h"
#include "Departments.h"

TAPI_REGISTER_TARGOMAN_ENUM(Targoman::API::TicketingModule, enuTicketStatus);

Expand Down Expand Up @@ -72,6 +74,7 @@ Tickets::Tickets() :
{ tblTickets::tktID, ORM_PRIMARYKEY_64 },
{ tblTickets::tktTarget_usrID, S(NULLABLE_TYPE(quint64)), QFV.integer().minValue(1), QNull, UPNone },
{ tblTickets::tkt_svcID, S(NULLABLE_TYPE(quint32)), QFV.integer().minValue(1), QNull, UPNone },
{ tblTickets::tkt_untID, S(NULLABLE_TYPE(quint32)), QFV.integer().minValue(1), QNull, UPNone },
{ tblTickets::tktBase_tktID, S(NULLABLE_TYPE(quint64)), QFV.integer().minValue(1), QNull, UPNone },
{ tblTickets::tktInReply_tktID, S(NULLABLE_TYPE(quint64)), QFV.integer().minValue(1), QNull, UPNone },
{ tblTickets::tktType, S(Targoman::API::TicketingModule::enuTicketType::Type), QFV, Targoman::API::TicketingModule::enuTicketType::Message, UPNone },
Expand All @@ -86,6 +89,7 @@ Tickets::Tickets() :
{ tblTickets::tktInReply_tktID, R(TicketingSchema,tblTickets::Name), tblTickets::tktID, "InReply_" , true },
{ tblTickets::tktTarget_usrID, R(AAASchema,tblUser::Name), tblUser::usrID, "Target_" , true },
{ tblTickets::tktID, R(TicketingSchema,tblTicketRead::Name), tblTicketRead::tkr_tktID, "ReadInfo_", true },
{ tblTickets::tkt_untID, R(TicketingSchema, tblUnits::Name), tblUnits::untID },
ORM_RELATION_OF_CREATOR(tblTickets::tktCreatedBy_usrID),
ORM_RELATION_OF_UPDATER(tblTickets::tktUpdatedBy_usrID),
}
Expand Down Expand Up @@ -130,6 +134,7 @@ QVariant Tickets::apiGET(
.addCol(tblTickets::tktID)
.addCol(tblTickets::tktTarget_usrID)
.addCol(tblTickets::tkt_svcID)
.addCol(tblTickets::tkt_untID)
.addCol(tblTickets::tktBase_tktID)
.addCol(tblTickets::tktInReply_tktID)
.addCol(tblTickets::tktType)
Expand All @@ -140,6 +145,12 @@ QVariant Tickets::apiGET(
.addCol(tblTickets::tktCreatedBy_usrID)
.addCol(tblTickets::tktUpdatedBy_usrID)
.addCol(CURRENT_TIMESTAMP)

.leftJoin(tblUnits::Name)
.leftJoin(tblDepartments::Name, clsCondition(tblDepartments::Name, tblDepartments::depID, enuConditionOperator::Equal, tblUnits::Name, tblUnits::unt_depID))
.addCol(tblUnits::untName)
.addCol(tblDepartments::depID)
.addCol(tblDepartments::depName)
;

if (_inReplyTicketID > 0)
Expand Down
5 changes: 3 additions & 2 deletions Modules/Ticketing/moduleSrc/ORM/Tickets.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace tblTickets {
TARGOMAN_CREATE_CONSTEXPR(tktID);
TARGOMAN_CREATE_CONSTEXPR(tktTarget_usrID);
TARGOMAN_CREATE_CONSTEXPR(tkt_svcID);
TARGOMAN_CREATE_CONSTEXPR(tkt_untID);
TARGOMAN_CREATE_CONSTEXPR(tktBase_tktID);
TARGOMAN_CREATE_CONSTEXPR(tktInReply_tktID);
TARGOMAN_CREATE_CONSTEXPR(tktType);
Expand Down Expand Up @@ -82,8 +83,8 @@ private slots:
// GET_METHOD_ARGS_HEADER_APICALL,
TAPI::JWT_t _JWT,
TAPI::PKsByPath_t _pksByPath = {},
quint64 _offset = 0,
quint16 _limit = 10,
quint64 _pageIndex = 0,
quint16 _pageSize = 20,
// TAPI::Cols_t _cols = {},
// TAPI::Filter_t _filters = {},
TAPI::OrderBy_t _orderBy = {},
Expand Down
78 changes: 78 additions & 0 deletions Modules/Ticketing/moduleSrc/ORM/Units.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/******************************************************************************
# 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 "Units.h"
#include "Interfaces/AAA/AAA.hpp"
#include "Defs.hpp"
#include "Departments.h"

using namespace Targoman::API::ORM;

namespace Targoman::API::TicketingModule::ORM {

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
Units::Units() :
intfSQLBasedModule(
TicketingSchema,
tblUnits::Name,
{///< ColName Type Validation Default UpBy Sort Filter Self Virt PK
{ tblUnits::untID, ORM_PRIMARYKEY_32 },
{ tblUnits::unt_depID, S(quint32), QFV.integer().minValue(1), QRequired, UPNone },
{ tblUnits::untName, S(QString), QFV, QRequired, UPNone },
{ tblUnits::untCreationDateTime, ORM_CREATED_ON },
{ tblUnits::untCreatedBy_usrID, ORM_CREATED_BY },
},
{///< Col Reference Table ForeignCol Rename LeftJoin
{ tblUnits::unt_depID, R(TicketingSchema, tblDepartments::Name), tblDepartments::depID },
ORM_RELATION_OF_CREATOR(tblUnits::untCreatedBy_usrID),
}
)
{}

QVariant Units::apiGET(GET_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_GET, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->Select(*this, GET_METHOD_CALL_ARGS_INTERNAL_CALL);
}

quint32 Units::apiCREATE(CREATE_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_PUT, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->Create(*this, CREATE_METHOD_CALL_ARGS_INTERNAL_CALL);
}

bool Units::apiUPDATE(UPDATE_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_PATCH, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->Update(*this, UPDATE_METHOD_CALL_ARGS_INTERNAL_CALL);
}

bool Units::apiDELETE(DELETE_METHOD_ARGS_IMPL_APICALL)
{
Authorization::checkPriv(_JWT, this->privOn(EHTTP_DELETE, this->moduleBaseName()));
return /*Targoman::API::Query::*/this->DeleteByPks(*this, DELETE_METHOD_CALL_ARGS_INTERNAL_CALL);
}

} //namespace Targoman::API::TicketingModule::ORM
62 changes: 62 additions & 0 deletions Modules/Ticketing/moduleSrc/ORM/Units.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/******************************************************************************
# 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_MODULES_TICKETING_ORM_UNITS_H
#define TARGOMAN_API_MODULES_TICKETING_ORM_UNITS_H

#include "Interfaces/API/intfSQLBasedModule.h"

namespace Targoman::API::TicketingModule {

//structures and enumes goes here

namespace ORM {

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace tblUnits {
constexpr char Name[] = "tblUnits";
TARGOMAN_CREATE_CONSTEXPR(untID);
TARGOMAN_CREATE_CONSTEXPR(unt_depID);
TARGOMAN_CREATE_CONSTEXPR(untName);
TARGOMAN_CREATE_CONSTEXPR(untCreationDateTime);
TARGOMAN_CREATE_CONSTEXPR(untCreatedBy_usrID);
}
#pragma GCC diagnostic pop

class Units : public intfSQLBasedModule
{
Q_OBJECT
TARGOMAN_DEFINE_API_SUBMODULE(Ticketing, Units)

private slots:
QVariant ORMGET("Get units")
quint32 ORMCREATE("Create a new unit")
bool ORMUPDATE("Update unit")
bool ORMDELETE("Delete a unit")
};

} //namespace ORM
} //namespace Targoman::API::TicketingModule

#endif // TARGOMAN_API_MODULES_TICKETING_ORM_UNITS_H
Loading