Skip to content

Commit

Permalink
Changes to how the api stores data
Browse files Browse the repository at this point in the history
  • Loading branch information
BttrDrgn committed May 4, 2022
1 parent ae9045a commit b08ff31
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/app/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 });
}

}
Expand Down
9 changes: 2 additions & 7 deletions src/app/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@ 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
{
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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/audio/audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct playing_t
{
std::string title;
station_t station;
city_t region;
place_t region;
};

class audio
Expand Down
8 changes: 4 additions & 4 deletions src/app/menus/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit b08ff31

Please sign in to comment.