implement base template operations with the corresponding templates

fully implement the delete operation
todo:edit operation
This commit is contained in:
Tina_Azure
2023-05-15 19:32:21 +02:00
parent bbf526f99f
commit d9f3fd711c
6 changed files with 128 additions and 14 deletions

View File

@ -765,7 +765,7 @@ int main(int argc, char *argv[]) {
}
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
}
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT);
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT_STAGE_CONFIRMATION);
return page.render(ctx);
});
@ -773,17 +773,77 @@ int main(int argc, char *argv[]) {
* Execute Template Operation
* todo:implement
*/
CROW_ROUTE(app, "/freelancer/templateManagement/fulfilment").methods("POST"_method)
([&, configuration](const crow::request& postRequest ) {
CROW_ROUTE(app, "/freelancer/templateManagement/fulfilment/<string>").methods("POST"_method)
([&, configuration](const crow::request& postRequest, string operation ) {
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
cout << postRequest.body << endl;
crow::mustache::context ctx;
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
ctx = Utilities::getFreelancerTemplates(configuration, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
ctx["freelanceremail"] = cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL);
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
bool operationEdit = false;
bool operationDelete = false;
bool error = false;
if (operation == MUSTACHE_FREELANCER_TEMPLATE_OPERATION_EDIT) {
operationEdit = true;
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT] = true;
}
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT);
else if (operation == MUSTACHE_FREELANCER_TEMPLATE_OPERATION_DELETE) {
operationDelete = true;
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_DELETE] = true;
}
else {
error = true;
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_ERROR] = true;
}
if (!error) {
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
string freelancerEmail = cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL);
string postRequestBody = postRequest.body;
Utilities::decodeString(postRequestBody);
int templateid;
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
for (const string& item : splitPostRequestBody) {
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
if (splitItem.at(0) == "templateid")
templateid = stoi(splitItem.at(1));
}
pqxx::connection databaseConnection(configuration.databaseConnectionString);
if (operationEdit) {
//todo:implement Edit
string name, content, contactdata, contactinformation, currencypreference, priceupfront, priceondeliver;
Database::prepareStatement(databaseConnection, ID_EDIT_FREELANCER_TEMPLATE);
for (const string& item : splitPostRequestBody) {
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
if (splitItem.at(0) == "templatename")
name = splitItem.at(1);
if (splitItem.at(0) == "templatecontent")
content = splitItem.at(1);
if (splitItem.at(0) == "templatecontactdata")
contactdata = splitItem.at(1);
if (splitItem.at(0) == "templatecontactinformation")
contactinformation = splitItem.at(1);
if (splitItem.at(0) == "templatecurrencypreference")
currencypreference = splitItem.at(1);
if (splitItem.at(0) == "templatepriceupfront")
priceupfront = splitItem.at(1);
if (splitItem.at(0) == "templatepriceondeliver")
priceondeliver = splitItem.at(1);
}
if (!Utilities::checkIfStrIsNumber(priceupfront))
priceupfront = "0";
if (!Utilities::checkIfStrIsNumber(priceondeliver))
priceondeliver = "0";
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_COMPLETE] = true;
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT] = true;
} else if (operationDelete) {
Database::prepareStatement(databaseConnection, ID_DELETE_FREELANCER_TEMPLATE);
Database::executePreparedStatement_DELETE_FREELANCER_TEMPLATE(databaseConnection, templateid, freelancerEmail);
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_COMPLETE] = true;
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_DELETE] = true;
}
}
}
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT_STAGE_EXECUTION);
return page.render(ctx);
});