diff options
Diffstat (limited to 'server/controllers/api/pods.ts')
-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 | } |