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);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
41
templates/customer_FreelancerListing.html
Normal file
41
templates/customer_FreelancerListing.html
Normal 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>
|
26
templates/customer_FreelancerListing_NOTFOUND.html
Normal file
26
templates/customer_FreelancerListing_NOTFOUND.html
Normal 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>
|
Reference in New Issue
Block a user