Minor optimization and typofix
and add ctx to be rendered
This commit is contained in:
27
src/main.cpp
27
src/main.cpp
@ -48,11 +48,10 @@ int main(int argc, char *argv[]) {
|
|||||||
* Freelancer Profile Page for customers
|
* Freelancer Profile Page for customers
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/customer/<string>").methods("POST"_method)
|
CROW_ROUTE(app, "/customer/<string>").methods("POST"_method)
|
||||||
([databaseURI](const crow::request& postRequest, string freelancerName ) {
|
([configuration](const crow::request& postRequest, string freelancerName ) {
|
||||||
//Parses the request body and extracts the specified value
|
//Parses the request body and extracts the specified value
|
||||||
int freelancerID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "freelancerID"));
|
int freelancerID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "freelancerID"));
|
||||||
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
|
||||||
pqxx::result resultFreelancer = Database::executePreparedStatement_SELECT_FREELANCER(databaseConnection, freelancerID);
|
pqxx::result resultFreelancer = Database::executePreparedStatement_SELECT_FREELANCER(databaseConnection, freelancerID);
|
||||||
|
|
||||||
//error handling if invalid ID was delivered
|
//error handling if invalid ID was delivered
|
||||||
@ -71,7 +70,6 @@ int main(int argc, char *argv[]) {
|
|||||||
if (resultFreelancer.size() != 0){
|
if (resultFreelancer.size() != 0){
|
||||||
/*
|
/*
|
||||||
* puts freelancer data into context
|
* puts freelancer data into context
|
||||||
* todo::solve this with less hardcoding
|
|
||||||
*/
|
*/
|
||||||
for (int i = 0; i < resultFreelancer.columns(); ++i) {
|
for (int i = 0; i < resultFreelancer.columns(); ++i) {
|
||||||
string freelancerColumn = resultFreelancer.column_name(i);
|
string freelancerColumn = resultFreelancer.column_name(i);
|
||||||
@ -89,10 +87,10 @@ int main(int argc, char *argv[]) {
|
|||||||
* Page representing a freelancers Template
|
* Page representing a freelancers Template
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/customer/<string>/template/<string>").methods("POST"_method)
|
CROW_ROUTE(app, "/customer/<string>/template/<string>").methods("POST"_method)
|
||||||
([databaseURI](const crow::request& postRequest, string freelancerName, string templateName ) {
|
([configuration](const crow::request& postRequest, string freelancerName, string templateName ) {
|
||||||
int templateID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "templateID"));
|
int templateID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "templateID"));
|
||||||
|
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE(databaseConnection, templateID);
|
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE(databaseConnection, templateID);
|
||||||
|
|
||||||
crow::json::wvalue resultJsonTemplate = Database::convertResultRowToJSON(resultTemplate);
|
crow::json::wvalue resultJsonTemplate = Database::convertResultRowToJSON(resultTemplate);
|
||||||
@ -119,10 +117,10 @@ int main(int argc, char *argv[]) {
|
|||||||
* Page for entry of request data
|
* Page for entry of request data
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/customer/<string>/template/<string>/request").methods("POST"_method)
|
CROW_ROUTE(app, "/customer/<string>/template/<string>/request").methods("POST"_method)
|
||||||
([databaseURI](const crow::request& postRequest, string freelancerName, string templateName ) {
|
([configuration](const crow::request& postRequest, string freelancerName, string templateName ) {
|
||||||
int templateID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "templateID"));
|
int templateID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "templateID"));
|
||||||
|
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE(databaseConnection, templateID);
|
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE(databaseConnection, templateID);
|
||||||
|
|
||||||
crow::json::wvalue resultJsonTemplate = Database::convertResultRowToJSON(resultTemplate);
|
crow::json::wvalue resultJsonTemplate = Database::convertResultRowToJSON(resultTemplate);
|
||||||
@ -138,8 +136,8 @@ int main(int argc, char *argv[]) {
|
|||||||
* executes the creation of a new request.
|
* executes the creation of a new request.
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/customer/<string>/template/<string>/request/fulfilment").methods("POST"_method)
|
CROW_ROUTE(app, "/customer/<string>/template/<string>/request/fulfilment").methods("POST"_method)
|
||||||
([databaseURI, configuration](const crow::request& postRequest, string freelancerName, string templateName ) {
|
([configuration](const crow::request& postRequest, string freelancerName, string templateName ) {
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
string templateHTML = "customer_Freelancer_Template_Request_Fulfilment_ERROR.html";
|
string templateHTML = "customer_Freelancer_Template_Request_Fulfilment_ERROR.html";
|
||||||
|
|
||||||
Database::requestsItem newRequest;
|
Database::requestsItem newRequest;
|
||||||
@ -338,7 +336,7 @@ int main(int argc, char *argv[]) {
|
|||||||
* Page for freelancer to sign up fulfillment
|
* Page for freelancer to sign up fulfillment
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/freelancer/signup/fulfilment").methods("POST"_method)
|
CROW_ROUTE(app, "/freelancer/signup/fulfilment").methods("POST"_method)
|
||||||
([databaseURI, configuration](const crow::request& postRequest ) {
|
([configuration](const crow::request& postRequest ) {
|
||||||
crow::mustache::context ctx;
|
crow::mustache::context ctx;
|
||||||
|
|
||||||
string postRequestBody = postRequest.body;
|
string postRequestBody = postRequest.body;
|
||||||
@ -364,7 +362,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
if (requestFillCompletion) {
|
if (requestFillCompletion) {
|
||||||
//check if email address hasn't been registered yet
|
//check if email address hasn't been registered yet
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
pqxx::result checkResult = Database::executePreparedStatement_SELECT_CHECK_EMAIL_EXISTS(databaseConnection, email);
|
pqxx::result checkResult = Database::executePreparedStatement_SELECT_CHECK_EMAIL_EXISTS(databaseConnection, email);
|
||||||
int checkResultExtracted = stoi(checkResult.at(0).at(0).c_str());
|
int checkResultExtracted = stoi(checkResult.at(0).at(0).c_str());
|
||||||
|
|
||||||
@ -374,6 +372,7 @@ int main(int argc, char *argv[]) {
|
|||||||
pwhash = Utilities::hashPassword(pwsalt, password);
|
pwhash = Utilities::hashPassword(pwsalt, password);
|
||||||
|
|
||||||
int errorLevel = Database::executePreparedStatement_INSERT_NEW_FREELANCER(databaseConnection, email, name, pwsalt, pwhash);
|
int errorLevel = Database::executePreparedStatement_INSERT_NEW_FREELANCER(databaseConnection, email, name, pwsalt, pwhash);
|
||||||
|
|
||||||
if (errorLevel == 0) {
|
if (errorLevel == 0) {
|
||||||
ctx["REGISTRATION_SUCCESS"] = true;
|
ctx["REGISTRATION_SUCCESS"] = true;
|
||||||
ctx["freelancername"] = name;
|
ctx["freelancername"] = name;
|
||||||
@ -390,7 +389,7 @@ int main(int argc, char *argv[]) {
|
|||||||
else {
|
else {
|
||||||
ctx["REGISTRATION_ERROR"] = true;
|
ctx["REGISTRATION_ERROR"] = true;
|
||||||
ctx["freelanceremail"] = email;
|
ctx["freelanceremail"] = email;
|
||||||
ctx["REGISTRATION_ERROR_EMAIL_ALREADY_IN_USE<"] = true;
|
ctx["REGISTRATION_ERROR_EMAIL_ALREADY_IN_USE"] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -402,7 +401,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
auto page = crow::mustache::load(templateHTML);
|
auto page = crow::mustache::load(templateHTML);
|
||||||
|
|
||||||
return page.render();
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user