mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
feat: add pagination metadata to all list endpoints
- Add pagination.helper.js with addPaginationMeta function - Add pagination info to: most-popular, search, new-release, newly-added, latest-updated, az-list, filter, category, status - Pagination includes: currentPage, totalPages, totalItems, itemsPerPage, hasNext, hasPrev - Fix creatorInfo middleware to include message field
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
import { extractFilter } from "../extractors/filter.extractor.js";
|
||||
import { getCache, setCache, TTL } from "../helper/cache.helper.js";
|
||||
import { addPaginationMeta } from "../helper/pagination.helper.js";
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// CONTROLLER: FILTER
|
||||
@@ -47,6 +48,7 @@ import { getCache, setCache, TTL } from "../helper/cache.helper.js";
|
||||
const getFilter = async (req, res, next) => {
|
||||
try {
|
||||
const params = req.query;
|
||||
const page = params.page || 1;
|
||||
const cacheKey = `filter_${JSON.stringify(params, Object.keys(params).sort())}`;
|
||||
const cached = getCache(cacheKey);
|
||||
if (cached) {
|
||||
@@ -57,8 +59,9 @@ const getFilter = async (req, res, next) => {
|
||||
if (Array.isArray(params.type)) params.type = params.type.join(",");
|
||||
if (Array.isArray(params.status)) params.status = params.status.join(",");
|
||||
const data = await extractFilter(params);
|
||||
setCache(cacheKey, data, TTL.genres);
|
||||
res.json({ success: true, results: data });
|
||||
const response = addPaginationMeta(data, page);
|
||||
setCache(cacheKey, response, TTL.genres);
|
||||
res.json({ success: true, results: response });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user