Also try fixing current_series in distribution

main
Simon Quigley 2 days ago
parent dd8f41140f
commit 3bbef476f9

@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "distribution.h" #include "distribution.h"
#include "distro_series.h"
#include <iostream> #include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -25,15 +26,15 @@ distribution::distribution()
summary(""), summary(""),
domain_name(""), domain_name(""),
lp(nullptr), lp(nullptr),
current_series([this]() -> std::optional<distro_series> { current_series([this]() -> std::optional<::distro_series> {
if (current_series_link.empty()) return std::nullopt; if (!lp || current_series_link.empty()) return std::nullopt;
if (_current_series) return _current_series; if (_current_series) return _current_series;
auto response = lp ? lp->api_get(current_series_link) : std::nullopt; auto response = lp ? lp->api_get(current_series_link) : std::nullopt;
if (!response) return std::nullopt; if (!response) return std::nullopt;
auto data = nlohmann::json::parse(response.value()); auto data = nlohmann::json::parse(response.value());
auto ds = distro_series::parse(data.dump()); auto ds = ::distro_series::parse(data.dump());
if (ds) { if (ds) {
ds->set_lp(lp); ds->set_lp(lp);

@ -69,14 +69,15 @@ public:
std::string valid_specifications_collection_link; std::string valid_specifications_collection_link;
std::string vulnerabilities_collection_link; std::string vulnerabilities_collection_link;
std::string webhooks_collection_link; std::string webhooks_collection_link;
lazy_optional<distro_series, std::function<std::optional<distro_series>()>> current_series;
private: private:
launchpad* lp; launchpad* lp;
std::optional<distro_series> _current_series = std::nullopt; std::optional<distro_series> _current_series = std::nullopt;
// JSON parsing utility // JSON parsing utility
void parse_json(const std::string& json_data); void parse_json(const std::string& json_data);
public:
lazy_optional<distro_series, std::function<std::optional<distro_series>()>> current_series;
}; };
#endif // DISTRIBUTION_H #endif // DISTRIBUTION_H

Loading…
Cancel
Save