소스 검색

get admin home data from server

yusuketk 6 년 전
부모
커밋
60d29ef5c3
3개의 변경된 파일86개의 추가작업 그리고 2개의 파일을 삭제
  1. 10 2
      src/client/js/services/AdminHomeContainer.js
  2. 74 0
      src/server/routes/apiv3/admin-home.js
  3. 2 0
      src/server/routes/apiv3/index.js

+ 10 - 2
src/client/js/services/AdminHomeContainer.js

@@ -41,8 +41,16 @@ export default class AdminCustomizeContainer extends Container {
    */
   async retrieveAdminHomeData() {
     try {
-      // [TODO GW-727] create api endpoint for retrieve admin home data
-      // const response = await this.appContainer.apiv3.get('/home/');
+      const response = await this.appContainer.apiv3.get('/admin-home/');
+      const { adminHomeParams } = response.data;
+
+      this.setState({
+        growiVersion: adminHomeParams.growiVersion,
+        nodeVersion: adminHomeParams.nodeVersion,
+        npmVersion: adminHomeParams.npmVersion,
+        yarnVersion: adminHomeParams.yarnVersion,
+        installedPlugins: adminHomeParams.installedPlugins,
+      });
     }
     catch (err) {
       logger.error(err);

+ 74 - 0
src/server/routes/apiv3/admin-home.js

@@ -0,0 +1,74 @@
+const express = require('express');
+
+const router = express.Router();
+
+/**
+ * @swagger
+ *  tags:
+ *    name: adminHome
+ */
+
+/**
+ * @swagger
+ *
+ *  components:
+ *    schemas:
+ *      SystemInformationParams:
+ *        type: object
+ *        properties:
+ *          growiVersion:
+ *            type: String
+ *            description: version of growi
+ *          nodeVersion:
+ *            type: String
+ *            description: version of node
+ *          npmVersion:
+ *            type: String
+ *            description: version of npm
+ *          yarnVersion:
+ *            type: String
+ *            description: version of yarn
+ *      InstalledPluginsParams:
+ *        type: object
+ *        properties:
+ *          installedPlugins:
+ *            type: object
+ *            description: installed plugins
+ */
+
+module.exports = (crowi) => {
+  const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
+  const adminRequired = require('../../middleware/admin-required')(crowi);
+
+  /**
+   * @swagger
+   *
+   *    /admin-home/:
+   *      get:
+   *        tags: [adminHome]
+   *        description: Get adminHome paramaters
+   *        responses:
+   *          200:
+   *            description: params of adminHome
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    adminHomeParams:
+   *                      type: object
+   *                      description: adminHome params
+   */
+  router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
+    const adminHomeParams = {
+      growiVersion: 'x.y.x',
+      nodeVersion: 'x.y.x',
+      npmVersion: 'x.y.x',
+      yarnVersion: 'x.y.x',
+      installedPlugins: { ex: 'x.y.z' },
+    };
+
+    return res.apiv3({ adminHomeParams });
+  });
+
+  return router;
+};

+ 2 - 0
src/server/routes/apiv3/index.js

@@ -13,6 +13,8 @@ module.exports = (crowi) => {
 
   router.use('/healthcheck', require('./healthcheck')(crowi));
 
+  router.use('/admin-home', require('./admin-home')(crowi));
+
   router.use('/markdown-setting', require('./markdown-setting')(crowi));
 
   router.use('/customize-setting', require('./customize-setting')(crowi));