From ccfb131aaf6a06f193149ad0adc71a09b3ab59ad Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Thu, 23 Mar 2023 20:54:14 -0400 Subject: [PATCH] songs endpoint --- server.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/server.cpp b/server.cpp index 3e3da0e..b9829b1 100644 --- a/server.cpp +++ b/server.cpp @@ -28,6 +28,27 @@ int main() driver = get_driver_instance(); + CROW_ROUTE(app, "/songs")([](){ + con = driver->connect(getenv("DBURL"),getenv("DBUSER"),getenv("DBPWD")); + con->setSchema("my_group_songs"); + stmt = con->createStatement(); + crow::json::wvalue entries; + + ResultSet *res = stmt->executeQuery("SELECT * FROM songs WHERE learned=True ORDER BY title ASC;"); + + int i = 0; + while (res->next()) { + int id = res->getInt("id"); + string title = res->getString("title"); + string notes = res->getString("notes"); + entries[i] = {{"id", id}, {"title", title}, {"notes", notes}}; + i++; + } + + delete res; + return entries; + }); + CROW_ROUTE(app, "/categories")([](){ connect(); crow::json::wvalue entries;