guhongwei 2 سال پیش
والد
کامیت
d6cf8e515f

+ 13 - 0
app/controller/collects.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.collects.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 我的收藏
+class CollectsController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.collects;
+  }
+}
+module.exports = CrudController(CollectsController, meta);

+ 65 - 0
app/controller/config/.collects.js

@@ -0,0 +1,65 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "user_name",
+      "video_id",
+      "title",
+      "img_url",
+      "view_num",
+      "time_num",
+      "follow_time",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "user_name",
+      "video_id",
+      "title",
+      "img_url",
+      "view_num",
+      "time_num",
+      "follow_time",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        user_id: "user_id",
+        user_name: "user_name",
+        video_id: "video_id",
+        title: "title",
+        view_num: "view_num",
+        time_num: "time_num",
+        follow_time: "follow_time",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  secollects: {
+    requestBody: ["!user_id", "!video_id"],
+  },
+};

+ 61 - 0
app/controller/config/.discuss.js

@@ -0,0 +1,61 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "user_name",
+      "user_img_url",
+      "video_id",
+      "video_title",
+      "content",
+      "create_time",
+      "create_address",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "user_name",
+      "user_img_url",
+      "video_id",
+      "video_title",
+      "content",
+      "create_time",
+      "create_address",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        user_id: "user_id",
+        user_name: "user_name",
+        video_id: "video_id",
+        video_title: "video_title",
+        create_time: "create_time",
+        create_address: "create_address",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 65 - 0
app/controller/config/.likes.js

@@ -0,0 +1,65 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "user_name",
+      "video_id",
+      "title",
+      "img_url",
+      "view_num",
+      "time_num",
+      "follow_time",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "user_name",
+      "video_id",
+      "title",
+      "img_url",
+      "view_num",
+      "time_num",
+      "follow_time",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        user_id: "user_id",
+        user_name: "user_name",
+        video_id: "video_id",
+        title: "title",
+        view_num: "view_num",
+        time_num: "time_num",
+        follow_time: "follow_time",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  selikes: {
+    requestBody: ["!user_id", "!video_id"],
+  },
+};

+ 13 - 0
app/controller/discuss.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.discuss.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 讨论
+class DiscussController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.discuss;
+  }
+}
+module.exports = CrudController(DiscussController, meta);

+ 13 - 0
app/controller/likes.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.likes.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 我的喜欢
+class LikesController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.likes;
+  }
+}
+module.exports = CrudController(LikesController, meta);

+ 34 - 0
app/model/collects.js

@@ -0,0 +1,34 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// 我的收藏
+const collects = {
+  user_id: { type: String, required: false, zh: '用户id' }, //
+  user_name: { type: String, required: false, zh: '用户名称' }, //
+  video_id: { type: String, required: false, zh: '视频id' }, //
+  title: { type: String, required: false, zh: '视频名称' }, //
+  img_url: { type: Array, required: false, zh: '图片' }, //
+  view_num: { type: String, required: false, zh: '观看次数' }, //
+  time_num: { type: String, required: false, zh: '时长' }, //
+  follow_time: { type: String, required: false, zh: '关注时间' }, //
+};
+const schema = new Schema(collects, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ user_id: 1 });
+schema.index({ user_name: 1 });
+schema.index({ video_id: 1 });
+schema.index({ title: 1 });
+schema.index({ view_num: 1 });
+schema.index({ time_num: 1 });
+schema.index({ follow_time: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Collects', schema, 'collects');
+};
+

+ 32 - 0
app/model/discuss.js

@@ -0,0 +1,32 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// 讨论
+const discuss = {
+  user_id: { type: String, required: false, zh: '用户id' }, //
+  user_name: { type: String, required: false, zh: '用户名称' }, //
+  user_img_url: { type: Array, required: false, zh: '用户头像' }, //
+  video_id: { type: String, required: false, zh: '视频id' }, //
+  video_title: { type: String, required: false, zh: '视频名称' }, //
+  content: { type: String, required: false, zh: '评论内容' }, //
+  create_time: { type: String, required: false, zh: '评论时间' }, //
+  create_address: { type: String, required: false, zh: '评论地点' }, //
+};
+const schema = new Schema(discuss, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ user_id: 1 });
+schema.index({ user_name: 1 });
+schema.index({ video_id: 1 });
+schema.index({ video_title: 1 });
+schema.index({ create_time: 1 });
+schema.index({ create_address: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Discuss', schema, 'discuss');
+};

+ 33 - 0
app/model/likes.js

@@ -0,0 +1,33 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// 我的喜欢
+const likes = {
+  user_id: { type: String, required: false, zh: '用户id' }, //
+  user_name: { type: String, required: false, zh: '用户名称' }, //
+  video_id: { type: String, required: false, zh: '视频id' }, //
+  title: { type: String, required: false, zh: '视频名称' }, //
+  img_url: { type: Array, required: false, zh: '视频图片' }, //
+  view_num: { type: String, required: false, zh: '观看次数' }, //
+  time_num: { type: String, required: false, zh: '时长' }, //
+  follow_time: { type: String, required: false, zh: '关注时间' }, //
+};
+const schema = new Schema(likes, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ user_id: 1 });
+schema.index({ user_name: 1 });
+schema.index({ video_id: 1 });
+schema.index({ title: 1 });
+schema.index({ view_num: 1 });
+schema.index({ time_num: 1 });
+schema.index({ follow_time: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Likes', schema, 'likes');
+};

+ 3 - 0
app/router.js

@@ -26,4 +26,7 @@ module.exports = app => {
   require('./z_router/scenetype')(app); // 视频场景分类
   require('./z_router/scenedata')(app); // 视频场景信息
   require('./z_router/videos')(app); // 视频
+  require('./z_router/likes')(app); // 我的喜欢
+  require('./z_router/collects')(app); // 我的收藏
+  require('./z_router/discuss')(app); // 讨论
 };

+ 20 - 0
app/service/collects.js

@@ -0,0 +1,20 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 我的收藏
+class CollectsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'collects');
+    this.model = this.ctx.model.Collects;
+  }
+  async secollects({ user_id, video_id }) {
+    const data = await this.model.findOne({ user_id, video_id });
+    if (data) return { id: data._id, is: true };
+    return { is: false };
+  }
+}
+
+module.exports = CollectsService;

+ 15 - 0
app/service/discuss.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 讨论
+class DiscussService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'discuss');
+    this.model = this.ctx.model.Discuss;
+  }
+}
+
+module.exports = DiscussService;

+ 20 - 0
app/service/likes.js

@@ -0,0 +1,20 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 我的喜欢
+class LikesService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'likes');
+    this.model = this.ctx.model.Likes;
+  }
+  async selikes({ user_id, video_id }) {
+    const data = await this.model.findOne({ user_id, video_id });
+    if (data) return { id: data._id, is: true };
+    return { is: false };
+  }
+}
+
+module.exports = LikesService;

+ 29 - 0
app/z_router/collects.js

@@ -0,0 +1,29 @@
+'use strict';
+// 测试接口
+const rKey = 'collects'; // routerKey,路由前缀变量
+const cKey = 'collects'; // controllerKey,controller名
+const zhKey = '我的收藏';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}/secollects`, controller: `${cKey}.secollects`, name: `${cKey}Secollects`, zh: `${zhKey}查询喜欢` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 28 - 0
app/z_router/discuss.js

@@ -0,0 +1,28 @@
+'use strict';
+// 测试接口
+const rKey = 'discuss'; // routerKey,路由前缀变量
+const cKey = 'discuss'; // controllerKey,controller名
+const zhKey = '讨论';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 29 - 0
app/z_router/likes.js

@@ -0,0 +1,29 @@
+'use strict';
+// 测试接口
+const rKey = 'likes'; // routerKey,路由前缀变量
+const cKey = 'likes'; // controllerKey,controller名
+const zhKey = '我的喜欢';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}/selikes`, controller: `${cKey}.selikes`, name: `${cKey}Selikes`, zh: `${zhKey}查询喜欢` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};