Freelancer Profile page with Templates

This commit is contained in:
Tina_Azure
2023-04-03 00:00:10 +02:00
parent 33b7196690
commit 17c0123c19
3 changed files with 105 additions and 0 deletions

View File

@ -36,6 +36,44 @@ int main() {
return page.render(ctx);
});
/*
* Freelancer Profile Page for customers
*/
CROW_ROUTE(app, "/customer/<string>/<int>")
([databaseURI](string freelancerName, int freelancerID) {
pqxx::connection databaseConnection(databaseURI);
pqxx::result resultFreelancer = Database::executePreparedStatement_SELECT_FREELANCER(databaseConnection, freelancerID);
string freelancerHTML = "customer_FreelancerListing_NOTFOUND.html";
//crow::json::wvalue resultJsonFreelancer;
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");
}
auto page = crow::mustache::load(freelancerHTML);
crow::mustache::context ctx(resultJsonFreelancerTemplate);
if (resultFreelancer.size() != 0){
/*
* puts freelancer data into context
* todo::solve this with less hardcoding
*/
for (int i = 0; i < resultFreelancer.columns(); ++i) {
string freelancerColumn = resultFreelancer.column_name(i);
ctx["freelancer" + freelancerColumn] = resultFreelancer.at(0).at(i).c_str();
}
}
ctx["freelancerid"] = freelancerID;
ctx["selectedfreelancername"] = freelancerName;
return page.render(ctx);
});