File indexing completed on 2024-12-22 04:45:27

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "teamremoveroomjob.h"
0008 #include "restapimethod.h"
0009 #include "rocketchatqtrestapi_debug.h"
0010 
0011 #include <QJsonDocument>
0012 #include <QJsonObject>
0013 #include <QNetworkReply>
0014 using namespace RocketChatRestApi;
0015 TeamRemoveRoomJob::TeamRemoveRoomJob(QObject *parent)
0016     : RestApiAbstractJob(parent)
0017 {
0018 }
0019 
0020 TeamRemoveRoomJob::~TeamRemoveRoomJob() = default;
0021 
0022 bool TeamRemoveRoomJob::start()
0023 {
0024     if (!canStart()) {
0025         deleteLater();
0026         return false;
0027     }
0028     addStartRestApiInfo("TeamRemoveRoomJob::start");
0029     submitPostRequest(json());
0030 
0031     return true;
0032 }
0033 
0034 void TeamRemoveRoomJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson)
0035 {
0036     const QJsonObject replyObject = replyJson.object();
0037 
0038     if (replyObject[QLatin1String("success")].toBool()) {
0039         addLoggerInfo(QByteArrayLiteral("TeamRemoveRoomJob success: ") + replyJson.toJson(QJsonDocument::Indented));
0040         Q_EMIT removeTeamRoomDone();
0041     } else {
0042         emitFailedMessage(replyErrorString, replyObject);
0043         addLoggerWarning(QByteArrayLiteral("TeamRemoveRoomJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented));
0044     }
0045 }
0046 
0047 QString TeamRemoveRoomJob::teamId() const
0048 {
0049     return mTeamId;
0050 }
0051 
0052 void TeamRemoveRoomJob::setTeamId(const QString &teamId)
0053 {
0054     mTeamId = teamId;
0055 }
0056 
0057 QString TeamRemoveRoomJob::roomId() const
0058 {
0059     return mRoomId;
0060 }
0061 
0062 void TeamRemoveRoomJob::setRoomId(const QString &roomId)
0063 {
0064     mRoomId = roomId;
0065 }
0066 
0067 bool TeamRemoveRoomJob::requireHttpAuthentication() const
0068 {
0069     return true;
0070 }
0071 
0072 bool TeamRemoveRoomJob::canStart() const
0073 {
0074     if (!RestApiAbstractJob::canStart()) {
0075         return false;
0076     }
0077     if (mRoomId.isEmpty()) {
0078         qCWarning(ROCKETCHATQTRESTAPI_LOG) << "TeamRemoveRoomJob: mRoomId is empty";
0079         return false;
0080     }
0081     if (mTeamId.isEmpty()) {
0082         qCWarning(ROCKETCHATQTRESTAPI_LOG) << "TeamRemoveRoomJob: mTeamId is empty";
0083         return false;
0084     }
0085     return true;
0086 }
0087 
0088 QNetworkRequest TeamRemoveRoomJob::request() const
0089 {
0090     const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::TeamsRemoveRoom);
0091     QNetworkRequest request(url);
0092     addAuthRawHeader(request);
0093     addRequestAttribute(request);
0094     return request;
0095 }
0096 
0097 QJsonDocument TeamRemoveRoomJob::json() const
0098 {
0099     QJsonObject jsonObj;
0100     jsonObj[QLatin1String("roomId")] = mRoomId;
0101     jsonObj[QLatin1String("teamId")] = mTeamId;
0102     const QJsonDocument postData = QJsonDocument(jsonObj);
0103     return postData;
0104 }
0105 
0106 #include "moc_teamremoveroomjob.cpp"