mirror of
https://github.com/strapi/strapi.git
synced 2025-09-09 08:39:45 +00:00
Add pagination
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
9438230648
commit
cbafb3ef92
@ -22,13 +22,19 @@ module.exports = {
|
|||||||
return ctx.forbidden();
|
return ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
const method = has('_q', query) ? 'search' : 'find';
|
const method = has('_q', query) ? 'searchPage' : 'findPage';
|
||||||
|
|
||||||
const permissionQuery = permissionChecker.buildPermissionQuery(query);
|
const permissionQuery = permissionChecker.buildPermissionQuery(query);
|
||||||
|
|
||||||
const results = await getService('entity-manager')[method](permissionQuery, model);
|
const { results, pagination } = await getService('entity-manager')[method](
|
||||||
|
permissionQuery,
|
||||||
|
model
|
||||||
|
);
|
||||||
|
|
||||||
ctx.body = results.map(entity => permissionChecker.sanitizeOutput(entity));
|
ctx.body = {
|
||||||
|
results: results.map(entity => permissionChecker.sanitizeOutput(entity)),
|
||||||
|
pagination,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async findOne(ctx) {
|
async findOne(ctx) {
|
||||||
|
@ -322,6 +322,19 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- Collection Types content management
|
- Collection Types content management
|
||||||
description: Get a list of entries
|
description: Get a list of entries
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
results:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/entity'
|
||||||
|
pagination:
|
||||||
|
$ref: '#/components/schemas/pagination'
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- Collection Types content management
|
- Collection Types content management
|
||||||
@ -473,6 +486,18 @@ components:
|
|||||||
- type: string
|
- type: string
|
||||||
- type: integer
|
- type: integer
|
||||||
|
|
||||||
|
pagination:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
page:
|
||||||
|
type: integer
|
||||||
|
pageSize:
|
||||||
|
type: integer
|
||||||
|
pageCount:
|
||||||
|
type: integer
|
||||||
|
total:
|
||||||
|
type: integer
|
||||||
|
|
||||||
entity:
|
entity:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
|
@ -48,10 +48,18 @@ module.exports = {
|
|||||||
return strapi.entityService.find({ params }, { model });
|
return strapi.entityService.find({ params }, { model });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
findPage(params, model) {
|
||||||
|
return strapi.entityService.findPage({ params }, { model });
|
||||||
|
},
|
||||||
|
|
||||||
search(params, model) {
|
search(params, model) {
|
||||||
return strapi.entityService.search({ params }, { model });
|
return strapi.entityService.search({ params }, { model });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
searchPage(params, model) {
|
||||||
|
return strapi.entityService.searchPage({ params }, { model });
|
||||||
|
},
|
||||||
|
|
||||||
count(params, model) {
|
count(params, model) {
|
||||||
return strapi.entityService.count({ params }, { model });
|
return strapi.entityService.count({ params }, { model });
|
||||||
},
|
},
|
||||||
|
@ -33,6 +33,10 @@ module.exports = ({ db, eventHub, entityValidator }) => ({
|
|||||||
return db.query(model).find(params, populate);
|
return db.query(model).find(params, populate);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
findPage({ params, populate }, { model }) {
|
||||||
|
return db.query(model).findPage(params, populate);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promise to fetch record
|
* Promise to fetch record
|
||||||
*
|
*
|
||||||
@ -148,6 +152,10 @@ module.exports = ({ db, eventHub, entityValidator }) => ({
|
|||||||
return db.query(model).search(params);
|
return db.query(model).search(params);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
searchPage({ params }, { model }) {
|
||||||
|
return db.query(model).searchPage(params);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promise to count searched records
|
* Promise to count searched records
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user