aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-16 22:31:45 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-16 22:31:45 +0200
commit5c39adb7313e0696aabb4b71196ab7b0b378c359 (patch)
treeac44b67890509338b984f8cbf11660dc77cdd0fd /server/controllers/api
parent089ff2f2046fdbaf9531726eea1f8c6726ebf0c0 (diff)
downloadPeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.gz
PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.zst
PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.zip
Server: add user list sort/pagination
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/v1/users.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js
index 704df770c..975e25e68 100644
--- a/server/controllers/api/v1/users.js
+++ b/server/controllers/api/v1/users.js
@@ -11,6 +11,10 @@ const logger = require('../../../helpers/logger')
11const middlewares = require('../../../middlewares') 11const middlewares = require('../../../middlewares')
12const admin = middlewares.admin 12const admin = middlewares.admin
13const oAuth = middlewares.oauth 13const oAuth = middlewares.oauth
14const pagination = middlewares.pagination
15const sort = middlewares.sort
16const validatorsPagination = middlewares.validators.pagination
17const validatorsSort = middlewares.validators.sort
14const validatorsUsers = middlewares.validators.users 18const validatorsUsers = middlewares.validators.users
15 19
16const User = mongoose.model('User') 20const User = mongoose.model('User')
@@ -18,9 +22,16 @@ const Video = mongoose.model('Video')
18 22
19const router = express.Router() 23const router = express.Router()
20 24
21router.get('/', listUsers)
22router.get('/me', oAuth.authenticate, getUserInformation) 25router.get('/me', oAuth.authenticate, getUserInformation)
23 26
27router.get('/',
28 validatorsPagination.pagination,
29 validatorsSort.usersSort,
30 sort.setUsersSort,
31 pagination.setPagination,
32 listUsers
33)
34
24router.post('/', 35router.post('/',
25 oAuth.authenticate, 36 oAuth.authenticate,
26 admin.ensureIsAdmin, 37 admin.ensureIsAdmin,
@@ -73,10 +84,10 @@ function getUserInformation (req, res, next) {
73} 84}
74 85
75function listUsers (req, res, next) { 86function listUsers (req, res, next) {
76 User.list(function (err, usersList) { 87 User.listForApi(req.query.start, req.query.count, req.query.sort, function (err, usersList, usersTotal) {
77 if (err) return next(err) 88 if (err) return next(err)
78 89
79 res.json(getFormatedUsers(usersList)) 90 res.json(getFormatedUsers(usersList, usersTotal))
80 }) 91 })
81} 92}
82 93
@@ -145,7 +156,7 @@ function success (req, res, next) {
145 156
146// --------------------------------------------------------------------------- 157// ---------------------------------------------------------------------------
147 158
148function getFormatedUsers (users) { 159function getFormatedUsers (users, usersTotal) {
149 const formatedUsers = [] 160 const formatedUsers = []
150 161
151 users.forEach(function (user) { 162 users.forEach(function (user) {
@@ -153,6 +164,7 @@ function getFormatedUsers (users) {
153 }) 164 })
154 165
155 return { 166 return {
167 total: usersTotal,
156 data: formatedUsers 168 data: formatedUsers
157 } 169 }
158} 170}