Commit c68d064b by luyt

add;项目文档描述api 编辑删除新增

     问题记录新增查询 联调
     项目主页新增编辑评论删除 联调
1 parent 55d4b349
/*
* @Author: huyue
* @Date: 2021-09-02 17:57:28
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 15:20:28
*/
// app/controller/commons.js
const Controller = require('egg').Controller;
class commonsController extends Controller {
constructor(ctx) {
super(ctx);
this.request = ctx.request;
this.commonsService = ctx.service.commons;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
async getList() {
const query = this.ctx.query
const result = await this.commonsService.findAll(query);
this.ctx.body = this.ServerResponse.Success(result);
}
async create({ request: { body } }){
const p = body
const result = await this.commonsService.create(p)
this.ctx.body = this.ServerResponse.Success(result)
}
// async update({ request: { body } }){
// const p = body
// const result = await this.commonsService.update(p)
// this.ctx.body = this.ServerResponse.Success(result)
// }
// async delete({ request: { body } }){
// const p = body
// const result = await this.commonsService.delete(p)
// this.ctx.body = this.ServerResponse.Success(result)
// }
}
module.exports = commonsController;
\ No newline at end of file
......@@ -5,7 +5,7 @@
* @Last Modified time: 2021-09-10 15:20:12
*/
// app/controller/documentation.js
const Controller = require('egg').Controller;
const Controller = require("egg").Controller;
class DocumentationController extends Controller {
constructor(ctx) {
......@@ -17,16 +17,26 @@ class DocumentationController extends Controller {
}
/** 搜索列表 */
async getList() {
const query = this.ctx.query
const query = this.ctx.query;
const result = await this.documentationService.findAll(query);
this.ctx.body = this.ServerResponse.Success(result);
}
/** 新增文档 */
/** 新增文档 */
async create({ request: { body } }) {
const p = body
const result = await this.documentationService.create(p)
this.ctx.body = this.ServerResponse.Success(result)
const p = body;
const result = await this.documentationService.create(p);
this.ctx.body = this.ServerResponse.Success(result);
}
async update({ request: { body } }) {
const p = body;
const result = await this.documentationService.update(p);
this.ctx.body = this.ServerResponse.Success(result);
}
async delete({ request: { body } }) {
const p = body;
const result = await this.documentationService.delete(p);
this.ctx.body = this.ServerResponse.Success(result);
}
}
......
......@@ -22,6 +22,22 @@ class ProjectController extends Controller {
const result = await this.projectService.findAll(query);
this.ctx.body = this.ServerResponse.Success(result);
}
async create({ request: { body } }){
const p = body
const result = await this.projectService.create(p)
this.ctx.body = this.ServerResponse.Success(result)
}
async update({ request: { body } }){
const p = body
const result = await this.projectService.update(p)
this.ctx.body = this.ServerResponse.Success(result)
}
async delete({ request: { body } }){
const p = body
const result = await this.projectService.delete(p)
this.ctx.body = this.ServerResponse.Success(result)
}
}
module.exports = ProjectController;
\ No newline at end of file
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('commons_info', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
user_id: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: '1'
},
project_id: {
type: DataTypes.STRING(255),
allowNull: false
},
content: {
type: DataTypes.TEXT,
allowNull: true
},
created_at: {
type: DataTypes.DATE,
allowNull: true
},
updated_at: {
type: DataTypes.DATE,
allowNull: true
},
}, {
tableName: 'commons_info'
});
Model.associate = function() {
}
return Model;
};
......@@ -25,7 +25,7 @@ module.exports = app => {
del_flag: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: 'Y'
defaultValue: 'n'
},
created_at: {
type: DataTypes.DATE,
......
......@@ -30,17 +30,26 @@ module.exports = app => {
type: DataTypes.STRING(255),
allowNull: true
},
developer_name: {
type: DataTypes.STRING(255),
allowNull: true
},
technology: {
type: DataTypes.STRING(255),
allowNull: true
},
create_time: {
create_at: {
type: DataTypes.DATE,
allowNull: false
allowNull: true
},
update_time: {
update_at: {
type: DataTypes.DATE,
allowNull: false
allowNull: true
},
del_flag:{
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: 'n'
}
}, {
tableName: 'project_info'
......
......@@ -3,6 +3,15 @@ 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('/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
/*
* @Author: huyue
* @Date: 2021-09-02 14:15:48
* @Last Modified by: huyue
* @Last Modified time: 2021-09-02 14:43:02
*/
// app/service/Commons.js
const Service = require("egg").Service;
class CommonsService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const { CommonsInfo } = this.app.model;
this.DI = CommonsInfo;
}
/** 搜索列表 */
async findAll({ project_id }) {
return await this.DI.findAll({
where: { project_id: project_id },
attributes: [
"id",
"user_id",
"project_id",
"content",
"created_at",
"updated_at",
],
});
}
/** 新增评论 */
async create(params) {
const now = Date.now();
const p = await this.DI.create({
//目前还没有用户,所以都是默认值 ’1‘
// user_id:'',
project_id: params.project_id,
content: params.content,
created_at: now,
updated_at: now,
});
// console.log(p);
return {
id: p.id,
};
}
}
module.exports = CommonsService;
......@@ -6,7 +6,7 @@
*/
// app/service/documentation.js
const Service = require('egg').Service
const Service = require("egg").Service;
class DocumentationService extends Service {
constructor(ctx) {
super(ctx);
......@@ -17,36 +17,70 @@ class DocumentationService extends Service {
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
DocumentationInfo
} = this.app.model
this.DI = DocumentationInfo
const { DocumentationInfo } = this.app.model;
this.DI = DocumentationInfo;
}
/** 搜索列表 */
async findAll({
pager = {},
}) {
async findAll({ pager = {} }) {
return await this.DI.findAll({
attributes: ['id', 'doc_title', 'doc_url', 'doc_description']
where: { del_flag: "n" },
attributes: ["id", "doc_title", "doc_url", "doc_description"],
});
}
/** 新增文档 */
async create(params) {
const now = Date.now()
const now = Date.now();
const p = await this.DI.create({
doc_title: params.docTitle,
doc_url: params.docUrl,
doc_description: params.docDescription,
created_at: now,
updated_at: now,
del_flag: 'Y'
})
del_flag: "n",
});
return {
id: p.id
id: p.id,
};
}
async update(params) {
const now = Date.now();
const p = await this.DI.update(
{
doc_title: params.docTitle,
doc_url: params.docUrl,
doc_description: params.docDescription,
// 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 = DocumentationService
module.exports = DocumentationService;
......@@ -6,7 +6,7 @@
*/
// app/service/project.js
const Service = require('egg').Service
const Service = require("egg").Service;
class ProjectService extends Service {
constructor(ctx) {
super(ctx);
......@@ -17,19 +17,86 @@ class ProjectService extends Service {
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
ProjectInfo
} = this.app.model
this.PI = ProjectInfo
const { ProjectInfo } = this.app.model;
this.PI = ProjectInfo;
}
async findAll({
pager = {},
}) {
async findAll({ pager = {} }) {
return await this.PI.findAll({
attributes: ['id', 'project_title', 'project_description', 'developer_name', 'config_name', 'test_url', 'product_url', 'technology']
where: { del_flag: "n" },
attributes: [
"id",
"project_title",
"project_description",
"developer_name",
"config_name",
"test_url",
"product_url",
"technology",
],
});
}
async create(params) {
console.log("params: ", params);
const now = Date.now();
const p = await this.PI.create({
project_title: params.project_title,
project_description: params.project_description,
developer_name: params.developer_name,
config_name: params.config_name,
test_url: params.test_url,
product_url: params.product_url,
technology: params.technology,
created_at: now,
updated_at: now,
del_flag: "n",
});
return {
id: p.id,
};
}
async update(params) {
// console.log('params: ', params);
const now = Date.now();
const p = await this.PI.update(
{
project_title: params.project_title,
project_description: params.project_description,
developer_name: params.developer_name,
config_name: params.config_name,
test_url: params.test_url,
product_url: params.product_url,
technology: params.technology,
// created_at: now,
updated_at: now,
// del_flag: "n",
},
{
where: {
id: params.id,
}
}
);
return {
id: p,
};
}
async delete(params) {
const p = await this.PI.update(
{
del_flag: "y",
},
{
where: {
id: params.id,
}
}
)
return {
id: p,
};
}
}
module.exports = ProjectService
module.exports = ProjectService;
......@@ -20,13 +20,15 @@ module.exports = appInfo => {
};
config.cors = {
// 任何地址都可以访问
origin: ctx => ctx.get('origin'), //这种方式是允许所有的IP+端口跨域访问
// origin: ctx => ctx.get('origin'), //这种方式是允许所有的IP+端口跨域访问
// 任何地址都可以访问
origin:"*",
// 指定地址才可以访问
// origin: 'http://localhost:8080',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
// allowMethods: '*',
// allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
allowMethods: '*',
// cookie跨域配置
credentials: true
credentials: true,
};
return config
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!