ORE Studio 0.0.4
Loading...
Searching...
No Matches
currency_service.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_REFDATA_CORE_SERVICE_CURRENCY_SERVICE_HPP
21#define ORES_REFDATA_CORE_SERVICE_CURRENCY_SERVICE_HPP
22
23#include <string>
24#include <vector>
25#include <cstdint>
26#include <optional>
27#include <boost/uuid/uuid.hpp>
28#include "ores.database/domain/context.hpp"
29#include "ores.refdata.api/domain/currency.hpp"
30#include "ores.refdata.api/domain/currency_version_history.hpp"
31#include "ores.refdata.core/repository/currency_repository.hpp"
32#include "ores.refdata.core/repository/party_currency_repository.hpp"
33#include "ores.logging/make_logger.hpp"
34
35namespace ores::refdata::service {
36
44private:
45 inline static std::string_view logger_name =
46 "ores.refdata.service.currency_service";
47
48 [[nodiscard]] static auto& lg() {
49 using namespace ores::logging;
50 static auto instance = make_logger(logger_name);
51 return instance;
52 }
53
54public:
56
62 explicit currency_service(context ctx);
63
71 std::vector<domain::currency> list_currencies(std::uint32_t offset,
72 std::uint32_t limit);
73
79 std::uint32_t count_currencies();
80
87 void save_currency(const domain::currency& currency);
88
95 void save_currencies(const std::vector<domain::currency>& currencies);
96
103 void delete_currency(const std::string& iso_code);
104
108 void delete_currencies(const std::vector<std::string>& iso_codes);
109
116 std::optional<domain::currency> get_currency(const std::string& iso_code);
117
124 std::vector<domain::currency> get_currency_history(const std::string& iso_code);
125
136 std::optional<domain::currency_version_history>
137 get_currency_version_history(const std::string& iso_code);
138
150 std::vector<domain::currency> list_currencies_for_party(
151 const boost::uuids::uuid& party_id,
152 std::uint32_t offset, std::uint32_t limit);
153
160 std::uint32_t count_currencies_for_party(const boost::uuids::uuid& party_id);
161
162private:
163 context ctx_;
165 repository::party_currency_repository junction_repo_;
166};
167
168}
169
170#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
Represents a currency with its metadata and formatting rules.
Definition currency.hpp:34
Reads and writes currencies off of data storage.
Definition currency_repository.hpp:35
Service for managing currencies.
Definition currency_service.hpp:43
void delete_currency(const std::string &iso_code)
Deletes a currency by its ISO code.
Definition currency_service.cpp:74
std::uint32_t count_currencies_for_party(const boost::uuids::uuid &party_id)
Gets the total count of currencies visible to a specific party.
Definition currency_service.cpp:169
std::vector< domain::currency > list_currencies(std::uint32_t offset, std::uint32_t limit)
Lists currencies with pagination support.
Definition currency_service.cpp:39
std::vector< domain::currency > get_currency_history(const std::string &iso_code)
Retrieves all historical versions of a currency.
Definition currency_service.cpp:94
std::optional< domain::currency_version_history > get_currency_version_history(const std::string &iso_code)
Retrieves currency version history with version metadata.
Definition currency_service.cpp:101
void delete_currencies(const std::vector< std::string > &iso_codes)
Deletes currencies by their ISO codes.
Definition currency_service.cpp:79
std::uint32_t count_currencies()
Gets the total count of active currencies.
Definition currency_service.cpp:46
void save_currencies(const std::vector< domain::currency > &currencies)
Saves a batch of currencies atomically (all or nothing).
Definition currency_service.cpp:61
std::vector< domain::currency > list_currencies_for_party(const boost::uuids::uuid &party_id, std::uint32_t offset, std::uint32_t limit)
Lists currencies visible to a specific party, with pagination.
Definition currency_service.cpp:139
void save_currency(const domain::currency &currency)
Saves a currency (creates or updates).
Definition currency_service.cpp:51
std::optional< domain::currency > get_currency(const std::string &iso_code)
Retrieves a single currency by its ISO code.
Definition currency_service.cpp:84