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); 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);
});

View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h2>Freelancer: {{freelancername}}</h2>
<div>Basic Profile:</div>
<div>{{freelancerbasicinformation}}</div>
<br>
<div>Detailed Profile:</div>
<div>{{freelancergeneralinformation}}</div>
<br>
<a href="/">Return to freelancer selection</a>
<br>
<table>
{{#templates}}
<tr>
<th><a href="/customer/{{freelancername}}/template/{{name}}/{{id}}">{{name}}</a></th>
<th>{{content}}</th>
</tr>
{{/templates}}
</table>
</body>
</html>

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h1>Freelancer: {{selectedfreelancername}} Could not be found!</h1>
<h2><a href="/">Return to freelancer selection</a></h2>
</body>
</html>