currencies request
This commit is contained in:
parent
a2c2c2a883
commit
db37abacd2
24 changed files with 243 additions and 57 deletions
|
@ -4,11 +4,13 @@
|
|||
set(HEADERS
|
||||
session.h
|
||||
asset.h
|
||||
currency.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
session.cpp
|
||||
asset.cpp
|
||||
currency.cpp
|
||||
)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
||||
|
|
|
@ -4,30 +4,33 @@
|
|||
#include "asset.h"
|
||||
|
||||
DB::Asset::Asset ():
|
||||
id(),
|
||||
owner(),
|
||||
currency(),
|
||||
id(0),
|
||||
owner(0),
|
||||
currency(0),
|
||||
title(),
|
||||
icon(),
|
||||
archived()
|
||||
color(0),
|
||||
archived(false)
|
||||
{}
|
||||
|
||||
DB::Asset::Asset (const std::vector<std::any>& vec):
|
||||
id(std::any_cast<unsigned int>(vec[0])),
|
||||
owner(std::any_cast<unsigned int>(vec[1])),
|
||||
currency(std::any_cast<unsigned int>(vec[2])),
|
||||
id(std::any_cast<uint32_t>(vec[0])),
|
||||
owner(std::any_cast<uint32_t>(vec[1])),
|
||||
currency(std::any_cast<uint32_t>(vec[2])),
|
||||
title(std::any_cast<const std::string&>(vec[3])),
|
||||
icon(std::any_cast<const std::string&>(vec[4])),
|
||||
archived(std::any_cast<uint8_t>(vec[5]))
|
||||
color(std::any_cast<uint32_t>(vec[5])),
|
||||
archived(std::any_cast<uint8_t>(vec[6]))
|
||||
{}
|
||||
|
||||
void DB::Asset::parse (const std::vector<std::any>& vec) {
|
||||
id = std::any_cast<unsigned int>(vec[0]);
|
||||
owner = std::any_cast<unsigned int>(vec[1]);
|
||||
currency = std::any_cast<unsigned int>(vec[2]);
|
||||
id = std::any_cast<uint32_t>(vec[0]);
|
||||
owner = std::any_cast<uint32_t>(vec[1]);
|
||||
currency = std::any_cast<uint32_t>(vec[2]);
|
||||
title = std::any_cast<const std::string&>(vec[3]);
|
||||
icon = std::any_cast<const std::string&>(vec[4]);
|
||||
archived = std::any_cast<uint8_t>(vec[5]);
|
||||
color = std::any_cast<uint32_t>(vec[5]);
|
||||
archived = std::any_cast<uint8_t>(vec[6]);
|
||||
}
|
||||
|
||||
nlohmann::json DB::Asset::toJSON () const {
|
||||
|
@ -38,6 +41,7 @@ nlohmann::json DB::Asset::toJSON () const {
|
|||
//result["currency"] = currency;
|
||||
result["title"] = title;
|
||||
result["icon"] = icon;
|
||||
result["color"] = color;
|
||||
result["archived"] = archived;
|
||||
|
||||
return result;
|
||||
|
|
|
@ -20,12 +20,12 @@ public:
|
|||
nlohmann::json toJSON () const;
|
||||
|
||||
public:
|
||||
unsigned int id;
|
||||
unsigned int owner;
|
||||
unsigned int currency;
|
||||
uint32_t id;
|
||||
uint32_t owner;
|
||||
uint32_t currency;
|
||||
std::string title;
|
||||
std::string icon;
|
||||
// `color` INTEGER UNSIGNED DEFAULT 0,
|
||||
uint32_t color;
|
||||
// `balance` DECIMAL (20, 5) DEFAULT 0,
|
||||
// `type` INTEGER UNSIGNED NOT NULL,
|
||||
bool archived;
|
||||
|
|
40
database/schema/currency.cpp
Normal file
40
database/schema/currency.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
//SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "currency.h"
|
||||
|
||||
DB::Currency::Currency ():
|
||||
id(0),
|
||||
code(),
|
||||
title(),
|
||||
manual(false),
|
||||
icon()
|
||||
{}
|
||||
|
||||
DB::Currency::Currency (const std::vector<std::any>& vec):
|
||||
id(std::any_cast<uint32_t>(vec[0])),
|
||||
code(std::any_cast<const std::string&>(vec[1])),
|
||||
title(std::any_cast<const std::string&>(vec[2])),
|
||||
manual(std::any_cast<uint8_t>(vec[3])),
|
||||
icon(std::any_cast<const std::string&>(vec[4]))
|
||||
{}
|
||||
|
||||
void DB::Currency::parse (const std::vector<std::any>& vec) {
|
||||
id = std::any_cast<uint32_t>(vec[0]);
|
||||
code = std::any_cast<const std::string&>(vec[1]);
|
||||
title = std::any_cast<const std::string&>(vec[2]);
|
||||
manual = std::any_cast<uint8_t>(vec[3]);
|
||||
icon = std::any_cast<const std::string&>(vec[4]);
|
||||
}
|
||||
|
||||
nlohmann::json DB::Currency::toJSON () const {
|
||||
nlohmann::json result = nlohmann::json::object();
|
||||
|
||||
result["id"] = id;
|
||||
result["code"] = code;
|
||||
result["title"] = title;
|
||||
result["manual"] = manual;
|
||||
result["icon"] = icon;
|
||||
|
||||
return result;
|
||||
}
|
35
database/schema/currency.h
Normal file
35
database/schema/currency.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
//SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <any>
|
||||
#include <cstdint>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace DB {
|
||||
class Currency {
|
||||
public:
|
||||
Currency ();
|
||||
Currency (const std::vector<std::any>& vec);
|
||||
|
||||
void parse (const std::vector<std::any>& vec);
|
||||
nlohmann::json toJSON () const;
|
||||
|
||||
public:
|
||||
uint32_t id;
|
||||
std::string code;
|
||||
std::string title;
|
||||
bool manual;
|
||||
// `added` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
|
||||
// `type` INTEGER UNSIGNED NOT NULL,
|
||||
// `value` DECIMAL (20, 5) NOT NULL,
|
||||
// `source` TEXT,
|
||||
// `description` TEXT,
|
||||
std::string icon;
|
||||
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue