Commit 10b1eff1 by 张权

dev:新增项目文档分类

1 parent 8ff936b4
/*
* @Author: huyue
* @Date: 2021-09-09 16:06:39
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 15:20:12
*/
// app/controller/classify.js
const Controller = require("egg").Controller;
class ClassifyController extends Controller {
constructor(ctx) {
super(ctx);
this.request = ctx.request;
this.classifyService = ctx.service.docClassify;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
async getList() {
const query = this.ctx.query;
const result = await this.classifyService.findAll(query);
this.ctx.body = this.ServerResponse.Success(result);
}
async create({ request: { body } }) {
const p = body;
console.log('p: ', p);
const result = await this.classifyService.create(p);
this.ctx.body = this.ServerResponse.Success(result);
}
async update({ request: { body } }) {
const p = body;
console.log(this.ctx.request.query,999)
const result = await this.classifyService.update(p);
this.ctx.body = this.ServerResponse.Success(result);
}
async delete({ request: { body } }) {
const p = body;
console.log(p)
const result = await this.classifyService.delete(p);
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = ClassifyController;
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('doc_classify', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
title: {
type: DataTypes.STRING(255),
allowNull: false
},
description: {
type: DataTypes.STRING(255),
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: true
},
updated_at: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 'doc_classify'
});
Model.associate = function() {
}
return Model;
};
\ No newline at end of file
......@@ -27,6 +27,10 @@ module.exports = app => {
allowNull: false,
defaultValue: 'n'
},
classify_id:{
type: DataTypes.INTEGER(11),
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
allowNull: false
......
......@@ -14,6 +14,12 @@ module.exports = (app) => {
router.patch("/documentation/update", controller.documentation.update);
router.patch("/documentation/delete", controller.documentation.delete);
//文档分类
router.get("/docClassify/getList", controller.docClassify.getList);
router.post("/docClassify/create", controller.docClassify.create);
router.patch("/docClassify/update", controller.docClassify.update);
router.patch("/docClassify/delete", controller.docClassify.delete);
//评论
router.get("/commons/getList", controller.commons.getList);
router.post("/commons/create", controller.commons.create);
......
/*
* @Author: huyue
* @Date: 2021-09-09 15:45:14
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 11:20:31
*/
// app/service/Classify.js
const Service = require("egg").Service;
class ClassifyService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const { DocClassify } = this.app.model;
this.DI = DocClassify;
}
/** 搜索分类列表 */
async findAll({ pager = {} }) {
return await this.DI.findAll({
attributes: [
"id",
"title",
"description"
],
});
}
/** 新增分类 */
async create(params) {
const now = Date.now();
const p = await this.DI.create({
title: params.title,
description: params.description,
created_at: now,
updated_at: now,
});
return {
id: p.id,
};
}
async update(params) {
const now = Date.now();
const p = await this.DI.update(
{
title: params.title,
description: params.description,
updated_at: now
},
{
where: {
id: params.id,
},
}
);
return {
id: p,
};
}
async delete(params) {
const p = await this.DI.destroy(
{
where: {
id: params.id,
},
}
);
return {
id: p,
};
}
}
module.exports = ClassifyService;
......@@ -22,10 +22,12 @@ class DocumentationService extends Service {
}
/** 搜索列表 */
async findAll({ pager = {} }) {
async findAll(param) {
let where = { del_flag: "n" }
if(param.classifyId) where.classify_id = param.classifyId
return await this.DI.findAll({
where: { del_flag: "n" },
attributes: ["id", "doc_title", "doc_url", "doc_description"],
where,
attributes: ["id", "doc_title","classify_id", "doc_url", "doc_description"],
});
}
......@@ -34,6 +36,7 @@ class DocumentationService extends Service {
const now = Date.now();
const p = await this.DI.create({
doc_title: params.docTitle,
classify_id: params.classifyId,
doc_url: params.docUrl,
doc_description: params.docDescription,
created_at: now,
......@@ -51,6 +54,7 @@ class DocumentationService extends Service {
doc_title: params.docTitle,
doc_url: params.docUrl,
doc_description: params.docDescription,
classify_id: params.classify_id,
// created_at: now,
updated_at: now,
// del_flag: 'n'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!