File indexing completed on 2024-05-12 16:59:03
0001 /* 0002 SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "bugclient.h" 0008 0009 namespace Bugzilla 0010 { 0011 QList<Bug::Ptr> BugClient::search(KJob *kjob) const 0012 { 0013 auto *job = qobject_cast<APIJob *>(kjob); 0014 0015 auto ary = job->object().value(QStringLiteral("bugs")).toArray(); 0016 0017 QList<Bug::Ptr> list; 0018 for (auto bug : ary) { 0019 list.append(Bug::Ptr(new Bug(bug.toObject().toVariantHash()))); 0020 } 0021 0022 return list; 0023 } 0024 0025 KJob *BugClient::search(const BugSearch &search) 0026 { 0027 return m_connection.get(QStringLiteral("/bug"), search.toQuery()); 0028 } 0029 0030 qint64 BugClient::create(KJob *kjob) const 0031 { 0032 auto *job = qobject_cast<APIJob *>(kjob); 0033 0034 qint64 ret = job->object().value(QStringLiteral("id")).toInt(-1); 0035 Q_ASSERT(ret != -1); 0036 return ret; 0037 } 0038 0039 KJob *BugClient::create(const NewBug &bug) 0040 { 0041 return m_connection.post(QStringLiteral("/bug"), bug.toJson()); 0042 } 0043 0044 qint64 BugClient::update(KJob *kjob) const 0045 { 0046 auto *job = qobject_cast<APIJob *>(kjob); 0047 0048 auto ary = job->object().value(QStringLiteral("bugs")).toArray(); 0049 // It's unclear if this can happen. When the ids would be empty there was 0050 // an error, and when there was an error the API should have sent an error. 0051 Q_ASSERT(ary.size() == 1); 0052 0053 int value = ary.at(0).toObject().value(QStringLiteral("id")).toInt(-1); 0054 Q_ASSERT(value != -1); 0055 0056 return value; 0057 } 0058 0059 KJob *BugClient::update(qint64 bugId, BugUpdate &bug) 0060 { 0061 return m_connection.put(QStringLiteral("/bug/%1").arg(bugId), bug.toJson()); 0062 } 0063 0064 } // namespace Bugzilla