list -status now works, solves #4
This commit is contained in:
+42
-1
@@ -98,8 +98,49 @@ vector<ticket_t> Dao::fetch_ticket_get_all() {
|
||||
return t;
|
||||
}
|
||||
|
||||
vector<ticket_t> Dao::fetch_ticket_get_by_status(string status) {
|
||||
vector<ticket_t> filter_by_status(const vector<ticket_t>& tickets, const string status) {
|
||||
vector<ticket_t> out;
|
||||
|
||||
for (const auto& t: tickets) {
|
||||
if (t.status == status) {
|
||||
out.push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
vector<ticket_t> Dao::fetch_ticket_get_by_status(string status) {
|
||||
string response;
|
||||
string url = this->base_url + "/tickets";
|
||||
|
||||
CURL *handle = curl_easy_init();
|
||||
|
||||
struct curl_slist* headers = nullptr;
|
||||
headers = curl_slist_append(headers, "Content-Type: application/json");
|
||||
headers = curl_slist_append(headers, ("Authorization: Bearer " + this->api_key).c_str());
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &response);
|
||||
|
||||
CURLcode rc = curl_easy_perform(handle);
|
||||
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_cleanup(handle);
|
||||
|
||||
if (rc != CURLE_OK) {
|
||||
throw std::runtime_error(std::string("curl_easy_perform failed: ") + curl_easy_strerror(rc));
|
||||
}
|
||||
|
||||
nlohmann::json j = nlohmann::json::parse(response);
|
||||
|
||||
vector<ticket_t> tickets = j.get<vector<ticket_t>>();
|
||||
|
||||
return filter_by_status(tickets, status);
|
||||
}
|
||||
|
||||
ticket_t Dao::fetch_ticket_get_by_id(unsigned long id) {
|
||||
|
||||
Reference in New Issue
Block a user