implementation of the edit function for the template managment

+minor typo fixes
This commit is contained in:
Tina_Azure
2023-05-17 18:39:32 +02:00
parent d9f3fd711c
commit 1620967c45
3 changed files with 37 additions and 9 deletions

View File

@ -808,9 +808,8 @@ int main(int argc, char *argv[]) {
}
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);
Database::prepareStatement(databaseConnection, ID_UPDATE_EDIT_FREELANCER_TEMPLATE);
for (const string& item : splitPostRequestBody) {
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
if (splitItem.at(0) == "templatename")
@ -828,13 +827,22 @@ int main(int argc, char *argv[]) {
if (splitItem.at(0) == "templatepriceondeliver")
priceondeliver = splitItem.at(1);
}
if (name.empty())
name = "unnamed";
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;
bool updateSuccess = Database::executePreparedStatement_UPDATE_EDIT_FREELANCER_TEMPLATE(databaseConnection, name, content, contactdata, contactinformation, currencypreference, priceupfront, priceondeliver, templateid, freelancerEmail);
if (updateSuccess) {
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_COMPLETE] = true;
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT] = true;
}
else {
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_ERROR] = true;
}
} else if (operationDelete) {
Database::prepareStatement(databaseConnection, ID_DELETE_FREELANCER_TEMPLATE);
Database::executePreparedStatement_DELETE_FREELANCER_TEMPLATE(databaseConnection, templateid, freelancerEmail);