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 "commentclient.h"
0008 
0009 #include <QVariantHash>
0010 
0011 namespace Bugzilla
0012 {
0013 QList<Comment::Ptr> CommentClient::getFromBug(KJob *kjob) const
0014 {
0015     auto *job = qobject_cast<APIJob *>(kjob);
0016     QJsonObject bugs = job->object().value(QStringLiteral("bugs")).toObject();
0017 
0018     // The API should never return anything other than the single bug we asked for.
0019     Q_ASSERT(bugs.keys().size() == 1);
0020 
0021     QJsonObject bug = bugs.value(bugs.keys().at(0)).toObject();
0022     QJsonArray comments = bug.value(QStringLiteral("comments")).toArray();
0023 
0024     QList<Comment::Ptr> list;
0025     for (auto it = comments.constBegin(); it != comments.constEnd(); ++it) {
0026         list.append(new Comment((*it).toObject().toVariantHash()));
0027     }
0028 
0029     return list;
0030 }
0031 
0032 KJob *CommentClient::getFromBug(int bugId)
0033 {
0034     return m_connection.get(QStringLiteral("/bug/%1/comment").arg(QString::number(bugId)));
0035 }
0036 
0037 } // namespace Bugzilla