tested currencies retrieval, now assets display the currency
This commit is contained in:
parent
45f924a4cf
commit
cf2f387f58
14 changed files with 137 additions and 27 deletions
19
API/api.cpp
19
API/api.cpp
|
@ -11,7 +11,8 @@
|
|||
#include "requests/register.h"
|
||||
#include "requests/login.h"
|
||||
#include "requests/poll.h"
|
||||
#include "requests/listassets.h"
|
||||
#include "requests/assets.h"
|
||||
#include "requests/currencies.h"
|
||||
#include "requests/addasset.h"
|
||||
#include "requests/deleteasset.h"
|
||||
|
||||
|
@ -93,10 +94,20 @@ API::RequestId API::sendLogin (const QString& login, const QString& password, co
|
|||
API::RequestId API::requestAssets (const SuccessListHandler& success, const ErrorHandler& error) {
|
||||
qDebug() << "Requesting assets...";
|
||||
|
||||
auto list = std::make_unique<Request::ListAssets>(magpie.getAddress());
|
||||
auto list = std::make_unique<Request::Assets>(magpie.getAddress());
|
||||
list->setAuthorizationToken(magpie.getAccessToken());
|
||||
connect(list.get(), &Request::ListAssets::success, success);
|
||||
connect(list.get(), &Request::ListAssets::error, error);
|
||||
connect(list.get(), &Request::Assets::success, success);
|
||||
connect(list.get(), &Request::Assets::error, error);
|
||||
return registerAndSend(std::move(list));
|
||||
}
|
||||
|
||||
API::RequestId API::requestCurrencies (const SuccessListHandler& success, const ErrorHandler& error) {
|
||||
qDebug() << "Requesting currencies...";
|
||||
|
||||
auto list = std::make_unique<Request::Currencies>(magpie.getAddress());
|
||||
list->setAuthorizationToken(magpie.getAccessToken());
|
||||
connect(list.get(), &Request::Currencies::success, success);
|
||||
connect(list.get(), &Request::Currencies::error, error);
|
||||
return registerAndSend(std::move(list));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
explicit API(Models::Magpie& magpie, QObject* parent = nullptr);
|
||||
|
||||
RequestId requestAssets(const SuccessListHandler& success, const ErrorHandler& error);
|
||||
RequestId requestCurrencies(const SuccessListHandler& success, const ErrorHandler& error);
|
||||
RequestId poll(const SuccessMapHandler& success, const ErrorHandler& error, bool clear = false);
|
||||
|
||||
static const RequestId none = 0;
|
||||
|
|
|
@ -8,7 +8,8 @@ set(HEADERS
|
|||
register.h
|
||||
login.h
|
||||
poll.h
|
||||
listassets.h
|
||||
assets.h
|
||||
currencies.h
|
||||
addasset.h
|
||||
deleteasset.h
|
||||
)
|
||||
|
@ -20,7 +21,8 @@ set(SOURCES
|
|||
register.cpp
|
||||
login.cpp
|
||||
poll.cpp
|
||||
listassets.cpp
|
||||
assets.cpp
|
||||
currencies.cpp
|
||||
addasset.cpp
|
||||
deleteasset.cpp
|
||||
)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "listassets.h"
|
||||
#include "assets.h"
|
||||
|
||||
#include "utils/helpers.h"
|
||||
|
||||
Request::ListAssets::ListAssets (const QUrl& baseUrl):
|
||||
Request(createUrl(baseUrl, "/listAssets")) {}
|
||||
Request::Assets::Assets (const QUrl& baseUrl):
|
||||
Request(createUrl(baseUrl, "/assets")) {}
|
||||
|
||||
void Request::ListAssets::onSuccess (const QVariantMap& data) {
|
||||
void Request::Assets::onSuccess (const QVariantMap& data) {
|
||||
QVariantMap::ConstIterator itr = data.find("assets");
|
||||
if (itr == data.constEnd() || !itr->canConvert<QVariantList>())
|
||||
return Request::onError("Error receiving assets: assets are missing or not in an array", std::nullopt);
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
namespace Request {
|
||||
|
||||
class ListAssets : public Request {
|
||||
class Assets : public Request {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ListAssets (const QUrl& baseUrl);
|
||||
Assets (const QUrl& baseUrl);
|
||||
|
||||
signals:
|
||||
void success(const QVariantList& assets);
|
18
API/requests/currencies.cpp
Normal file
18
API/requests/currencies.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "currencies.h"
|
||||
|
||||
#include "utils/helpers.h"
|
||||
|
||||
Request::Currencies::Currencies (const QUrl& baseUrl):
|
||||
Request(createUrl(baseUrl, "/currencies")) {}
|
||||
|
||||
void Request::Currencies::onSuccess (const QVariantMap& data) {
|
||||
QVariantMap::ConstIterator itr = data.find("currencies");
|
||||
if (itr == data.constEnd() || !itr->canConvert<QVariantList>())
|
||||
return Request::onError("Error receiving currencies: currencies are missing or not in an array", std::nullopt);
|
||||
|
||||
emit success(qast<QVariantList>(itr.value()));
|
||||
emit done();
|
||||
}
|
24
API/requests/currencies.h
Normal file
24
API/requests/currencies.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "request.h"
|
||||
|
||||
namespace Request {
|
||||
|
||||
class Currencies : public Request::Request {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Currencies (const QUrl& baseUrl);
|
||||
|
||||
signals:
|
||||
void success(const QVariantList& assets);
|
||||
|
||||
protected:
|
||||
void onSuccess (const QVariantMap& data) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue