diff --git a/src/distribution.cpp b/src/distribution.cpp index be3be9a..8db1869 100644 --- a/src/distribution.cpp +++ b/src/distribution.cpp @@ -24,7 +24,26 @@ distribution::distribution() title(""), summary(""), domain_name(""), - lp(nullptr) {} + lp(nullptr), + current_series([this]() -> std::optional { + if (current_series_link.empty()) return std::nullopt; + if (_current_series) return _current_series; + + auto response = lp ? lp->api_get(current_series_link) : std::nullopt; + if (!response) return std::nullopt; + + auto data = nlohmann::json::parse(response.value()); + auto ds = distro_series::parse(data.dump()); + + if (ds) { + ds->set_lp(lp); + _current_series = ds; + return ds; + } + + return std::nullopt; + }) +{} distribution::~distribution() {} @@ -47,6 +66,7 @@ void distribution::parse_json(const std::string& json_data) { {"summary", [this](const nlohmann::json& val) { summary = val.get(); }}, {"domain_name", [this](const nlohmann::json& val) { domain_name = val.get(); }}, {"self_link", [this](const nlohmann::json& val) { self_link = val.get(); }}, + {"current_series_link", [this](const nlohmann::json& val) { current_series_link = val.get(); }}, {"web_link", [this](const nlohmann::json& val) { web_link = val.get(); }}, {"translationgroup_link", [this](const nlohmann::json& val) { translationgroup_link = val.get(); }} }; diff --git a/src/distribution.h b/src/distribution.h index 1ac3db4..e5c5da7 100644 --- a/src/distribution.h +++ b/src/distribution.h @@ -21,6 +21,7 @@ #include #include "launchpad.h" #include "distro_series.h" +#include "lazy_optional.h" #ifndef LAUNCHPAD_API #ifdef BUILDING_LAUNCHPAD @@ -63,13 +64,16 @@ public: std::string archive_mirrors_collection_link; std::string archives_collection_link; std::string main_archive_link; + std::string current_series_link; std::string series_collection_link; std::string valid_specifications_collection_link; std::string vulnerabilities_collection_link; std::string webhooks_collection_link; + lazy_optional()>> current_series; private: launchpad* lp; + std::optional _current_series = std::nullopt; // JSON parsing utility void parse_json(const std::string& json_data);