From 61f124f3594ea3977683dc6f16f5179e593352b8 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 20 Mar 2023 16:59:24 -0400 Subject: [PATCH] show category route --- server.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server.cpp b/server.cpp index fe2043f..b696b02 100644 --- a/server.cpp +++ b/server.cpp @@ -82,6 +82,39 @@ int main() return entries; }); + CROW_ROUTE(app, "/show-category/")([](int category_id){ + connect(); + crow::json::wvalue entries; + + ResultSet *res = stmt->executeQuery("call show_category("+to_string(category_id)+");"); + + int i = 0; + while (res->next()) { + int id = res->getInt("id"); + string description = res->getString("description"); + int seconds = res->getInt("seconds"); + string comments = res->getString("comments"); + string created_at = res->getString("created_at"); + int category_id = res->getInt("category_id"); + string category = res->getString("category"); + string instrument = res->getString("instrument"); + entries[i] = { + {"id", id}, + {"description", description}, + {"seconds", seconds}, + {"comments", comments}, + {"created_at", created_at}, + {"category_id", category_id}, + {"category", category}, + {"instrument", instrument} + }; + i++; + } + + delete res; + return entries; + }); + app.port(18080).run(); atexit(exiting);