Rewrite to handle routing of /customer/freelancer using POST

This commit is contained in:
Tina_Azure
2023-04-04 01:51:27 +02:00
parent 0693fc0bf5
commit c70053eb53

View File

@ -3,6 +3,7 @@
#include <string>
#include <fmt/core.h>
#include "database.cpp"
#include "utilities.cpp"
using namespace std;
@ -39,18 +40,20 @@ int main() {
/*
* Freelancer Profile Page for customers
*/
CROW_ROUTE(app, "/customer/<string>/<int>")
([databaseURI](string freelancerName, int freelancerID) {
CROW_ROUTE(app, "/customer/<string>").methods("POST"_method)
([databaseURI](const crow::request& postRequest, string freelancerName ) {
//Parses the request body and extracts the specified value
int freelancerID = stoi(Utilities::extractSingleValueFromRequestBody(postRequest.body.c_str(), "freelancerID"));
pqxx::connection databaseConnection(databaseURI);
pqxx::result resultFreelancer = Database::executePreparedStatement_SELECT_FREELANCER(databaseConnection, freelancerID);
//error handling if invalid ID was delivered
string freelancerHTML = "customer_FreelancerListing_NOTFOUND.html";
//crow::json::wvalue resultJsonFreelancer;
crow::json::wvalue resultJsonFreelancerTemplate;
crow::json::wvalue resultJsonFreelancerTemplate;
if (resultFreelancer.size() != 0){
freelancerHTML = "customer_FreelancerListing.html";
//resultJsonFreelancer = Database::convertResultRowToJSON(resultFreelancer);
pqxx::result resultFreelancerTemplates = Database::executePreparedStatement_SELECT_FREELANCER_TEMPLATES(databaseConnection, freelancerID);
resultJsonFreelancerTemplate = Database::convertResultToJSON(resultFreelancerTemplates, "templates");
}