ORE Studio 0.0.4
Loading...
Searching...
No Matches
country_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_COUNTRY_SERVICE_HPP
21#define ORES_REFDATA_CORE_SERVICE_COUNTRY_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/country.hpp"
30#include "ores.refdata.core/repository/country_repository.hpp"
31#include "ores.refdata.core/repository/party_country_repository.hpp"
32#include "ores.logging/make_logger.hpp"
33
34namespace ores::refdata::service {
35
43private:
44 inline static std::string_view logger_name =
45 "ores.refdata.service.country_service";
46
47 [[nodiscard]] static auto& lg() {
48 using namespace ores::logging;
49 static auto instance = make_logger(logger_name);
50 return instance;
51 }
52
53public:
55
61 explicit country_service(context ctx);
62
70 std::vector<domain::country> list_countries(std::uint32_t offset,
71 std::uint32_t limit);
72
78 std::uint32_t count_countries();
79
86 void save_country(const domain::country& country);
87
94 void save_countries(const std::vector<domain::country>& countries);
95
102 void delete_country(const std::string& alpha2_code);
103
107 void delete_countries(const std::vector<std::string>& alpha2_codes);
108
115 std::optional<domain::country> get_country(const std::string& alpha2_code);
116
123 std::vector<domain::country> get_country_history(const std::string& alpha2_code);
124
136 std::vector<domain::country> list_countries_for_party(
137 const boost::uuids::uuid& party_id,
138 std::uint32_t offset, std::uint32_t limit);
139
146 std::uint32_t count_countries_for_party(const boost::uuids::uuid& party_id);
147
148private:
149 context ctx_;
151 repository::party_country_repository junction_repo_;
152};
153
154}
155
156#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 country using ISO 3166-1 standard codes.
Definition country.hpp:34
Reads and writes countries off of data storage.
Definition country_repository.hpp:35
Service for managing countries.
Definition country_service.hpp:42
std::vector< domain::country > get_country_history(const std::string &alpha2_code)
Retrieves all historical versions of a country.
Definition country_service.cpp:93
void save_countries(const std::vector< domain::country > &countries)
Saves a batch of countries.
Definition country_service.cpp:61
std::optional< domain::country > get_country(const std::string &alpha2_code)
Retrieves a single country by its alpha-2 code.
Definition country_service.cpp:83
void delete_country(const std::string &alpha2_code)
Deletes a country by its alpha-2 code.
Definition country_service.cpp:73
std::vector< domain::country > list_countries_for_party(const boost::uuids::uuid &party_id, std::uint32_t offset, std::uint32_t limit)
Lists countries visible to a specific party, with pagination.
Definition country_service.cpp:99
void delete_countries(const std::vector< std::string > &alpha2_codes)
Deletes countries by their alpha-2 codes.
Definition country_service.cpp:78
std::vector< domain::country > list_countries(std::uint32_t offset, std::uint32_t limit)
Lists countries with pagination support.
Definition country_service.cpp:39
std::uint32_t count_countries_for_party(const boost::uuids::uuid &party_id)
Gets the total count of countries visible to a specific party.
Definition country_service.cpp:129
void save_country(const domain::country &country)
Saves a country (creates or updates).
Definition country_service.cpp:51
std::uint32_t count_countries()
Gets the total count of active countries.
Definition country_service.cpp:46