-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/LawPlusThree/QSyncUi
- Loading branch information
Showing
11 changed files
with
81 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
#include "apirequest.h" | ||
|
||
QByteArray ApiRequest::get(const QString &path) { | ||
ApiResponse ApiRequest::get(const QString &path) { | ||
QNetworkRequest request(QUrl(baseUrl + path)); | ||
QNetworkReply* reply = manager->get(request); | ||
QEventLoop loop; | ||
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
if (reply->error() == QNetworkReply::NoError) { | ||
if (reply->error() == QNetworkReply::NoError||reply->error()>=401) { | ||
QByteArray responseData = reply->readAll(); | ||
response=response->processJson(responseData); | ||
ApiResponse response(responseData); | ||
return response; | ||
} else { | ||
qDebug() << "Error:" << reply->errorString(); | ||
QString jsonString = R"({"code": 666, "message": "ApiRequest error!", "data": "Nooo!"})"; | ||
QByteArray jsonData = jsonString.toUtf8(); | ||
QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||
QJsonObject jsonObject = document.object(); | ||
ApiResponse errorResponse(666,"ApiRequest error!",jsonObject); | ||
return errorResponse; | ||
} | ||
return 0; | ||
} | ||
|
||
QByteArray ApiRequest::post(const QString &path, const QByteArray &data) { | ||
ApiResponse ApiRequest::post(const QString &path, const QByteArray &data) { | ||
QNetworkRequest request(QUrl(baseUrl + path)); | ||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | ||
QNetworkReply* reply = manager->post(request, data); | ||
QEventLoop loop; | ||
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); | ||
loop.exec(); | ||
if (reply->error() == QNetworkReply::NoError) { | ||
if (reply->error() == QNetworkReply::NoError||reply->error()>=401) { | ||
QByteArray responseData = reply->readAll(); | ||
response=response->processJson(responseData); | ||
qDebug() << "response code:" << response->getCode(); | ||
ApiResponse response(responseData); | ||
return response; | ||
} else { | ||
qDebug() << "Error:" << reply->errorString(); | ||
QString jsonString = R"({"code": 666, "message": "ApiRequest error!", "data": "Nooo!"})"; | ||
QByteArray jsonData = jsonString.toUtf8(); | ||
QJsonDocument document = QJsonDocument::fromJson(jsonData); | ||
QJsonObject jsonObject = document.object(); | ||
ApiResponse errorResponse(666,"ApiRequest error!",jsonObject); | ||
return errorResponse; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#define SIGNIN_H | ||
|
||
#include <QWidget> | ||
#include "user.h" | ||
|
||
namespace Ui { | ||
class signin; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters