|
|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
|
|
#include <driver.h>
|
|
|
|
|
#include <statement.h>
|
|
|
|
|
#include <prepared_statement.h>
|
|
|
|
|
|
|
|
|
|
using namespace sql;
|
|
|
|
|
using namespace std;
|
|
|
|
|
@ -10,6 +11,7 @@ using namespace std;
|
|
|
|
|
Driver *driver;
|
|
|
|
|
Connection *con;
|
|
|
|
|
Statement *stmt;
|
|
|
|
|
PreparedStatement *prep_stmt;
|
|
|
|
|
|
|
|
|
|
void exiting(){
|
|
|
|
|
delete con;
|
|
|
|
|
@ -28,6 +30,29 @@ int main()
|
|
|
|
|
|
|
|
|
|
driver = get_driver_instance();
|
|
|
|
|
|
|
|
|
|
CROW_ROUTE(app, "/sessions").methods(crow::HTTPMethod::POST)([](const crow::request& req){
|
|
|
|
|
con = driver->connect(getenv("DBURL"),getenv("DBUSER"),getenv("DBPWD"));
|
|
|
|
|
con->setSchema("practice");
|
|
|
|
|
crow::json::wvalue status;
|
|
|
|
|
auto request_body = crow::json::load(req.body);
|
|
|
|
|
|
|
|
|
|
prep_stmt = con->prepareStatement("INSERT INTO practice_sessions (description, seconds, comments, practice_category_id) VALUES (?, ?, ?, ?)");
|
|
|
|
|
|
|
|
|
|
string description = request_body["description"].s();
|
|
|
|
|
int seconds = request_body["seconds"].i();
|
|
|
|
|
string comments = request_body["comments"].s();
|
|
|
|
|
int practice_category_id = request_body["practice_category_id"].i();
|
|
|
|
|
|
|
|
|
|
prep_stmt->setString(1, description);
|
|
|
|
|
prep_stmt->setInt(2, seconds);
|
|
|
|
|
prep_stmt->setString(3, comments);
|
|
|
|
|
prep_stmt->setInt(4, practice_category_id);
|
|
|
|
|
prep_stmt->execute();
|
|
|
|
|
|
|
|
|
|
status = {{"status", "success"}};
|
|
|
|
|
return status;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CROW_ROUTE(app, "/songs")([](){
|
|
|
|
|
con = driver->connect(getenv("DBURL"),getenv("DBUSER"),getenv("DBPWD"));
|
|
|
|
|
con->setSchema("my_group_songs");
|
|
|
|
|
|