guhongwei 4 سال پیش
والد
کامیت
274fc99443
5فایلهای تغییر یافته به همراه90 افزوده شده و 0 حذف شده
  1. 34 0
      app/controller/.flower.js
  2. 16 0
      app/controller/flower.js
  3. 19 0
      app/model/flower.js
  4. 4 0
      app/router.js
  5. 17 0
      app/service/flower.js

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

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

+ 16 - 0
app/controller/flower.js

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

+ 19 - 0
app/model/flower.js

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

+ 4 - 0
app/router.js

@@ -106,4 +106,8 @@ module.exports = app => {
   router.resources('channelVideo', '/api/live/channelvideo', controller.channelVideo); // index、create、show、destroy
   router.resources('channelVideo', '/api/live/channelvideo', controller.channelVideo); // index、create、show、destroy
   router.post('channelVideo', '/api/live/channelvideo/update/:id', controller.channelVideo.update);
   router.post('channelVideo', '/api/live/channelvideo/update/:id', controller.channelVideo.update);
 
 
+  // 花表
+  router.resources('flower', '/api/live/flower', controller.flower); // index、create、show、destroy
+  router.post('flower', '/api/live/flower/update/:id', controller.flower.update);
+
 };
 };

+ 17 - 0
app/service/flower.js

@@ -0,0 +1,17 @@
+'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 FlowerService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'flower');
+    this.model = this.ctx.model.Flower;
+  }
+}
+
+module.exports = FlowerService;