can insert sessions with no comments

master
Matt Huntington 3 years ago
parent 9b510748f8
commit daa0e81f49

@ -36,18 +36,35 @@ int main()
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();
if(request_body.has("comments")){
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();
} else {
prep_stmt = con->prepareStatement("INSERT INTO practice_sessions (description, seconds, practice_category_id) VALUES (?, ?, ?)");
string description = request_body["description"].s();
int seconds = request_body["seconds"].i();
int practice_category_id = request_body["practice_category_id"].i();
prep_stmt->setString(1, description);
prep_stmt->setInt(2, seconds);
prep_stmt->setInt(3, practice_category_id);
prep_stmt->execute();
}
status = {{"status", "success"}};
return status;

Loading…
Cancel
Save