Spec marked
Handler for the creation of a new request
This commit is contained in:
@ -107,7 +107,7 @@ See the freelancer section under concepts for more information of what this shou
|
|||||||
|
|
||||||
Accessing this page will provide the customer with a rendered HTML document of a freelancer's job template. This rendering will take data that the freelancer provides for the job, ideally stored in the database, and fills it in for delivery to the customer. The job template should use a html template that the system administrator provides for filling in.
|
Accessing this page will provide the customer with a rendered HTML document of a freelancer's job template. This rendering will take data that the freelancer provides for the job, ideally stored in the database, and fills it in for delivery to the customer. The job template should use a html template that the system administrator provides for filling in.
|
||||||
|
|
||||||
### "/customer/$freelancer/template/$templateName/request"
|
+++ "/customer/$freelancer/template/$templateName/request"
|
||||||
|
|
||||||
request data partially provided by the template, gets filled out by the customer on this page.
|
request data partially provided by the template, gets filled out by the customer on this page.
|
||||||
|
|
||||||
|
88
src/main.cpp
88
src/main.cpp
@ -9,6 +9,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
Utilities::config configuration;
|
||||||
|
configuration.readConfigFile();
|
||||||
|
|
||||||
crow::SimpleApp app;
|
crow::SimpleApp app;
|
||||||
|
|
||||||
// CROW_ROUTE(app, "/test.json")
|
// CROW_ROUTE(app, "/test.json")
|
||||||
@ -145,21 +148,24 @@ int main() {
|
|||||||
return page.render(ctx);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 ) {
|
([databaseURI, configuration](const crow::request& postRequest, string freelancerName, string templateName ) {
|
||||||
|
pqxx::connection databaseConnection(databaseURI);
|
||||||
|
string templateHTML = "customer_Freelancer_Template_Request_Fulfilment_ERROR.html";
|
||||||
|
|
||||||
Database::requestsItem newRequest;
|
Database::requestsItem newRequest;
|
||||||
|
crow::mustache::context ctx;
|
||||||
|
|
||||||
|
ctx["freelancername"] = freelancerName;
|
||||||
|
ctx["templatename"] = templateName;
|
||||||
|
|
||||||
string postRequestBody = postRequest.body.c_str();
|
string postRequestBody = postRequest.body.c_str();
|
||||||
Utilities::decodeString(postRequestBody);
|
Utilities::decodeString(postRequestBody);
|
||||||
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
|
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
|
||||||
|
bool requestFillCompletion = false;
|
||||||
for (string item : splitPostRequestBody) {
|
for (string item : splitPostRequestBody) {
|
||||||
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
||||||
if (splitItem.at(0) == "customername")
|
if (splitItem.at(0) == "customername")
|
||||||
@ -173,33 +179,55 @@ int main() {
|
|||||||
if (splitItem.at(0) == "templateID")
|
if (splitItem.at(0) == "templateID")
|
||||||
newRequest.templateID = stoi(splitItem.at(1));
|
newRequest.templateID = stoi(splitItem.at(1));
|
||||||
}
|
}
|
||||||
|
if (newRequest.customerName != "" && (newRequest.customerEmailAddress != "" || newRequest.customerContactDetails != "") && newRequest.requestDescription != "" )
|
||||||
|
requestFillCompletion = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ctx["templateid"] = newRequest.templateID;
|
||||||
|
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
|
||||||
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE_FLAT(databaseConnection, newRequest.templateID);
|
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE_FLAT(databaseConnection, newRequest.templateID);
|
||||||
|
if (resultTemplate.size() > 0 && requestFillCompletion) {
|
||||||
|
for (int i = 0; i < resultTemplate.columns(); ++i) {
|
||||||
|
//freelancerid
|
||||||
|
newRequest.freelancerID = stoi(resultTemplate.at(0).at(0).c_str());
|
||||||
|
//currencypreference
|
||||||
|
newRequest.currencyPreference = resultTemplate.at(0).at(1).c_str();
|
||||||
|
//priceupfront
|
||||||
|
newRequest.priceUpFront = resultTemplate.at(0).at(2).c_str();
|
||||||
|
//priceondeliver
|
||||||
|
newRequest.priceOnDeliver = resultTemplate.at(0).at(3).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < resultTemplate.columns(); ++i) {
|
pqxx::result resultCommissionState = Database::executePreparedStatement_SELECT_FREELANCER_COMMISSION_STATE(databaseConnection, newRequest.freelancerID);
|
||||||
//freelancerid
|
|
||||||
newRequest.freelancerID = stoi(resultTemplate.at(0).at(0).c_str());
|
//the commissionstate
|
||||||
//currencypreference
|
if (resultCommissionState.size() == 0 || stoi(resultTemplate.at(0).at(0).c_str()) == 1) {
|
||||||
newRequest.currencyPreference = resultTemplate.at(0).at(1).c_str();
|
ctx["ERROR_COMMISSIONS_CLOSED"] = true;
|
||||||
//priceupfront
|
}
|
||||||
newRequest.priceUpFront = resultTemplate.at(0).at(2).c_str();
|
else {
|
||||||
//priceondeliver
|
int resultInsertOperation = Database::executePreparedStatement_INSERT_ITEM_IN_REQUESTS(databaseConnection, newRequest);
|
||||||
newRequest.priceOnDeliver = resultTemplate.at(0).at(3).c_str();
|
if (resultInsertOperation == 0) {
|
||||||
|
templateHTML = "customer_Freelancer_Template_Request_Fulfilment.html";
|
||||||
|
pqxx::result resultEmailAddress = Database::executePreparedStatement_SELECT_FREELANCER_EMAIL(databaseConnection, newRequest.freelancerID);
|
||||||
|
if (resultEmailAddress.size() > 0)
|
||||||
|
Utilities::sendEmail(configuration, resultEmailAddress.at(0).at(0).c_str(), "NEW REQUEST", newRequest.toJSONString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx["ERROR_UNABLE_TO_CREATE_REQUEST"] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newRequest.outputItem();
|
else {
|
||||||
|
if (requestFillCompletion)
|
||||||
|
ctx["ERROR_TEMPLATE_NOT_FOUND"] = true;
|
||||||
|
else
|
||||||
|
ctx["REQUEST_NOT_FILLED"] = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Utilities::sendEmail(configuration, "testfaewfaw@tempr.email", "NEW REQUEST", "NEW REQUEST");
|
|
||||||
|
|
||||||
string templateHTML = "customer_Freelancer_Template_Request_Fulfilment.html";
|
|
||||||
auto page = crow::mustache::load(templateHTML);
|
auto page = crow::mustache::load(templateHTML);
|
||||||
|
|
||||||
return page.render();
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -221,7 +249,7 @@ int main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
CROW_ROUTE(app, "/getEntry/<int>")
|
/*CROW_ROUTE(app, "/getEntry/<int>")
|
||||||
([databaseURI](int entry) {
|
([databaseURI](int entry) {
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
pqxx::connection databaseConnection(databaseURI);
|
||||||
pqxx::result result = Database::executePreparedStatement_SELECT_ITEM_BY_ID(databaseConnection, entry);
|
pqxx::result result = Database::executePreparedStatement_SELECT_ITEM_BY_ID(databaseConnection, entry);
|
||||||
@ -269,11 +297,11 @@ int main() {
|
|||||||
if (!jsonBody)
|
if (!jsonBody)
|
||||||
return crow::response(crow::status::BAD_REQUEST);
|
return crow::response(crow::status::BAD_REQUEST);
|
||||||
|
|
||||||
/*
|
|
||||||
* Example CURL to insert into DB:
|
* Example CURL to insert into DB:
|
||||||
* Price must be delivered as a string to avoid unnecessary conversion to double which would lead to the addition to a database of the value 0.359999999999999999999999999 instead of 0.36.
|
* Price must be delivered as a string to avoid unnecessary conversion to double which would lead to the addition to a database of the value 0.359999999999999999999999999 instead of 0.36.
|
||||||
* curl -H "Content-Type: application/json" -H "Accept: application/json" -d '{"customerEmailAddress":"2@testmail.com","freelancer":"nick","templateName":"coding","currencyPreference":"XMR","priceUpFront":"0.36","priceOnDeliver":"0.36","requestDescription":"This is a test","accepted":false,"upFrontInvoiceID":"12424242424","onDeliverInvoiceID":"329532532532","upFrontPaid":false,"onDeliverPaid":false}' http://0.0.0.0:18080/newRequest
|
* curl -H "Content-Type: application/json" -H "Accept: application/json" -d '{"customerEmailAddress":"2@testmail.com","freelancer":"nick","templateName":"coding","currencyPreference":"XMR","priceUpFront":"0.36","priceOnDeliver":"0.36","requestDescription":"This is a test","accepted":false,"upFrontInvoiceID":"12424242424","onDeliverInvoiceID":"329532532532","upFrontPaid":false,"onDeliverPaid":false}' http://0.0.0.0:18080/newRequest
|
||||||
*/
|
|
||||||
Database::requestsItem item;
|
Database::requestsItem item;
|
||||||
item.insertJsonIntoItem(jsonBody);
|
item.insertJsonIntoItem(jsonBody);
|
||||||
|
|
||||||
@ -282,7 +310,7 @@ int main() {
|
|||||||
|
|
||||||
return crow::response(200);
|
return crow::response(200);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
//set the port, set the app to run on multiple threads, and run the app
|
//set the port, set the app to run on multiple threads, and run the app
|
||||||
app.port(18080).multithreaded().run();
|
app.port(18080).multithreaded().run();
|
||||||
|
Reference in New Issue
Block a user