Clicking the sendInvite button triggers a post request to the server to send a bidding invite via mail.
This commit is contained in:
@ -178,6 +178,12 @@ void GenericCore::onOnlineUserAccountReceived(const QString mailAddress,
|
||||
const QString message = QString("Online credentials received for: %1").arg(mailAddress);
|
||||
emit displayStatusMessage(message);
|
||||
}
|
||||
|
||||
void GenericCore::onSendInviteMailTriggered(const QString& mailAddress) {
|
||||
qInfo() << "Sending invite mail to:" << mailAddress;
|
||||
const QString serverUrl = m_serverCommunicator->getUserLoginUrl();
|
||||
const QJsonDocument mailInviteJsonDoc = m_mainModel->getMailInviteJsonDoc(mailAddress, serverUrl);
|
||||
emit sendPostRequest(MailInvite, mailInviteJsonDoc.toJson());
|
||||
}
|
||||
|
||||
void GenericCore::setupModels() {
|
||||
|
||||
@ -53,6 +53,7 @@ class GenericCore : public QObject {
|
||||
void onOnlineUserAccountReceived(const QString mailAddress,
|
||||
const QString uuid,
|
||||
const QString accessToken);
|
||||
void onSendInviteMailTriggered(const QString& mailAddress);
|
||||
|
||||
signals:
|
||||
void displayStatusMessage(QString message);
|
||||
|
||||
@ -91,7 +91,7 @@ enum GetRequestTypes {
|
||||
GetBiddingsOfSpecificRound,
|
||||
GetBiddingsOfHighestRound
|
||||
};
|
||||
enum PostRequestTypes { RegisterUser };
|
||||
enum PostRequestTypes { RegisterUser, MailInvite };
|
||||
|
||||
/// functions
|
||||
static UserRoles GET_ROLE_FOR_COLUMN(const int column) {
|
||||
|
||||
@ -239,6 +239,34 @@ void TableModel::setOnlineCredentials(const QString& mail,
|
||||
setItemData(itemIndex, {{OnlineIdRole, uuid}, {AccessCodeRole, token}});
|
||||
}
|
||||
|
||||
QJsonDocument TableModel::getMailInviteJsonDoc(const QString& mail,
|
||||
const QString& serverUrl) const {
|
||||
QJsonDocument doc = QJsonDocument();
|
||||
|
||||
QModelIndex index = getIndexByRoleValue(mail, MailRole);
|
||||
|
||||
if (index.isValid()) {
|
||||
QJsonObject rootObject;
|
||||
|
||||
const QString user_id = data(index, OnlineIdRole).toString();
|
||||
const QString email = data(index, MailRole).toString();
|
||||
const QString name = data(index, FullNameRole).toString();
|
||||
const QString token = data(index, AccessCodeRole).toString();
|
||||
const QString accessUrl = serverUrl + "/" + token;
|
||||
|
||||
QJsonObject userObject;
|
||||
userObject.insert("user_id", user_id);
|
||||
userObject.insert("email", email);
|
||||
userObject.insert("name", name);
|
||||
userObject.insert("access_url", accessUrl);
|
||||
|
||||
rootObject.insert("user", userObject);
|
||||
|
||||
doc.setObject(rootObject);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
void TableModel::updateBiddings(const QList<bidding> biddings) {
|
||||
QListIterator<bidding> i(biddings);
|
||||
while (i.hasNext()) {
|
||||
@ -352,6 +380,7 @@ qreal TableModel::biddingAverage2() const {
|
||||
qInfo() << "average calculation (2):" << averageBidding;
|
||||
return averageBidding;
|
||||
}
|
||||
|
||||
qreal TableModel::biddingAverage3() const {
|
||||
const UserRoles biddingRole = Bidding3Role;
|
||||
const qreal averageBidding = averageBiddingAmount(biddingRole);
|
||||
|
||||
@ -46,6 +46,8 @@ class TableModel : public QAbstractTableModel {
|
||||
bool updateItem(const ModelItemValues& itemValues);
|
||||
|
||||
void setOnlineCredentials(const QString& mail, const QString& uuid, const QString& token);
|
||||
QJsonDocument getMailInviteJsonDoc(const QString& mail, const QString& serverUrl) const;
|
||||
|
||||
void updateBiddings(const QList<bidding> biddings);
|
||||
|
||||
public slots:
|
||||
@ -111,6 +113,7 @@ class TableModel : public QAbstractTableModel {
|
||||
qreal totalSharesWithBiddings(const UserRoles biddingRole) const;
|
||||
|
||||
QModelIndex getIndexByRoleValue(const QString& valueString, const int role) const;
|
||||
QMap<int, QVariant> getItemValues(const bidding bid);
|
||||
};
|
||||
|
||||
#endif // TABLEMODEL_H
|
||||
|
||||
@ -5,11 +5,14 @@
|
||||
|
||||
// TODO add namespace
|
||||
|
||||
static const QString ROUTE_LOG_IN = "/log_in";
|
||||
|
||||
static const QString apiPrefix = "/api/";
|
||||
|
||||
static const QString ROUTE_ITEMS = apiPrefix + "items";
|
||||
|
||||
static const QString ROUTE_REGISTER_USER = apiPrefix + "users";
|
||||
static const QString ROUTE_MAIL_INVITE = apiPrefix + "invite";
|
||||
|
||||
static const QString ROUTE_BIDDINGROUNDS = apiPrefix + "bidding_rounds";
|
||||
static const QString ROUTE_CURRENT_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/get_current";
|
||||
|
||||
@ -58,6 +58,11 @@ void ServerCommunicator::setServerConfiguration(const QString url,
|
||||
m_password = password;
|
||||
}
|
||||
|
||||
QString ServerCommunicator::getUserLoginUrl() const {
|
||||
const QString logInUrl = m_serviceApi->baseUrl().toString() + ROUTE_LOG_IN;
|
||||
return logInUrl;
|
||||
}
|
||||
|
||||
void ServerCommunicator::onSendGetRequestTriggered(const GetRequestTypes type,
|
||||
QVariant data = QVariant()) {
|
||||
QString path;
|
||||
@ -143,6 +148,9 @@ void ServerCommunicator::onSendPostRequestTriggered(const PostRequestTypes type,
|
||||
case RegisterUser:
|
||||
path = ROUTE_REGISTER_USER;
|
||||
break;
|
||||
case MailInvite:
|
||||
path = ROUTE_MAIL_INVITE;
|
||||
break;
|
||||
default:
|
||||
qWarning() << "No route found for PostRequestType:" << type;
|
||||
break;
|
||||
@ -184,6 +192,10 @@ void ServerCommunicator::onPostReplySuccessful(const PostRequestTypes type,
|
||||
qInfo() << "Register user successful:" << type;
|
||||
onlineUserAccountReply(doc);
|
||||
break;
|
||||
case MailInvite:
|
||||
qInfo() << "Mail invite successful sent:" << type;
|
||||
mailInviteSentReply(doc);
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Can't match request type:" << type;
|
||||
break;
|
||||
@ -228,3 +240,8 @@ void ServerCommunicator::onlineUserAccountReply(const QJsonDocument jsonDoc) {
|
||||
emit onlineUserAccountReceived(values[MailRole].toString(), values[OnlineIdRole].toString(),
|
||||
values[AccessCodeRole].toString());
|
||||
}
|
||||
|
||||
void ServerCommunicator::mailInviteSentReply(const QJsonDocument jsonDoc) {
|
||||
qInfo() << "Invitation mail successfully sent.";
|
||||
emit m_core->displayStatusMessage("Invitation mail successfully sent.");
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ class ServerCommunicator : public QObject {
|
||||
void setUrl(const QUrl& url);
|
||||
|
||||
void setServerConfiguration(const QString url, const QString email, const QString password);
|
||||
QString getUserLoginUrl() const;
|
||||
|
||||
public slots:
|
||||
void onSendGetRequestTriggered(const GetRequestTypes type, QVariant data);
|
||||
@ -64,6 +65,7 @@ class ServerCommunicator : public QObject {
|
||||
void currentBiddingRoundChangedReply(const QJsonDocument jsonDoc);
|
||||
void currentBiddingsReply(const QJsonDocument jsonDoc);
|
||||
void onlineUserAccountReply(const QJsonDocument jsonDoc);
|
||||
void mailInviteSentReply(const QJsonDocument jsonDoc);
|
||||
};
|
||||
|
||||
#endif // SERVERCOMMUNICATOR_H
|
||||
|
||||
Reference in New Issue
Block a user