From b08ff31781bea9ed19e0ea8ee351ee1115fc0cfc Mon Sep 17 00:00:00 2001 From: BttrDrgn <49764143+BttrDrgn@users.noreply.github.com> Date: Wed, 4 May 2022 16:52:43 -0500 Subject: [PATCH] Changes to how the api stores data --- src/app/api/api.cpp | 10 +++++----- src/app/api/api.hpp | 9 ++------- src/app/audio/audio.hpp | 2 +- src/app/menus/menus.cpp | 8 ++++---- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/app/api/api.cpp b/src/app/api/api.cpp index 6fcb219..74b07c3 100644 --- a/src/app/api/api.cpp +++ b/src/app/api/api.cpp @@ -87,19 +87,19 @@ void api::get_places() }).detach(); } -void api::get_details(const std::string& id) +void api::get_details(const place_t& place_in) { api::details = {}; api::detail_done = false; api::station = {}; - std::thread([id] + std::thread([place_in] { httplib::Client cli(API_URL); - if (httplib::Result res = cli.Get(PLACE_DETAIL_ENDPOINT(&id[0]))) + if (httplib::Result res = cli.Get(PLACE_DETAIL_ENDPOINT(&place_in.id[0]))) { - LOG_DEBUG("Accessing %s%s", API_URL, PLACE_DETAIL_ENDPOINT(&id[0])); + LOG_DEBUG("Accessing %s%s", API_URL, PLACE_DETAIL_ENDPOINT(&place_in.id[0])); if (res->status == 200) { @@ -131,7 +131,7 @@ void api::get_details(const std::string& id) if (std::strcmp(&id[0], "null")) { - api::station.emplace_back(station_t{ title, id.substr(id.size() - 8) }); + api::station.emplace_back(station_t{ title, id.substr(id.size() - 8), place_in }); } } diff --git a/src/app/api/api.hpp b/src/app/api/api.hpp index 7cdbfd0..a8a6f03 100644 --- a/src/app/api/api.hpp +++ b/src/app/api/api.hpp @@ -13,15 +13,10 @@ struct place_t std::string country, city, id; }; -struct city_t -{ - std::string country, city; -}; - struct station_t { std::string title, id; - city_t region; + place_t place; }; class api @@ -29,7 +24,7 @@ class api public: static void get_places(); static void filter_place(const std::string& key); - static void get_details(const std::string& id); + static void get_details(const place_t& place_in); static void get_station(const std::string& id); static nl::json places; diff --git a/src/app/audio/audio.hpp b/src/app/audio/audio.hpp index ec27895..5ea91d8 100644 --- a/src/app/audio/audio.hpp +++ b/src/app/audio/audio.hpp @@ -9,7 +9,7 @@ struct playing_t { std::string title; station_t station; - city_t region; + place_t region; }; class audio diff --git a/src/app/menus/menus.cpp b/src/app/menus/menus.cpp index 18fdc69..8084cb4 100644 --- a/src/app/menus/menus.cpp +++ b/src/app/menus/menus.cpp @@ -185,7 +185,7 @@ void menus::places() { if (ImGui::Button(&logger::va("[%s] %s", &place.country[0], &place.city[0])[0])) { - api::get_details(place.id); + api::get_details(place); ImGui::CloseCurrentPopup(); } } @@ -203,7 +203,7 @@ void menus::places() { if (ImGui::Button(&logger::va("[%s] %s", &place.country[0], &place.city[0])[0])) { - api::get_details(place.id); + api::get_details(place); ImGui::CloseCurrentPopup(); } } @@ -234,8 +234,8 @@ void menus::stations() { audio::currently_playing.station.title = station.title; audio::currently_playing.station.id = station.id; - audio::currently_playing.region.city = station.region.city; - audio::currently_playing.region.country = station.region.country; + audio::currently_playing.region.city = station.place.city; + audio::currently_playing.region.country = station.place.country; audio::play(station.id); }