Переглянути джерело

科技服务服务端更新

reloaded 5 роки тому
батько
коміт
07004bafff

+ 12 - 0
.travis.yml

@@ -0,0 +1,12 @@
+sudo: false
+language: node_js
+node_js:
+  - '10'
+before_install:
+  - npm i npminstall -g
+install:
+  - npminstall
+script:
+  - npm run ci
+after_script:
+  - npminstall codecov && codecov

+ 37 - 0
app/controller/.column.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      '!name'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name: 'name'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 52 - 0
app/controller/.news.js

@@ -0,0 +1,52 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!column_name',
+      '!column_id',
+      '!title',
+      '!orgin',
+      '!content',
+      'picture'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      '!column_name',
+      '!column_id',
+      '!title',
+      '!orgin',
+      '!content',
+      'picture'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        column_name : '!column_name',
+        column_id : '!column_id',
+        title : '!title',
+        orgin : '!orgin',
+        content : '!content',
+        picture : 'picture'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 19 - 0
app/controller/column.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.column.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class ColumnController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.column;
+  }
+
+
+}
+
+module.exports = CrudController(ColumnController, meta);

+ 19 - 0
app/controller/news.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.news.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class NewsController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.news;
+  }
+
+
+}
+
+module.exports = CrudController(NewsController, meta);

+ 19 - 0
app/model/column.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+
+// 栏目表
+const ColumnSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 栏目名称
+};
+
+
+const schema = new Schema(ColumnSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Column', schema, 'column');
+};

+ 24 - 0
app/model/news.js

@@ -0,0 +1,24 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+
+// 信息表
+const NewsSchema = {
+  column_name: { type: String, required: true, maxLength: 500 }, // 栏目名称
+  column_id: { type: String, required: true, maxLength: 500 }, // 栏目id
+  title: { type: String, required: true, maxLength: 500 }, // 标题
+  orgin: { type: String, required: true, maxLength: 500 }, // 来源
+  content: { type: String, required: true }, // 正文
+  picture: { type: String, required: false }, // 图片路径
+};
+
+
+const schema = new Schema(NewsSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('News', schema, 'news');
+};

+ 8 - 0
app/router.js

@@ -6,4 +6,12 @@
 module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
+
+  // 栏目表设置路由
+  router.resources('column', '/api/column', controller.column); // index、create、show、destroy
+  router.post('column', '/api/column/update/:id', controller.column.update);
+
+  // 信息表设置路由
+  router.resources('news', '/api/news', controller.news); // index、create、show、destroy
+  router.post('news', '/api/news/update/:id', controller.news.update);
 };

+ 18 - 0
app/service/column.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ColumnService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'column');
+    this.model = this.ctx.model.Column;
+  }
+
+}
+
+module.exports = ColumnService;

+ 18 - 0
app/service/news.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class NewsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'news');
+    this.model = this.ctx.model.News;
+  }
+
+}
+
+module.exports = NewsService;

+ 14 - 0
appveyor.yml

@@ -0,0 +1,14 @@
+environment:
+  matrix:
+    - nodejs_version: '10'
+
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm i npminstall && node_modules\.bin\npminstall
+
+test_script:
+  - node --version
+  - npm --version
+  - npm run test
+
+build: off