schema directory for all datastructures of database, add-list assets requests, not tested
This commit is contained in:
parent
d33ec5def8
commit
4df8d4319e
15 changed files with 306 additions and 62 deletions
14
database/schema/CMakeLists.txt
Normal file
14
database/schema/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
#SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
#SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set(HEADERS
|
||||
session.h
|
||||
asset.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
session.cpp
|
||||
asset.cpp
|
||||
)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
44
database/schema/asset.cpp
Normal file
44
database/schema/asset.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
//SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "asset.h"
|
||||
|
||||
DB::Asset::Asset ():
|
||||
id(),
|
||||
owner(),
|
||||
currency(),
|
||||
title(),
|
||||
icon(),
|
||||
archived()
|
||||
{}
|
||||
|
||||
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])),
|
||||
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]))
|
||||
{}
|
||||
|
||||
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]);
|
||||
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]);
|
||||
}
|
||||
|
||||
nlohmann::json DB::Asset::toJSON () const {
|
||||
nlohmann::json result = nlohmann::json::object();
|
||||
|
||||
result["id"] = id;
|
||||
//result["owner"] = owner;
|
||||
//result["currency"] = currency;
|
||||
result["title"] = title;
|
||||
result["icon"] = icon;
|
||||
result["archived"] = archived;
|
||||
|
||||
return result;
|
||||
}
|
33
database/schema/asset.h
Normal file
33
database/schema/asset.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
//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 Asset {
|
||||
public:
|
||||
Asset ();
|
||||
Asset (const std::vector<std::any>& vec);
|
||||
|
||||
void parse (const std::vector<std::any>& vec);
|
||||
nlohmann::json toJSON () const;
|
||||
|
||||
public:
|
||||
unsigned int id;
|
||||
unsigned int owner;
|
||||
unsigned int currency;
|
||||
std::string title;
|
||||
std::string icon;
|
||||
// `color` INTEGER UNSIGNED DEFAULT 0,
|
||||
// `balance` DECIMAL (20, 5) DEFAULT 0,
|
||||
// `type` INTEGER UNSIGNED NOT NULL,
|
||||
bool archived;
|
||||
};
|
||||
}
|
18
database/schema/session.cpp
Normal file
18
database/schema/session.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
//SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "session.h"
|
||||
|
||||
DB::Session::Session ():
|
||||
id(),
|
||||
owner(),
|
||||
accessToken(),
|
||||
renewToken()
|
||||
{}
|
||||
|
||||
DB::Session::Session (const std::vector<std::any>& vec):
|
||||
id(std::any_cast<unsigned int>(vec[0])),
|
||||
owner(std::any_cast<unsigned int>(vec[1])),
|
||||
accessToken(std::any_cast<const std::string&>(vec[2])),
|
||||
renewToken(std::any_cast<const std::string&>(vec[3]))
|
||||
{}
|
23
database/schema/session.h
Normal file
23
database/schema/session.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
//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>
|
||||
|
||||
namespace DB {
|
||||
class Session {
|
||||
public:
|
||||
Session ();
|
||||
Session (const std::vector<std::any>& vec);
|
||||
|
||||
public:
|
||||
unsigned int id;
|
||||
unsigned int owner;
|
||||
std::string accessToken;
|
||||
std::string renewToken;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue