Просмотр исходного кода

feat: 补完API接口,完成project的mock接口

Jinyao 5 лет назад
Родитель
Сommit
86f32e2c5f
9 измененных файлов с 172 добавлено и 34 удалено
  1. 56 12
      mock/routers/project.js
  2. 3 1
      src/api/index.ts
  3. 57 0
      src/api/pipeline.ts
  4. 5 0
      src/api/prefix.ts
  5. 11 5
      src/api/project.ts
  6. 0 7
      src/api/requirement.ts
  7. 15 0
      src/api/tree.ts
  8. 2 9
      src/api/user.ts
  9. 23 0
      src/typings/project.d.ts

+ 56 - 12
mock/routers/project.js

@@ -6,21 +6,65 @@ const wrapper = require('../wrapper');
 
 const { Random } = Mock;
 
-router.get('/all',
+const groups = [101, 102, 103, 104];
+
+router.get('/:projectId',
+  (req, res) => {
+    const { projectId: id } = req.params;
+    res.json(wrapper(
+      Mock.mock(
+        {
+          description: Random.csentence(5, 40),
+          gitRemoteUrl: Random.url('http', 'gitlab.seecoder.cn'),
+          groupId: 101,
+          id,
+          name: 'string',
+        },
+      ),
+    ));
+  });
+
+router.post('/create',
+  (req, res) => {
+    const { body } = req;
+    body.id = 101;
+    res.json(wrapper(body));
+  });
+
+router.get('/listByUser/:userId',
   (req, res) => {
-    const query = req.query || {};
-    const { userId } = query;
     res.json(wrapper(
-      Mock.mock({
-        userId,
-        'projectList|1-10': [
-          {
-            'projectId|+1': 100,
-            name: Random.ctitle(10),
-          },
-        ],
-      }),
+      Mock.mock(Mock.mock({
+        'data|5-10': [{
+          'id|+1': 100,
+          description: Random.csentence(5, 40),
+          gitRemoteUrl: Random.url('http', 'gitlab.seecoder.cn'),
+          'groupId|1': groups,
+          name: Random.cname(),
+        }],
+      }).data),
     ));
   });
 
+router.get('/listByGroup/:groupId',
+  (req, res) => {
+    const { groupId } = req.params;
+    res.json(wrapper(
+      Mock.mock(Mock.mock({
+        'data|3-5': [{
+          'id|+1': 100,
+          description: Random.csentence(5, 40),
+          gitRemoteUrl: Random.url('http', 'gitlab.seecoder.cn'),
+          groupId,
+          name: Random.cname(),
+        }],
+      }).data),
+    ));
+  });
+
+router.get('/delete/:projectId',
+  (req, res) => {
+    res.json(wrapper({}));
+  });
+
 module.exports = router;

+ 3 - 1
src/api/index.ts

@@ -1,9 +1,11 @@
 import * as UserAPI from './user';
 import * as ProjectAPI from './project';
-import * as RequirementAPI from './requirement';
+import * as RequirementAPI from './tree';
+import * as PipelineAPI from './pipeline';
 
 export {
   UserAPI,
   ProjectAPI,
   RequirementAPI,
+  PipelineAPI,
 };

+ 57 - 0
src/api/pipeline.ts

@@ -0,0 +1,57 @@
+import axios from 'axios';
+
+import { PIPELINE_PREFIX, DEPLOYMENT_PREFIX } from './prefix';
+
+interface PipelinePayload {
+  projectId: number;
+  pipeline: number;
+}
+
+type CreatePipelinePayload = PipelinePayload & {
+  name: string;
+  templateName: string;
+}
+
+type UpdatePipelinePayload = PipelinePayload & {
+  configJson: string;
+}
+
+export const deletePipeline = (pipeline: PipelinePayload) => axios.delete(`${PIPELINE_PREFIX}`, {
+  params: pipeline,
+});
+
+export const getPipeline = (pipeline: PipelinePayload) => axios.get(`${PIPELINE_PREFIX}`, {
+  params: pipeline,
+});
+
+export const createPipeline = (createPipelinePayload: CreatePipelinePayload) => axios.post(`${PIPELINE_PREFIX}`, createPipelinePayload);
+
+export const updatePipeline = (updatePipelinePayload: UpdatePipelinePayload) => axios.put(`${PIPELINE_PREFIX}/config`, {
+  params: updatePipelinePayload,
+});
+
+export const getPipelineHistory = (pipeline: PipelinePayload) => axios.get(`${PIPELINE_PREFIX}/history/list`, {
+  params: pipeline,
+});
+
+export const getPipelinesByProjectId = (projectId: number) => axios.get(`${PIPELINE_PREFIX}/list`, {
+  params: {
+    projectId,
+  },
+});
+
+export const deleteInstance = (deploymentId: number) => axios.delete(`${DEPLOYMENT_PREFIX}`, {
+  params: {
+    deploymentId,
+  },
+});
+
+export const triggerDeployment = (pipeline: PipelinePayload) => axios.post(`${DEPLOYMENT_PREFIX}`, {
+  params: pipeline,
+});
+
+export const getAllDeployment = (projectId: number) => axios.get(`${PIPELINE_PREFIX}/list`, {
+  params: {
+    projectId,
+  },
+});

+ 5 - 0
src/api/prefix.ts

@@ -0,0 +1,5 @@
+export const PIPELINE_PREFIX = '/pipelines';
+export const DEPLOYMENT_PREFIX = '/deployments';
+export const USER_PREFIX = '/user';
+export const TREE_PREFIX = '/tree';
+export const PROJECT_PREFIX = '/project';

+ 11 - 5
src/api/project.ts

@@ -1,7 +1,13 @@
 import axios from '@/utils/axios';
 
-export const getProjectList = (userId: number) => axios.get('/project/all', {
-  params: {
-    userId,
-  },
-});
+import { PROJECT_PREFIX } from './prefix';
+
+export const getProjectById = (projectId: number) => axios.get(`${PROJECT_PREFIX}/${projectId}`);
+
+export const createProject = (project: Project) => axios.post(`${PROJECT_PREFIX}/create`, project);
+
+export const getProjectListByUserId = (userId: number) => axios.get(`${PROJECT_PREFIX}/listByUser/${userId}`);
+
+export const getProjectListByGroupId = (groupId: number) => axios.get(`${PROJECT_PREFIX}/listByGroup/${groupId}`);
+
+export const deleteProject = (projectId: string) => axios.get(`${PROJECT_PREFIX}/delete/${projectId}`);

+ 0 - 7
src/api/requirement.ts

@@ -1,7 +0,0 @@
-import axios from '@/utils/axios';
-
-export const addChild = (parentId: number) => axios.post('/requirement', {
-  parentId,
-});
-
-export const deleteNode = (id: number) => axios.delete(`/requirement/${id}`);

+ 15 - 0
src/api/tree.ts

@@ -0,0 +1,15 @@
+import axios from '@/utils/axios';
+
+import { TREE_PREFIX } from './prefix';
+
+export const getAllTreeNodes = () => axios.get(`${TREE_PREFIX}/all`);
+
+export const insertTreeNode = (treenode: TreeNode) => axios.post(`${TREE_PREFIX}/node`, treenode);
+
+export const updateTreeNode = (treenode: TreeNode) => axios.put(`${TREE_PREFIX}/node`, treenode);
+
+export const deleteTreeNode = (nodeId: number) => axios.delete(`${TREE_PREFIX}/node/${nodeId}`);
+
+export const addChildNode = (parentId: number) => axios.post(`${TREE_PREFIX}/subNode/${parentId}`);
+
+export const getTreeNodesByProjectId = (projectId: number) => axios.get(`${TREE_PREFIX}/${projectId}`);

+ 2 - 9
src/api/user.ts

@@ -1,12 +1,5 @@
 import axios from '@/utils/axios';
 
-export const getUserInfo = (userId: number) => axios.get(`/user/info/${userId}`);
+import { USER_PREFIX } from './prefix';
 
-export const getUserInfo2 = (userId: number) => axios.get('/user/info', {
-  params: { userId },
-});
-
-export const post = () => axios.post('/user/post', {
-  userId: 3,
-  gender: 'male',
-});
+export const getUserInfo = () => axios.get(`${USER_PREFIX}/self`);

+ 23 - 0
src/typings/project.d.ts

@@ -2,4 +2,27 @@ declare interface Project {
   id: number;
   name: string;
   description: string;
+  groupId: number;
+  gitRemoteUrl: string;
+}
+
+declare type TreeNodeType = '0:需求' | '1:任务';
+declare type TreeNodeState = '0:已创建' | '1:进行中' | '2:已结束';
+
+declare interface TreeNode {
+  deep: number;
+  description: string;
+  endTime: string;
+  groupId: number;
+  id: number;
+  leaf: boolean;
+  parentId: number;
+  priority: number;
+  projectId: number;
+  startTime: string;
+  state: TreeNodeState;
+  timeToTake: number;
+  title: string;
+  type: TreeNodeType;
+  userId: number;
 }