Fetch information if the cache was recommended by the user from Okapi

sql-rework
Tomasz Golinski 2020-02-29 02:14:31 +01:00
rodzic 1a3a7e0747
commit fc98a0a858
2 zmienionych plików z 6 dodań i 3 usunięć

Wyświetl plik

@ -53,6 +53,7 @@ public:
float terr = 0; float terr = 0;
int fav = 0; int fav = 0;
int founds = 0; int founds = 0;
bool recommended = 0; // was the cache recommended by that user?
std::string type; std::string type;
std::string region; std::string region;
std::string origin; std::string origin;

Wyświetl plik

@ -78,7 +78,7 @@ std::string Okapi::curl_post(const std::string& url, const std::string& post) co
std::string Okapi::get_user_caches_json(const std::string& uuid, int count, int offset) const { std::string Okapi::get_user_caches_json(const std::string& uuid, int count, int offset) const {
std::string service = url + OKAPI_logs; std::string service = url + OKAPI_logs;
std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=cache_code|type|date&limit=" + std::to_string(count) + "&offset=" + std::to_string(offset); std::string query = "consumer_key=" + key + "&user_uuid=" + uuid + "&fields=cache_code|type|date|was_recommended&limit=" + std::to_string(count) + "&offset=" + std::to_string(offset);
return curl_post(service, query); return curl_post(service, query);
} }
@ -173,6 +173,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
struct extra_data { struct extra_data {
std::tm date; std::tm date;
bool was_recommended;
}; };
std::map<std::string, extra_data> tmp_data; // holds data from logs which needs to be added to Caches later std::map<std::string, extra_data> tmp_data; // holds data from logs which needs to be added to Caches later
@ -191,7 +192,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
// TODO need to take care of the time zone :/ // TODO need to take care of the time zone :/
ss >> std::get_time(&date, "%Y-%m-%dT%H:%M:%S+"); ss >> std::get_time(&date, "%Y-%m-%dT%H:%M:%S+");
codes.push_back(el.value()["cache_code"].get<std::string>()); codes.push_back(el.value()["cache_code"].get<std::string>());
tmp_data[el.value()["cache_code"].get<std::string>()] = { date }; tmp_data[el.value()["cache_code"].get<std::string>()] = { date, el.value()["was_recommended"] };
} }
} }
off += j.size(); off += j.size();
@ -207,7 +208,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
std::stringstream ss(el.value()["date"].get<std::string>()); std::stringstream ss(el.value()["date"].get<std::string>());
ss >> std::get_time(&date, "%Y-%m-%dT%H-%M-%S"); ss >> std::get_time(&date, "%Y-%m-%dT%H-%M-%S");
codes.push_back(el.value()["cache_code"].get<std::string>()); codes.push_back(el.value()["cache_code"].get<std::string>());
tmp_data[el.value()["cache_code"].get<std::string>()] = { date }; tmp_data[el.value()["cache_code"].get<std::string>()] = { date, el.value()["was_recommended"] };
} }
} }
off += j.size(); off += j.size();
@ -225,6 +226,7 @@ Caches Okapi::get_user_caches(const std::string& uuid, int count) const {
for (auto& el : tmp_data) { for (auto& el : tmp_data) {
auto& it = mcc.at(el.first); auto& it = mcc.at(el.first);
it.set_date(el.second.date); it.set_date(el.second.date);
it.recommended = el.second.was_recommended;
} }
return cc; return cc;