Skip to content

Commit

Permalink
Merge pull request 'send card to server imodeatly' (#550) from task_5…
Browse files Browse the repository at this point in the history
  • Loading branch information
EndrII committed Jul 13, 2022
2 parents fb112ca + f9a1998 commit b159ce1
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 67 deletions.
38 changes: 25 additions & 13 deletions src/GUI/private/mainmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,15 @@ void MainModel::initCardsListModels() {
connect(_cardsListModel, &CardsListModel::sigRemoveRequest,
this, &MainModel::handleRemoveRequest);

connect(_ownCardsListModel, &CardsListModel::sigEditFinished,
this, &MainModel::handleCardEditFinished);

connect(_cardsListModel, &CardsListModel::sigEditFinished,
this, &MainModel::saveCard);

connect(_cardsListModel, &CardsListModel::sigResetCardModel,
this, &MainModel::handleResetCardModel);

connect(_ownCardsListModel, &CardsListModel::sigEditFinished,
this, &MainModel::handleCardEditFinished);

connect(_ownCardsListModel, &CardsListModel::sigRemoveRequest,
this, &MainModel::handleRemoveRequest);

Expand All @@ -385,9 +388,6 @@ void MainModel::initCardsListModels() {
connect(_ownCardsListModel, &CardsListModel::sigCardSelectedForStatistic,
this, &MainModel::handleCardSelectedForStatistic);

connect(_cardsListModel, &CardsListModel::sigResetCardModel,
this, &MainModel::handleResetCardModel);

connect(_ownCardsListModel, &CardsListModel::sigResetCardModel,
this, &MainModel::handleResetCardModel);
}
Expand Down Expand Up @@ -779,15 +779,24 @@ void RC::MainModel::saveCard(const QSharedPointer<API::Card>& card) {
card->setCardVersion(VERSION_CARD_USER);
} else {
card->setCardVersion(card->getCardVersion() + 1);

}

_db->insertIfExistsUpdateObject(card);

// send notification about updates to server
if (!fClient) {
auto seller = _backEndModel.staticCast<Seller>();
seller->cardUpdated(card->cardId(), card->getCardVersion());
auto currentUserId = _currentUser->userId();
if (card->isOvner(currentUserId)) {

auto seller = _backEndModel.dynamicCast<Seller>();
if (!seller)
return;

auto header = _currentUser->getHelloPackage();

seller->setPurchase(header,
card->cardId(),
0);

}
}

Expand All @@ -801,7 +810,8 @@ void MainModel::handleCardEditFinished(const QSharedPointer<API::Card>& card) {
return;
}

auto listOfUsers = _backEndModel->getAllUserFromCard(card->cardId());
auto listOfUsers = _backEndModel->getAllUserFromCard(card->cardId(),
_currentUser->userId());

if (localCard && listOfUsers.size() && localCard->getFreeIndex() != card->getFreeIndex()) {

Expand Down Expand Up @@ -871,7 +881,9 @@ void MainModel::handleRemoveRequest(const QSharedPointer<API::Card> &card) {
};

if (getMode()) {
auto listOfUsers = _backEndModel->getAllActiveUserFromCard(card->cardId());
auto listOfUsers = _backEndModel->getAllActiveUserFromCard(card->cardId(),
ACTIVE_USER_TIME_LIMIT,
_currentUser->userId());

if (listOfUsers.size()) {
service->setNotify(tr("Operation not permitted"),
Expand Down Expand Up @@ -906,7 +918,7 @@ void MainModel::handleCardSelectedForWork(const QSharedPointer<CardModel> &card)
}

void MainModel::handleCardSelectedForStatistic(const QSharedPointer<CardModel> &card) {
auto usersList = _backEndModel->getAllUserFromCard(card->card()->cardId());
auto usersList = _backEndModel->getAllUserFromCard(card->card()->cardId(), _currentUser->userId());
auto usersDataList = _backEndModel->getAllUserDataFromCard(card->card()->cardId());

_statisticModel->setDataList(card, usersList, usersDataList);
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/private/usermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class UserModel: public QObject, public QuasarAppUtils::SettingsListner
Q_INVOKABLE QString userBackUpData() const;

int userId() const;
API::UserHeader getHelloPackage() const;

signals:
void objChanged();
Expand All @@ -74,7 +75,6 @@ class UserModel: public QObject, public QuasarAppUtils::SettingsListner

protected:
void setSessinon(long long newSessinon);
API::UserHeader getHelloPackage() const;
void handleSettingsChanged(const QString& key, const QVariant& value) override;

private:
Expand Down
36 changes: 28 additions & 8 deletions src/RC/CheatCard/api/apiobjectsfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ class APIObjectsFactory: public IAPIObjectsFactory
};

template<class UsersCards>
QList<QSharedPointer<API::UsersCards> > getAllUserFromCardImpl(unsigned int cardId) const {
QList<QSharedPointer<API::UsersCards> > getAllUserFromCardImpl(unsigned int cardId,
unsigned int ignoreUserId = 0) const {

check_type(UsersCards);

QString where = QString("card=%0").arg(cardId);
QString where;
if (ignoreUserId) {
where = QString("card=%0 AND user!=%1").arg(cardId).arg(ignoreUserId);
} else {
where = QString("card=%0").arg(cardId);
}

QH::PKG::DBObjectsRequest<UsersCards> request("UsersCards",
where);
Expand All @@ -89,14 +95,21 @@ class APIObjectsFactory: public IAPIObjectsFactory

template<class UsersCards>
QList<QSharedPointer<API::UsersCards> > getAllActiveUserFromCardImpl(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const {
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreUserId = 0) const {

check_type(UsersCards);

int timePoint = time(0) - unixTimeRange;

QString where = QString("card=%0 AND time>%1").
arg(cardId).arg(timePoint);
QString where;
if (ignoreUserId) {
where = QString("card=%0 AND time>%1 AND user!=%2").
arg(cardId).arg(timePoint).arg(ignoreUserId);
} else {
where = QString("card=%0 AND time>%1")
.arg(cardId).arg(timePoint);
}

QH::PKG::DBObjectsRequest<UsersCards> request("UsersCards",
where);
Expand All @@ -111,14 +124,21 @@ class APIObjectsFactory: public IAPIObjectsFactory

template<class UsersCards>
QList<QSharedPointer<API::UsersCards> > getAllPassiveUserFromCardImpl(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const {
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreUserId = 0) const {

check_type(UsersCards);

int timePoint = time(0) - unixTimeRange;

QString where = QString("card=%0 AND time<%1").
arg(cardId).arg(timePoint);
QString where;
if (ignoreUserId) {
where = QString("card=%0 AND time<%1 AND user!=%2").
arg(cardId).arg(timePoint).arg(ignoreUserId);
} else {
where = QString("card=%0 AND time<%1")
.arg(cardId).arg(timePoint);
}

QH::PKG::DBObjectsRequest<UsersCards> request("UsersCards",
where);
Expand Down
14 changes: 8 additions & 6 deletions src/RC/CheatCard/api/apiobjectsfactoryv0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ APIObjectsFactoryV0::getUserCardData(unsigned int userId, unsigned int cardId) c
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV0::getAllUserFromCard(unsigned int cardId) const {
return getAllUserFromCardImpl<API_PREFIX::UsersCards>(cardId);
APIObjectsFactoryV0::getAllUserFromCard(unsigned int cardId, unsigned int ignore) const {
return getAllUserFromCardImpl<API_PREFIX::UsersCards>(cardId, ignore);

}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV0::getAllPassiveUserFromCard(unsigned int cardId,
int unixTimeRange) const {
return getAllPassiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange);
int unixTimeRange,
unsigned int ignoreUserId) const {
return getAllPassiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange, ignoreUserId);

}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV0::getAllActiveUserFromCard(unsigned int cardId,
int unixTimeRange) const {
return getAllActiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange);
int unixTimeRange,
unsigned int ignoreUserId) const {
return getAllActiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange, ignoreUserId);
}

QList<QSharedPointer<API::User> >
Expand Down
8 changes: 5 additions & 3 deletions src/RC/CheatCard/api/apiobjectsfactoryv0.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class APIObjectsFactoryV0 : public APIObjectsFactory
QSharedPointer<API::User> getUser(unsigned int userId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserData(unsigned int userId) const override;
QSharedPointer<API::UsersCards> getUserCardData(unsigned int userId, unsigned int cardId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserFromCard(unsigned int cardId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserFromCard(unsigned int cardId, unsigned int ignore = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllPassiveUserFromCard(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override;
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreUserId = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllActiveUserFromCard(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override;
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreUserId = 0) const override;
QList<QSharedPointer<API::User> > getAllUserDataFromCard(unsigned int cardId) const override;
QList<QSharedPointer<API::User>> getAllUserWithPrivateKeys() const override;;

Expand Down
16 changes: 9 additions & 7 deletions src/RC/CheatCard/api/apiobjectsfactoryv1-5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@ APIObjectsFactoryV1_5::getUserCardData(unsigned int userId, unsigned int cardId)
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1_5::getAllUserFromCard(unsigned int cardId) const {
return getAllUserFromCardImpl<API_PREFIX::UsersCards>(cardId);
APIObjectsFactoryV1_5::getAllUserFromCard(unsigned int cardId, unsigned int ignoreuser) const {
return getAllUserFromCardImpl<API_PREFIX::UsersCards>(cardId, ignoreuser);
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1_5::getAllPassiveUserFromCard(unsigned int cardId,
int unixTimeRange) const {
return getAllPassiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange);
int unixTimeRange,
unsigned int ignoreuser) const {
return getAllPassiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange, ignoreuser);
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1_5::getAllActiveUserFromCard(unsigned int cardId,
int unixTimeRange) const {
return getAllActiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange);
int unixTimeRange,
unsigned int ignoreuser) const {
return getAllActiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange, ignoreuser);
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1_5::getAllUserCardsData(const QByteArray &userKey,
const QList<QSharedPointer<API::Contacts>> &childs) {
const QList<QSharedPointer<API::Contacts>> &childs) {


QList<QByteArray> keys;
Expand Down
9 changes: 6 additions & 3 deletions src/RC/CheatCard/api/apiobjectsfactoryv1-5.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class APIObjectsFactoryV1_5: public APIObjectsFactoryV1

QList<QSharedPointer<API::UsersCards> > getAllUserData(unsigned int userId) const override;
QSharedPointer<API::UsersCards> getUserCardData(unsigned int userId, unsigned int cardId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserFromCard(unsigned int cardId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserFromCard(unsigned int cardId,
unsigned int ignoreuser = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllPassiveUserFromCard(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override;
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreuser = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllActiveUserFromCard(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override;
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreuser = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserCardsData(const QByteArray &userKey,
const QList<QSharedPointer<API::Contacts> > &childs) override;

Expand Down
14 changes: 8 additions & 6 deletions src/RC/CheatCard/api/apiobjectsfactoryv1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@ APIObjectsFactoryV1::getUserCardData(unsigned int userId, unsigned int cardId) c
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1::getAllUserFromCard(unsigned int cardId) const {
return getAllUserFromCardImpl<API_PREFIX::UsersCards>(cardId);
APIObjectsFactoryV1::getAllUserFromCard(unsigned int cardId, unsigned int ignoreuser) const {
return getAllUserFromCardImpl<API_PREFIX::UsersCards>(cardId, ignoreuser);
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1::getAllPassiveUserFromCard(unsigned int cardId,
int unixTimeRange) const {
return getAllPassiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange);
int unixTimeRange,
unsigned int ignoreuser) const {
return getAllPassiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange, ignoreuser);
}

QList<QSharedPointer<API::UsersCards> >
APIObjectsFactoryV1::getAllActiveUserFromCard(unsigned int cardId,
int unixTimeRange) const {
return getAllActiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange);
int unixTimeRange,
unsigned int ignoreuser) const {
return getAllActiveUserFromCardImpl<API_PREFIX::UsersCards>(cardId, unixTimeRange, ignoreuser);
}

QSharedPointer<API::Card>
Expand Down
9 changes: 6 additions & 3 deletions src/RC/CheatCard/api/apiobjectsfactoryv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class APIObjectsFactoryV1: public APIObjectsFactoryV0

QList<QSharedPointer<API::UsersCards> > getAllUserData(unsigned int userId) const override;
QSharedPointer<API::UsersCards> getUserCardData(unsigned int userId, unsigned int cardId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserFromCard(unsigned int cardId) const override;
QList<QSharedPointer<API::UsersCards> > getAllUserFromCard(unsigned int cardId,
unsigned int ignoreuser = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllPassiveUserFromCard(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override;
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreuser = 0) const override;
QList<QSharedPointer<API::UsersCards> > getAllActiveUserFromCard(unsigned int cardId,
int unixTimeRange = ACTIVE_USER_TIME_LIMIT) const override;
int unixTimeRange = ACTIVE_USER_TIME_LIMIT,
unsigned int ignoreuser = 0) const override;
QSharedPointer<API::Card> getCard(unsigned int cardId) override;
QList<QSharedPointer<API::Card> > getAllUserCards(const QByteArray &userKey, bool restOf,
const QList<QSharedPointer<API::Contacts>> &childs) override;
Expand Down
4 changes: 3 additions & 1 deletion src/RC/CheatCard/api/apiv1-5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ bool ApiV1_5::processDeleteCardRequest(const QSharedPointer<APIv1_5::DeleteCardR
return false;
}

auto listOfUsers = node()->getAllActiveUserFromCard(request->card());
auto userKey = API::User::makeKey(request->secret());
auto userId = API::User::makeId(userKey);
auto listOfUsers = node()->getAllActiveUserFromCard(request->card(), ACTIVE_USER_TIME_LIMIT, userId);

if (listOfUsers.size()) {
return false;
Expand Down
9 changes: 6 additions & 3 deletions src/RC/CheatCard/api/iapiobjectsfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ class IAPIObjectsFactory
virtual QSharedPointer<API::UsersCards> getUserCardData(unsigned int userId,
unsigned int cardId) const = 0;

virtual QList<QSharedPointer<API::UsersCards>> getAllUserFromCard(unsigned int cardId) const = 0;
virtual QList<QSharedPointer<API::UsersCards>> getAllActiveUserFromCard(unsigned int cardId, int unixTimeRange) const = 0;
virtual QList<QSharedPointer<API::UsersCards>> getAllPassiveUserFromCard(unsigned int cardId, int unixTimeRange) const = 0;
virtual QList<QSharedPointer<API::UsersCards>> getAllUserFromCard(unsigned int cardId,
unsigned int ignoreUserId = 0) const = 0;
virtual QList<QSharedPointer<API::UsersCards>> getAllActiveUserFromCard(unsigned int cardId, int unixTimeRange,
unsigned int ignoreUserId = 0) const = 0;
virtual QList<QSharedPointer<API::UsersCards>> getAllPassiveUserFromCard(unsigned int cardId, int unixTimeRange,
unsigned int ignoreUserId = 0) const = 0;

virtual QList<QSharedPointer<API::User>> getAllUserDataFromCard(unsigned int cardId) const = 0;
virtual QList<QSharedPointer<API::User>> getAllUserWithPrivateKeys() const = 0;
Expand Down
14 changes: 11 additions & 3 deletions src/RC/CheatCard/dataconvertor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ DataConvertor::DataConvertor()
}

QSharedPointer<API::User> DataConvertor::toUser(const QSharedPointer<API::UserHeader> &userHeader) {

if (!userHeader)
return nullptr;

return toUser(*userHeader);
}

QSharedPointer<API::User> DataConvertor::toUser(const API::UserHeader &userHeader) {
auto result = QSharedPointer<API::User>::create();

result->setKey(userHeader->token());
result->setId(userHeader->getUserId());
result->setName(userHeader->userName());
result->setKey(userHeader.token());
result->setId(userHeader.getUserId());
result->setName(userHeader.userName());
result->setSecret("");

return result;
Expand Down
Loading

0 comments on commit b159ce1

Please sign in to comment.