This commit is contained in:
Jorijn van der Graaf 2026-11-01 18:35:23 +01:00
commit 1ea50c50bc
62 changed files with 9982 additions and 608 deletions

View file

@ -1,5 +1,5 @@
//SPDX-License-Identifier: LGPL-3.0-only
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Nostro:Account;
@ -8,33 +8,39 @@ import :Currency;
import :Transaction;
namespace Nostro {
// What a transaction list shows: the newest `limit` transactions that match every field. `from` and `to` are inclusive.
export struct TransactionQuery {
std::string search; // case-insensitive (ASCII), in the name, description or IBAN; empty matches all
std::optional<std::int64_t> amount; // exact, in the currency's minor unit, negative when outgoing
std::chrono::system_clock::time_point from = std::chrono::system_clock::time_point::min();
std::chrono::system_clock::time_point to = std::chrono::system_clock::time_point::max();
std::size_t limit = 100;
};
export struct Account {
std::string name;
std::string bic;
std::string iban;
Currency currency;
std::int64_t balance;
std::vector<Transaction> transactions;
// Transactions are stored per connector and account name, in a table ordered by time.
std::chrono::system_clock::time_point GetLastTransactionTime(std::string_view connector) const;
void SaveTransactions(std::string_view connector);
void LoadTransactions(std::string_view connector);
void LoadTransactions(std::string_view connector, std::chrono::system_clock::time_point from);
void LoadTransactions(std::string_view connector, std::chrono::system_clock::time_point from, std::chrono::system_clock::time_point to);
void LoadTransactionsByDescription(std::string_view connector, std::string_view description);
void LoadTransactionsByIban(std::string_view connector, std::string_view iban);
void LoadTransactions(std::string_view connector, std::int64_t amount);
// Appends the ones newer than the last stored transaction, in any order.
void SaveTransactions(std::string_view connector, std::vector<Transaction> transactions);
// Newest first.
std::vector<Transaction> FindTransactions(std::string_view connector, const TransactionQuery& query) const;
private:
std::ifstream LoadUntilFrom(std::string_view connector, std::chrono::system_clock::time_point from);
Transaction& LoadTransaction(std::ifstream& file);
// Deletes every table stored under `connector` (a connector's storage key covers all its accounts), closing the
// ones this process has open first: a table left open on deleted files would take the next sync's rows with it.
static void ForgetTransactions(std::string_view connector);
};
}
template<std::derived_from<Nostro::Account> T>
struct std::formatter<T> : std::formatter<std::string> {
auto format(const Nostro::Account& obj, std::format_context& ctx) const {
return std::formatter<std::string>::format(std::format("{}\t{} {}\t{}{}", obj.name, obj.bic, obj.iban, obj.currency, Nostro::FormatAmount(obj.balance, obj.currency)), ctx);
return std::formatter<std::string>::format(std::format("{}\t{} {}\t{}", obj.name, obj.bic, obj.iban, Nostro::FormatMoney(obj.balance, obj.currency)), ctx);
}
};