diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-13 17:39:41 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | 7a7724e66e4533523083e7336cd0d0c747c4a33b (patch) | |
tree | 805299eb9c6829158cd17e5a823a84a3a54d8209 /server/controllers/api | |
parent | 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (diff) | |
download | PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.gz PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.zst PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.zip |
Handle follow/accept
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/pods.ts | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts index 43df3f66f..aa07b17f6 100644 --- a/server/controllers/api/pods.ts +++ b/server/controllers/api/pods.ts | |||
@@ -1,16 +1,27 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects } from '../../helpers' | 2 | import { getFormattedObjects } from '../../helpers' |
3 | import { getApplicationAccount } from '../../helpers/utils' | ||
3 | import { database as db } from '../../initializers/database' | 4 | import { database as db } from '../../initializers/database' |
4 | import { asyncMiddleware, paginationValidator, podsSortValidator, setPagination, setPodsSort } from '../../middlewares' | 5 | import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares' |
6 | import { setFollowingSort } from '../../middlewares/sort' | ||
7 | import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort' | ||
5 | 8 | ||
6 | const podsRouter = express.Router() | 9 | const podsRouter = express.Router() |
7 | 10 | ||
8 | podsRouter.get('/', | 11 | podsRouter.get('/following', |
9 | paginationValidator, | 12 | paginationValidator, |
10 | podsSortValidator, | 13 | followingSortValidator, |
11 | setPodsSort, | 14 | setFollowingSort, |
12 | setPagination, | 15 | setPagination, |
13 | asyncMiddleware(listPods) | 16 | asyncMiddleware(listFollowing) |
17 | ) | ||
18 | |||
19 | podsRouter.get('/followers', | ||
20 | paginationValidator, | ||
21 | followersSortValidator, | ||
22 | setFollowersSort, | ||
23 | setPagination, | ||
24 | asyncMiddleware(listFollowers) | ||
14 | ) | 25 | ) |
15 | 26 | ||
16 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
@@ -21,8 +32,16 @@ export { | |||
21 | 32 | ||
22 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |
23 | 34 | ||
24 | async function listPods (req: express.Request, res: express.Response, next: express.NextFunction) { | 35 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { |
25 | const resultList = await db.Pod.listForApi(req.query.start, req.query.count, req.query.sort) | 36 | const applicationAccount = await getApplicationAccount() |
37 | const resultList = await db.Account.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort) | ||
38 | |||
39 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
40 | } | ||
41 | |||
42 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
43 | const applicationAccount = await getApplicationAccount() | ||
44 | const resultList = await db.Account.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort) | ||
26 | 45 | ||
27 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 46 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
28 | } | 47 | } |