Commit 42a4f148 by luyt

feat:1.前端文档-后端api添加项目分类,列表,新增,编辑,删除

2.项目数据库project_info添加分类字段,并调整列表,新增,编辑接口,以分类来获取
3.新增项目移动功能-支持移动到类一个分类中
1 parent c0904d6b
/*
* @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.classify;
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;
const result = await this.classifyService.update(p);
this.ctx.body = this.ServerResponse.Success(result);
}
async delete({ request: { body } }) {
const p = body;
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('classify_info', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
classify:{
type: DataTypes.STRING(255),
allowNull: false
},
classify_title: {
type: DataTypes.STRING(255),
allowNull: false
},
classify_description: {
type: DataTypes.STRING(255),
allowNull: false
},
created_at: {
type: DataTypes.DATE,
allowNull: true
},
updated_at: {
type: DataTypes.DATE,
allowNull: true
},
del_flag:{
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: 'n'
}
}, {
tableName: 'classify_info'
});
Model.associate = function() {
}
return Model;
};
......@@ -58,6 +58,11 @@ module.exports = app => {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: 'n'
},
classify: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: 'other'
}
}, {
tableName: 'project_info'
......
// app/router.js
module.exports = app => {
module.exports = (app) => {
const { router, controller } = app;
// router.get('/', controller.home.index);
router.get('/project/getList', controller.project.getList)
router.post('/project/create', controller.project.create)
router.patch('/project/update', controller.project.update)
router.patch('/project/delete', controller.project.delete)
//项目
router.get("/project/getList", controller.project.getList);
router.post("/project/create", controller.project.create);
router.patch("/project/update", controller.project.update);
router.patch("/project/delete", controller.project.delete);
router.get('/documentation/getList', controller.documentation.getList)
router.post('/documentation/create', controller.documentation.create)
router.patch('/documentation/update', controller.documentation.update)
router.patch('/documentation/delete', controller.documentation.delete)
//文档相关
router.get("/documentation/getList", controller.documentation.getList);
router.post("/documentation/create", controller.documentation.create);
router.patch("/documentation/update", controller.documentation.update);
router.patch("/documentation/delete", controller.documentation.delete);
router.get('/commons/getList', controller.commons.getList)
router.post('/commons/create', controller.commons.create)
}
\ No newline at end of file
//评论
router.get("/commons/getList", controller.commons.getList);
router.post("/commons/create", controller.commons.create);
//分类信息
router.get("/classify/getList", controller.classify.getList);
router.post("/classify/create", controller.classify.create);
router.patch("/classify/update", controller.classify.update);
router.patch("/classify/delete", controller.classify.delete);
};
/*
* @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 { ClassifyInfo } = this.app.model;
this.DI = ClassifyInfo;
}
/** 搜索分类列表 */
async findAll({ pager = {} }) {
return await this.DI.findAll({
where: { del_flag: "n" },
attributes: [
"id",
"classify",
"classify_title",
"classify_description",
"del_flag",
],
});
}
/** 新增分类 */
async create(params) {
const now = Date.now();
const p = await this.DI.create({
classify: params.classify,
classify_title: params.classify_title,
classify_description: params.classify_description,
created_at: now,
updated_at: now,
del_flag: "n",
});
return {
id: p.id,
};
}
async update(params) {
const now = Date.now();
const p = await this.DI.update(
{
classify: params.classify,
classify_title: params.classify_title,
classify_description: params.classify_description,
// created_at: now,
updated_at: now,
// del_flag: "n",
},
{
where: {
id: params.id,
},
}
);
return {
id: p,
};
}
async delete(params) {
const p = await this.DI.update(
{
del_flag: "y",
},
{
where: {
id: params.id,
},
}
);
return {
id: p,
};
}
}
module.exports = ClassifyService;
......@@ -21,9 +21,9 @@ class ProjectService extends Service {
this.PI = ProjectInfo;
}
async findAll({ pager = {} }) {
async findAll({ classify,pager = {} }) {
return await this.PI.findAll({
where: { del_flag: "n" },
where: { del_flag: "n" ,classify},
attributes: [
"id",
"project_title",
......@@ -34,12 +34,13 @@ class ProjectService extends Service {
"product_url",
"technology",
"git_url",
"git_id"
"git_id",
"classify"
],
});
}
async create(params) {
console.log("params: ", params);
// console.log("params: ", params);
const now = Date.now();
const p = await this.PI.create({
......@@ -55,6 +56,7 @@ class ProjectService extends Service {
created_at: now,
updated_at: now,
del_flag: "n",
classify: params.classify
});
return {
id: p.id,
......@@ -77,6 +79,7 @@ class ProjectService extends Service {
// created_at: now,
updated_at: now,
// del_flag: "n",
classify: params.classify
},
{
where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!