diff --git a/src/main.cpp b/src/main.cpp index d7da9a7..328b4c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,44 @@ int main() { return page.render(ctx); }); + /* + * Freelancer Profile Page for customers + */ + CROW_ROUTE(app, "/customer//") + ([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); + }); diff --git a/templates/customer_FreelancerListing.html b/templates/customer_FreelancerListing.html new file mode 100644 index 0000000..e7df187 --- /dev/null +++ b/templates/customer_FreelancerListing.html @@ -0,0 +1,41 @@ + + + + + + +

Freelancer: {{freelancername}}

+
Basic Profile:
+
{{freelancerbasicinformation}}
+
+
Detailed Profile:
+
{{freelancergeneralinformation}}
+
+ Return to freelancer selection +
+ + {{#templates}} + + + + + {{/templates}} +
{{name}}{{content}}
+ + \ No newline at end of file diff --git a/templates/customer_FreelancerListing_NOTFOUND.html b/templates/customer_FreelancerListing_NOTFOUND.html new file mode 100644 index 0000000..a55fa7d --- /dev/null +++ b/templates/customer_FreelancerListing_NOTFOUND.html @@ -0,0 +1,26 @@ + + + + + + +

Freelancer: {{selectedfreelancername}} Could not be found!

+

Return to freelancer selection

+ + \ No newline at end of file