This commit is contained in:
parent
a0e6d40679
commit
954755fbc3
19 changed files with 356 additions and 321 deletions
|
|
@ -22,20 +22,7 @@ using namespace drogon::orm;
|
|||
|
||||
void EbookController::getAllEbooks(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
int page = 1;
|
||||
int limit = 20;
|
||||
|
||||
auto pageParam = req->getParameter("page");
|
||||
auto limitParam = req->getParameter("limit");
|
||||
|
||||
if (!pageParam.empty()) {
|
||||
try { page = std::stoi(pageParam); } catch (...) {}
|
||||
}
|
||||
if (!limitParam.empty()) {
|
||||
try { limit = std::min(std::stoi(limitParam), 50); } catch (...) {}
|
||||
}
|
||||
|
||||
int offset = (page - 1) * limit;
|
||||
auto pagination = parsePagination(req, 20, 50);
|
||||
|
||||
auto dbClient = app().getDbClient();
|
||||
*dbClient << "SELECT e.id, e.title, e.description, e.file_path, e.cover_path, "
|
||||
|
|
@ -48,7 +35,7 @@ void EbookController::getAllEbooks(const HttpRequestPtr &req,
|
|||
"WHERE e.is_public = true AND e.status = 'ready' "
|
||||
"ORDER BY e.created_at DESC "
|
||||
"LIMIT $1 OFFSET $2"
|
||||
<< static_cast<int64_t>(limit) << static_cast<int64_t>(offset)
|
||||
<< static_cast<int64_t>(pagination.limit) << static_cast<int64_t>(pagination.offset)
|
||||
>> [callback](const Result& r) {
|
||||
Json::Value resp;
|
||||
resp["success"] = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue