Freelancer Profile page with Templates
This commit is contained in:
38
src/main.cpp
38
src/main.cpp
@ -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);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user