diff options
author | Yohan Boniface <yohanboniface@free.fr> | 2019-04-09 11:02:02 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-04-09 11:02:02 +0200 |
commit | c100a6142e6571312db9f6407698a21a08b593fb (patch) | |
tree | c80ac9c7754b8f5b133255e003557937e415ee23 /server/controllers/api | |
parent | 8ce1ba6e3efe0a688d6a0b57e8201cde33ad7aac (diff) | |
download | PeerTube-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.ts | 38 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' | 2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' |
3 | import { | 3 | import { |
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' |
12 | import { accountNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' | 15 | import { |
16 | accountNameWithHostGetValidator, | ||
17 | accountsSortValidator, | ||
18 | videosSortValidator, | ||
19 | ensureAuthUserOwnsAccountValidator | ||
20 | } from '../../middlewares/validators' | ||
13 | import { AccountModel } from '../../models/account/account' | 21 | import { AccountModel } from '../../models/account/account' |
22 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | ||
14 | import { VideoModel } from '../../models/video/video' | 23 | import { VideoModel } from '../../models/video/video' |
15 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 24 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
16 | import { VideoChannelModel } from '../../models/video/video-channel' | 25 | import { 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 | ||
73 | accountsRouter.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 | ||
66 | export { | 87 | export { |
@@ -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 | |||
163 | async 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 | } | ||