minor refactoring in config

implement pagination
This commit is contained in:
Tina_Azure
2023-05-04 22:22:21 +02:00
parent 4720ffdad5
commit 8d2033b316
8 changed files with 132 additions and 19 deletions

View File

@ -1,6 +1,7 @@
#include <vector>
#include <string>
#include <thread>
#include <map>
#include <pqxx/pqxx>
@ -36,9 +37,28 @@ int main(int argc, char *argv[]) {
* Freelancer Profile listing for customers
*/
CROW_ROUTE(app, "/").methods("POST"_method, "GET"_method)
([configuration]() {
([configuration](const crow::request& request) {
int selectedPage = 1;
if (!request.url_params.keys().empty()) {
string selectedPageString = request.url_params.get("page");
if (!selectedPageString.empty())
selectedPage = stoi(selectedPageString);
}
auto page = crow::mustache::load(TEMPLATE_CUSTOMER_INDEX_FREELANCER_LISTING);
crow::mustache::context ctx(Utilities::getFreelancerListing(configuration));
crow::mustache::context ctx(Utilities::getFreelancerListing(configuration, selectedPage));
if (configuration.itemsPerPage > 0) {
ctx[MUSTACHE_PAGINATION] = true;
vector<int> pages = Utilities::getFreelancerIndexPagination(configuration);
ctx[MUSTACHE_PAGINATION_NUMBERS] = pages;
if (selectedPage <= 1)
ctx[MUSTACHE_PAGINATION_PREVIOUS] = 1;
else
ctx[MUSTACHE_PAGINATION_PREVIOUS] = selectedPage - 1;
if (selectedPage >= pages.size())
ctx[MUSTACHE_PAGINATION_NEXT] = pages.size();
else
ctx[MUSTACHE_PAGINATION_NEXT] = selectedPage + 1;
}
return page.render(ctx);
});