Redirection template

Handle @alias via the redirection template
This commit is contained in:
Tina_Azure
2023-04-05 02:24:42 +02:00
parent 2738fdaf5c
commit 1a1908a814
3 changed files with 91 additions and 1 deletions

View File

@ -48,6 +48,12 @@ namespace Database {
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_TEMPLATES = "selectFreelancerTemplates";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_TEMPLATES = "select id, name, content from templates where freelancerid = $1 order by id;";
/*
* Name and Statement for prepared statement to select an alias and its route via the alias name
*/
const static std::string PREPARED_STATEMENT_SELECT_ALIAS = "selectAlias";
const static std::string SQL_STATEMENT_SELECT_ALIAS = "select aliasname, route, routeparameter, routevalue from aliasroutes where aliasname = $1;";
/*
* Selects freelancers, their basicInfo and if the commissions are closed/open ordered by name.
* Delivers if the commission limit has been reached and if the commissions are closed based on the accepted/completed state of the freelancers requests
@ -180,6 +186,18 @@ namespace Database {
return result;
}
/*
* Executes the prepared statement SELECT_ALIAS
* Takes an open pqxx::connection and the alias name to select by
*/
pqxx::result executePreparedStatement_SELECT_ALIAS(pqxx::connection &connection, std::string aliasName) {
connection.prepare(PREPARED_STATEMENT_SELECT_ALIAS, SQL_STATEMENT_SELECT_ALIAS);
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_ALIAS, aliasName);
work.commit();
return result;
}
/*

View File

@ -25,7 +25,7 @@ int main() {
/*
* Freelancer Profile listing for customers
*/
CROW_ROUTE(app, "/").methods("POST"_method)
CROW_ROUTE(app, "/").methods("POST"_method, "GET"_method)
([databaseURI]() {
pqxx::connection databaseConnection(databaseURI);
pqxx::result result = Database::executeStatement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE(databaseConnection);
@ -37,6 +37,33 @@ int main() {
return page.render(ctx);
});
/*
* Freelancer Profile listing for customers
*/
CROW_ROUTE(app, "/@<string>")
([databaseURI](string alias) {
pqxx::connection databaseConnection(databaseURI);
pqxx::result resultAlias = Database::executePreparedStatement_SELECT_ALIAS(databaseConnection, alias);
crow::json::wvalue resultJsonAlias;
string redirectionHTML = "alias_Redirect.html";
if (resultAlias.size() > 0) {
resultJsonAlias = Database::convertResultRowToJSON(resultAlias);
}
else
{
//If the alias does not exist redirect back to the index.
resultJsonAlias["route"] = "/";
}
auto page = crow::mustache::load(redirectionHTML);
crow::mustache::context ctx(resultJsonAlias);
return page.render(ctx);
});
/*
* Freelancer Profile Page for customers
*/