8 #ifndef UPDATEEMAILREQUEST_H
9 #define UPDATEEMAILREQUEST_H
46 QJsonObject
execute(
const QJsonObject& jsonObj, QMutex& m)
override
48 QMutexLocker locker(&m);
58 response.insert(
"Response", 12);
61 if (jsonObj.contains(
"Data"))
63 QJsonObject dataObj = jsonObj[
"Data"].toObject();
65 if (dataObj.contains(
"email"))
67 email = dataObj.value(
"email").toString();
70 if (dataObj.contains(
"password"))
72 password = dataObj.value(
"password").toString();
75 if (dataObj.contains(
"new_email"))
77 new_email = dataObj.value(
"new_email").toString();
82 qCritical() <<
"Data not found";
94 int user_id = result.
first().value(
"id").toInt();
103 if (result.
first().value(
"password").toString() != password)
117 bool success = dbManager->
where(
"email = ", email)->
update(
"users", {{
"email", new_email}});
124 data.insert(
"status",
int(
true));
125 data.insert(
"message",
"Email updated successfully");
127 response.insert(
"Data", data);
132 QJsonDocument responseDoc(response);
133 QByteArray responseData = responseDoc.toJson();
136 qDebug().noquote() <<
"<-- UpdateEmail::Response :\n" << responseDoc.toJson(QJsonDocument::Indented);
This file contains the declaration of the Request class, which is an abstract base class for handling...
Manages database connections and SQL operations.
Definition: db.h:80
bool update(const QString &table, const QVariantMap &data)
Updates data in a specified table.
Definition: db.cpp:361
DatabaseManager * table(const QString &value)
Sets the table for the query.
Definition: db.cpp:115
DatabaseManager * where(const QString &value, const QVariant &val=QVariant())
Adds a WHERE clause to the query.
Definition: db.cpp:121
DbResult exec()
Executes the built query.
Definition: db.cpp:266
DatabaseManager * select(const QString &value)
Selects columns for the query.
Definition: db.cpp:107
The DbResult class represents a result set returned from a database query.
Definition: dbresult.h:24
QJsonObject first() const
Retrieves the first item in the result set.
Definition: dbresult.cpp:25
bool isEmpty() const
Checks if the result set is empty.
Definition: dbresult.cpp:20
The Request class is an abstract base class for handling different types of requests.
Definition: Request.h:25
QJsonObject CreateErrorResponse(QJsonObject &response, QJsonObject &dataObj, QString message)
Creates a generic error JSON response.
Definition: Request.h:90
QJsonObject CreateDBConnectionError(QJsonObject &response, QJsonObject &dataObj)
Creates a JSON response indicating a database connection error.
Definition: Request.h:65
bool isDBConnectionValid(DB::DatabaseManager *dbManager)
Checks if the database connection is valid.
Definition: Request.h:36
The UpdateEmailRequest class handles email update requests for users.
Definition: UpdateEmailRequest.h:21
QJsonObject execute(const QJsonObject &jsonObj, QMutex &m) override
Executes the email update request.
Definition: UpdateEmailRequest.h:46
UpdateEmailRequest()
Constructor for the UpdateEmailRequest class.
Definition: UpdateEmailRequest.h:31
Database management classes for handling database connections and operations.