|
@@ -3,7 +3,7 @@ const loggerFactory = require('@alias/logger');
|
|
|
const logger = loggerFactory('growi:routes:apiv3:page'); // eslint-disable-line no-unused-vars
|
|
const logger = loggerFactory('growi:routes:apiv3:page'); // eslint-disable-line no-unused-vars
|
|
|
|
|
|
|
|
const express = require('express');
|
|
const express = require('express');
|
|
|
-// const { body } = require('express-validator');
|
|
|
|
|
|
|
+const { body } = require('express-validator');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
|
|
|
|
|
@@ -14,6 +14,101 @@ const router = express.Router();
|
|
|
* tags:
|
|
* tags:
|
|
|
* name: Page
|
|
* name: Page
|
|
|
*/
|
|
*/
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * components:
|
|
|
|
|
+ * schemas:
|
|
|
|
|
+ * Page:
|
|
|
|
|
+ * description: Page
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * _id:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: page ID
|
|
|
|
|
+ * example: 5e07345972560e001761fa63
|
|
|
|
|
+ * __v:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * description: DB record version
|
|
|
|
|
+ * example: 0
|
|
|
|
|
+ * commentCount:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * description: count of comments
|
|
|
|
|
+ * example: 3
|
|
|
|
|
+ * createdAt:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: date created at
|
|
|
|
|
+ * example: 2010-01-01T00:00:00.000Z
|
|
|
|
|
+ * creator:
|
|
|
|
|
+ * $ref: '#/components/schemas/User'
|
|
|
|
|
+ * extended:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * description: extend data
|
|
|
|
|
+ * example: {}
|
|
|
|
|
+ * grant:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * description: grant
|
|
|
|
|
+ * example: 1
|
|
|
|
|
+ * grantedUsers:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * description: granted users
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: user ID
|
|
|
|
|
+ * example: ["5ae5fccfc5577b0004dbd8ab"]
|
|
|
|
|
+ * lastUpdateUser:
|
|
|
|
|
+ * $ref: '#/components/schemas/User'
|
|
|
|
|
+ * liker:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * description: granted users
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: user ID
|
|
|
|
|
+ * example: []
|
|
|
|
|
+ * path:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: page path
|
|
|
|
|
+ * example: /
|
|
|
|
|
+ * redirectTo:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: redirect path
|
|
|
|
|
+ * example: ""
|
|
|
|
|
+ * revision:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: page revision
|
|
|
|
|
+ * seenUsers:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * description: granted users
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: user ID
|
|
|
|
|
+ * example: ["5ae5fccfc5577b0004dbd8ab"]
|
|
|
|
|
+ * status:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: status
|
|
|
|
|
+ * enum:
|
|
|
|
|
+ * - 'wip'
|
|
|
|
|
+ * - 'published'
|
|
|
|
|
+ * - 'deleted'
|
|
|
|
|
+ * - 'deprecated'
|
|
|
|
|
+ * example: published
|
|
|
|
|
+ * updatedAt:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: date updated at
|
|
|
|
|
+ * example: 2010-01-01T00:00:00.000Z
|
|
|
|
|
+ *
|
|
|
|
|
+ * LikeParams:
|
|
|
|
|
+ * description: LikeParams
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * pageId:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: page ID
|
|
|
|
|
+ * example: 5e07345972560e001761fa63
|
|
|
|
|
+ * isLiked:
|
|
|
|
|
+ * type: boolean
|
|
|
|
|
+ */
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
|
const accessTokenParser = require('../../middleware/access-token-parser')(crowi);
|
|
const accessTokenParser = require('../../middleware/access-token-parser')(crowi);
|
|
|
const loginRequired = require('../../middleware/login-required')(crowi);
|
|
const loginRequired = require('../../middleware/login-required')(crowi);
|
|
@@ -21,10 +116,39 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
const globalNotificationService = crowi.getGlobalNotificationService();
|
|
const globalNotificationService = crowi.getGlobalNotificationService();
|
|
|
const { Page, GlobalNotificationSetting } = crowi.models;
|
|
const { Page, GlobalNotificationSetting } = crowi.models;
|
|
|
- // const { ApiV3FormValidator } = crowi.middlewares;
|
|
|
|
|
|
|
+ const { ApiV3FormValidator } = crowi.middlewares;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const validator = {
|
|
|
|
|
+ likes: [
|
|
|
|
|
+ body('pageId').isString(),
|
|
|
|
|
+ body('isLiked').isBoolean(),
|
|
|
|
|
+ ],
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- // TODO swagger
|
|
|
|
|
- router.put('/likes', accessTokenParser, loginRequired, csrf, async(req, res) => {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * /page/likes:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [Page]
|
|
|
|
|
+ * summary: /page/likes
|
|
|
|
|
+ * description: Update liked status
|
|
|
|
|
+ * operationId: updateLikedStatus
|
|
|
|
|
+ * requestBody:
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/LikeParams'
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Succeeded to update liked status.
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/Page'
|
|
|
|
|
+ */
|
|
|
|
|
+ router.put('/likes', accessTokenParser, loginRequired, csrf, validator.likes, ApiV3FormValidator, async(req, res) => {
|
|
|
const { pageId, isLiked } = req.body;
|
|
const { pageId, isLiked } = req.body;
|
|
|
|
|
|
|
|
let page;
|
|
let page;
|