Bläddra i källkod

Merge branch 'master' of http://git.cc-lotus.info/service-platform/service-live

lrf402788946 5 år sedan
förälder
incheckning
cef3b69729

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

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

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

@@ -0,0 +1,55 @@
+module.exports = {
+  create: {
+    requestBody: [
+      'column_id',
+      'column_name',
+      '!title',
+      'orgin',
+      'publish',
+      'content',
+      'picture'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'column_id',
+      'column_name',
+      '!title',
+      'orgin',
+      'publish',
+      'content',
+      'picture'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        column_id : 'column_id',
+        column_name : 'column_name',
+        title : 'title',
+        orgin : 'orgin',
+        publish: 'publish',
+        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 ColumnSchema = {
+  name: { type: String, required: true, maxLength: 500 }, // 栏目名称
+  site: { type: String, required: false, 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, 'live_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 NewsSchema = {
+  column_id: { type: String, required: false, maxLength: 500 }, // 栏目id
+  column_name: { type: String, required: false, maxLength: 500 }, // 栏目名称
+  title: { type: String, required: false, maxLength: 500 }, // 标题
+  orgin: { type: String, required: false, maxLength: 500 }, // 来源
+  publish: { type: String, required: false, maxLength: 500 }, // 发布者
+  content: { type: String, required: false }, // 正文
+  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, 'live_news');
+};

+ 7 - 0
app/router.js

@@ -36,4 +36,11 @@ module.exports = app => {
   router.post('dock', '/api/live/dock/apply/:id', controller.dock.apply);
   router.post('dock', '/api/live/dock/apply/:dock_id/check/:id', controller.dock.check);
 
+  // 栏目表设置路由
+  router.resources('column', '/api/live/column', controller.column); // index、create、show、destroy
+  router.post('column', '/api/live/column/update/:id', controller.column.update);
+
+  // 信息表设置路由
+  router.resources('news', '/api/live/news', controller.news); // index、create、show、destroy
+  router.post('news', '/api/live/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;