aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorYohan Boniface <yohanboniface@free.fr>2019-04-09 11:02:02 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-04-09 11:02:02 +0200
commitc100a6142e6571312db9f6407698a21a08b593fb (patch)
treec80ac9c7754b8f5b133255e003557937e415ee23 /server/controllers/api
parent8ce1ba6e3efe0a688d6a0b57e8201cde33ad7aac (diff)
downloadPeerTube-c100a6142e6571312db9f6407698a21a08b593fb.tar.gz
PeerTube-c100a6142e6571312db9f6407698a21a08b593fb.tar.zst
PeerTube-c100a6142e6571312db9f6407698a21a08b593fb.zip
Add /accounts/:username/ratings endpoint (#1756)
* Add /users/me/videos/ratings endpoint * Move ratings endpoint from users to accounts * /accounts/:name/ratings: add support for rating= and sort= * Restrict ratings list to owner * Wording and better way to ensure current account
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts38
1 files changed, 36 insertions, 2 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index adbf69781..aa01ea1eb 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -1,16 +1,25 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects, getServerActor } from '../../helpers/utils' 2import { getFormattedObjects, getServerActor } from '../../helpers/utils'
3import { 3import {
4 authenticate,
4 asyncMiddleware, 5 asyncMiddleware,
5 commonVideosFiltersValidator, 6 commonVideosFiltersValidator,
7 videoRatingValidator,
6 optionalAuthenticate, 8 optionalAuthenticate,
7 paginationValidator, 9 paginationValidator,
8 setDefaultPagination, 10 setDefaultPagination,
9 setDefaultSort, 11 setDefaultSort,
10 videoPlaylistsSortValidator 12 videoPlaylistsSortValidator,
13 videoRatesSortValidator
11} from '../../middlewares' 14} from '../../middlewares'
12import { accountNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' 15import {
16 accountNameWithHostGetValidator,
17 accountsSortValidator,
18 videosSortValidator,
19 ensureAuthUserOwnsAccountValidator
20} from '../../middlewares/validators'
13import { AccountModel } from '../../models/account/account' 21import { AccountModel } from '../../models/account/account'
22import { AccountVideoRateModel } from '../../models/account/account-video-rate'
14import { VideoModel } from '../../models/video/video' 23import { VideoModel } from '../../models/video/video'
15import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 24import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
16import { VideoChannelModel } from '../../models/video/video-channel' 25import { VideoChannelModel } from '../../models/video/video-channel'
@@ -61,6 +70,18 @@ accountsRouter.get('/:accountName/video-playlists',
61 asyncMiddleware(listAccountPlaylists) 70 asyncMiddleware(listAccountPlaylists)
62) 71)
63 72
73accountsRouter.get('/:accountName/ratings',
74 authenticate,
75 asyncMiddleware(accountNameWithHostGetValidator),
76 ensureAuthUserOwnsAccountValidator,
77 paginationValidator,
78 videoRatesSortValidator,
79 setDefaultSort,
80 setDefaultPagination,
81 videoRatingValidator,
82 asyncMiddleware(listAccountRatings)
83)
84
64// --------------------------------------------------------------------------- 85// ---------------------------------------------------------------------------
65 86
66export { 87export {
@@ -138,3 +159,16 @@ async function listAccountVideos (req: express.Request, res: express.Response) {
138 159
139 return res.json(getFormattedObjects(resultList.data, resultList.total)) 160 return res.json(getFormattedObjects(resultList.data, resultList.total))
140} 161}
162
163async function listAccountRatings (req: express.Request, res: express.Response) {
164 const account = res.locals.account
165
166 const resultList = await AccountVideoRateModel.listByAccountForApi({
167 accountId: account.id,
168 start: req.query.start,
169 count: req.query.count,
170 sort: req.query.sort,
171 type: req.query.rating
172 })
173 return res.json(getFormattedObjects(resultList.rows, resultList.count))
174}