Browse Source

增加评论表和服务

reloaded 5 years ago
parent
commit
e812d96220
7 changed files with 140 additions and 39 deletions
  1. 34 0
      app/controller/.comment.js
  2. 42 39
      app/controller/.news.js
  3. 19 0
      app/controller/comment.js
  4. 22 0
      app/model/comment.js
  5. 1 0
      app/model/news.js
  6. 4 0
      app/router.js
  7. 18 0
      app/service/comment.js

+ 34 - 0
app/controller/.comment.js

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

+ 42 - 39
app/controller/.news.js

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

+ 19 - 0
app/controller/comment.js

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

+ 22 - 0
app/model/comment.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 评论表
+const CommentSchema = {
+  newsid: { type: String, required: true, maxLength: 500 }, // 信息ID
+  uid: { type: String, required: true, maxLength: 500 }, // 用户ID
+  name: { type: String, required: true, maxLength: 500 }, // 用户名称
+  content: { type: String, required: true }, // 评论内容
+  public_time: { type: String, required: false, maxLength: 500 }, // 发布时间
+};
+
+
+const schema = new Schema(CommentSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Comment', schema, 'live_comment');
+};

+ 1 - 0
app/model/news.js

@@ -11,6 +11,7 @@ const NewsSchema = {
   orgin: { type: String, required: false, maxLength: 500 }, // 来源
   orgin: { type: String, required: false, maxLength: 500 }, // 来源
   publish: { type: String, required: false, maxLength: 500 }, // 发布者
   publish: { type: String, required: false, maxLength: 500 }, // 发布者
   publish_time: { type: String, required: false, maxLength: 500 }, // 发布时间
   publish_time: { type: String, required: false, maxLength: 500 }, // 发布时间
+  uid: { type: String, required: false, maxLength: 500 }, // 用户id
   content: { type: String, required: false }, // 正文
   content: { type: String, required: false }, // 正文
   picture: { type: String, required: false }, // 图片路径
   picture: { type: String, required: false }, // 图片路径
 };
 };

+ 4 - 0
app/router.js

@@ -59,6 +59,10 @@ module.exports = app => {
   router.resources('news', '/api/live/news', controller.news); // index、create、show、destroy
   router.resources('news', '/api/live/news', controller.news); // index、create、show、destroy
   router.post('news', '/api/live/news/update/:id', controller.news.update);
   router.post('news', '/api/live/news/update/:id', controller.news.update);
 
 
+  // 信息表设置路由
+  router.resources('comment', '/api/live/comment', controller.comment); // index、create、show、destroy
+  router.post('comment', '/api/live/comment/update/:id', controller.comment.update);
+
   // 私人聊天室表设置路由
   // 私人聊天室表设置路由
   router.resources('personroom', '/api/live/personroom', controller.personroom); // index、create、show、destroy
   router.resources('personroom', '/api/live/personroom', controller.personroom); // index、create、show、destroy
   router.post('personroom', '/api/live/personroom/update/:id', controller.personroom.update);
   router.post('personroom', '/api/live/personroom/update/:id', controller.personroom.update);

+ 18 - 0
app/service/comment.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 CommentService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'live_comment');
+    this.model = this.ctx.model.Comment;
+  }
+
+}
+
+module.exports = CommentService;