Nostro/interfaces/Nostro-Transaction.cppm

54 lines
2.2 KiB
Text
Raw Normal View History

2026-11-01 18:35:23 +01:00
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
2026-10-06 15:39:17 +02:00
export module Nostro:Transaction;
import std;
import :Currency;
2026-11-01 18:35:23 +01:00
import :Utils;
2026-10-06 15:39:17 +02:00
namespace Nostro {
2026-11-01 18:35:23 +01:00
// Version 1 of Transaction, kept so tables written by it migrate when opened. Do not change it.
struct TransactionV1 {
std::string name;
std::string bic;
std::string iban;
std::string description;
Currency currency;
std::int64_t amount;
std::chrono::system_clock::time_point timePoint;
static constexpr std::uint32_t version = 1;
static constexpr auto orderedBy = &TransactionV1::timePoint;
};
// Also the row type of the Crafter.DB transaction tables, so it has to stay an aggregate. The members are the
// on-disk schema: changing them needs a `version` bump (with the old struct as `using Previous`), or existing
// tables are refused when opened.
2026-10-06 15:39:17 +02:00
export struct Transaction {
2026-10-31 20:50:57 +01:00
std::string name;
std::string bic;
std::string iban;
std::string description;
2026-10-06 15:39:17 +02:00
Currency currency;
std::int64_t amount;
2026-10-31 20:50:57 +01:00
std::chrono::system_clock::time_point timePoint;
2026-11-01 18:35:23 +01:00
// The bank's own id for it, so a sync that overlaps the last stored timestamp stores nothing twice.
// Empty for rows stored by version 1.
std::string id;
// The bank's own classification, e.g. bunq's "MASTERCARD/PAYMENT" or "EBA_SDD/SDD". Empty for rows stored by version 1.
std::string kind;
2026-10-31 20:50:57 +01:00
2026-11-01 18:35:23 +01:00
static constexpr std::uint32_t version = 2;
static constexpr auto orderedBy = &Transaction::timePoint;
using Previous = TransactionV1;
2026-10-06 15:39:17 +02:00
};
}
2026-11-01 18:35:23 +01:00
// One line of a transaction list: local time, amount, counterparty, IBAN and description, tab separated.
template<>
struct std::formatter<Nostro::Transaction> : std::formatter<std::string> {
auto format(const Nostro::Transaction& obj, std::format_context& ctx) const {
return std::formatter<std::string>::format(std::format("{}\t{}\t{}\t{}\t{}", Nostro::FormatLocalTime(obj.timePoint), Nostro::FormatMoney(obj.amount, obj.currency), obj.name, obj.iban, obj.description), ctx);
}
};