File indexing completed on 2024-12-15 03:45:02
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "restapi.h" 0008 #include "restclient.h" 0009 0010 #include <core/product.h> 0011 #include <core/sample.h> 0012 #include <core/survey.h> 0013 0014 #include <QUuid> 0015 0016 using namespace KUserFeedback::Console; 0017 0018 QNetworkReply* RESTApi::checkSchema(RESTClient *client) 0019 { 0020 return client->get(QStringLiteral("analytics/check_schema")); 0021 } 0022 0023 QNetworkReply* RESTApi::listProducts(RESTClient *client) 0024 { 0025 return client->get(QStringLiteral("analytics/products")); 0026 } 0027 0028 QNetworkReply* RESTApi::createProduct(RESTClient *client, const Product &p) 0029 { 0030 Q_ASSERT(p.isValid()); 0031 return client->post(QStringLiteral("admin/products"), p.toJson()); 0032 } 0033 0034 QNetworkReply* RESTApi::updateProduct(RESTClient *client, const Product &p) 0035 { 0036 Q_ASSERT(p.isValid()); 0037 return client->put(QStringLiteral("admin/products/") + p.name(), p.toJson()); 0038 } 0039 0040 QNetworkReply* RESTApi::deleteProduct(RESTClient *client, const Product &p) 0041 { 0042 Q_ASSERT(p.isValid()); 0043 return client->deleteResource(QStringLiteral("admin/products/") + p.name()); 0044 } 0045 0046 QNetworkReply* RESTApi::listSamples(RESTClient *client, const Product &p) 0047 { 0048 Q_ASSERT(p.isValid()); 0049 return client->get(QStringLiteral("analytics/data/") + p.name()); 0050 } 0051 0052 QNetworkReply* RESTApi::addSamples(RESTClient *client, const Product &p, const QVector<Sample> &samples) 0053 { 0054 Q_ASSERT(p.isValid()); 0055 return client->post(QStringLiteral("admin/data/") + p.name(), Sample::toJson(samples, p)); 0056 } 0057 0058 QNetworkReply* RESTApi::listSurveys(RESTClient *client, const Product &p) 0059 { 0060 Q_ASSERT(p.isValid()); 0061 return client->get(QStringLiteral("analytics/surveys/") + p.name()); 0062 } 0063 0064 QNetworkReply* RESTApi::createSurvey(RESTClient *client, const Product &p, const Survey &s) 0065 { 0066 Q_ASSERT(p.isValid()); 0067 return client->post(QStringLiteral("admin/surveys/") + p.name(), s.toJson()); 0068 } 0069 0070 QNetworkReply* RESTApi::updateSurvey(RESTClient *client, const Survey &s) 0071 { 0072 return client->put(QStringLiteral("admin/surveys/") + s.uuid().toString(), s.toJson()); 0073 } 0074 0075 QNetworkReply* RESTApi::deleteSurvey(RESTClient *client, const Survey &s) 0076 { 0077 return client->deleteResource(QStringLiteral("admin/surveys/") + s.uuid().toString()); 0078 }