Commit 0d19ed36 by 胡悦

first

0 parents
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
typings/
.nyc_output/
/*
* @Author: huyue
* @Date: 2021-09-06 15:04:10
* @Last Modified by: huyue
* @Last Modified time: 2021-09-06 15:04:30
*/
const { SUCCESS, ERROR } = require("./server_response_code");
module.exports = class ServerResponse {
constructor(status, msg, data) {
this.status = status;
this.msg = msg;
this.data = data;
}
isSuccess() {
return this.status === SUCCESS;
}
getStatus() {
return this.status;
}
getData() {
return this.data;
}
getMsg() {
return this.msg;
}
static Success(data = null,respo = SUCCESS) {
const { code,message } = respo
return new ServerResponse(code,message, data);
}
static Error(respo = ERROR) {
const { code=ERROR.code,message,data } = respo
return new ServerResponse(code,message, data);
}
};
/*
* @Author: huyue
* @Date: 2021-09-06 15:04:32
* @Last Modified by: huyue
* @Last Modified time: 2021-09-06 15:04:32
*/
module.exports = {
SUCCESS: {code:0,message:'SUCCESS!'},
ERROR: {code:1,message:'ERROR!'},
NEED_LOGIN: {code:10,message:'请登录!'},
NO_AUTH: {code:20,message:'无权限访问!'},
ILLEGAL_ARGUMENT: {code:2,message:'参数错误!'}
};
/*
* @Author: huyue
* @Date: 2021-09-09 16:06:39
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 15:20:12
*/
// app/controller/documentation.js
const Controller = require('egg').Controller;
class DocumentationController extends Controller {
constructor(ctx) {
super(ctx);
this.request = ctx.request;
this.documentationService = ctx.service.documentation;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
/** 搜索列表 */
async getList() {
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)
}
}
module.exports = DocumentationController;
\ No newline at end of file
// app/controller/home.js
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
this.ctx.body = 'Hello world';
}
}
module.exports = HomeController;
\ No newline at end of file
/*
* @Author: huyue
* @Date: 2021-09-02 17:57:28
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 15:20:28
*/
// app/controller/project.js
const Controller = require('egg').Controller;
class ProjectController extends Controller {
constructor(ctx) {
super(ctx);
this.request = ctx.request;
this.projectService = ctx.service.project;
this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse;
}
async getList() {
const query = this.ctx.query
const result = await this.projectService.findAll(query);
this.ctx.body = this.ServerResponse.Success(result);
}
}
module.exports = ProjectController;
\ No newline at end of file
/*
* @Author: huyue
* @Date: 2021-09-06 15:05:31
* @Last Modified by: huyue
* @Last Modified time: 2021-09-06 15:05:31
*/
const ServerResponse = require("../common/server_response");
const ServerResponseCode = require("../common/server_response_code");
module.exports = {
ServerResponse,
ServerResponseCode
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('documentation_info', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
doc_title: {
type: DataTypes.STRING(255),
allowNull: false
},
doc_description: {
type: DataTypes.STRING(255),
allowNull: false
},
doc_url: {
type: DataTypes.STRING(255),
allowNull: false
},
del_flag: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: 'Y'
},
created_at: {
type: DataTypes.DATE,
allowNull: false
},
updated_at: {
type: DataTypes.DATE,
allowNull: false
}
}, {
tableName: 'documentation_info'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('project_info', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
project_title: {
type: DataTypes.STRING(255),
allowNull: false
},
project_description: {
type: DataTypes.STRING(255),
allowNull: false
},
config_name: {
type: DataTypes.STRING(255),
allowNull: true
},
test_url: {
type: DataTypes.STRING(255),
allowNull: true
},
product_url: {
type: DataTypes.STRING(255),
allowNull: true
},
technology: {
type: DataTypes.STRING(255),
allowNull: true
},
create_time: {
type: DataTypes.DATE,
allowNull: false
},
update_time: {
type: DataTypes.DATE,
allowNull: false
}
}, {
tableName: 'project_info'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('user_info', {
user_name: {
type: DataTypes.STRING(255),
allowNull: false
},
password: {
type: DataTypes.STRING(255),
allowNull: false
},
create_time: {
type: DataTypes.DATE,
allowNull: false
},
update_time: {
type: DataTypes.DATE,
allowNull: false
},
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
}
}, {
tableName: 'user_info'
});
Model.associate = function() {
}
return Model;
};
// app/router.js
module.exports = app => {
const { router, controller } = app;
// router.get('/', controller.home.index);
router.get('/project/getList', controller.project.getList)
router.get('/documentation/getList', controller.documentation.getList)
router.post('/documentation/create', controller.documentation.create)
}
\ No newline at end of file
/*
* @Author: huyue
* @Date: 2021-09-09 15:45:14
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 11:20:31
*/
// app/service/documentation.js
const Service = require('egg').Service
class DocumentationService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
DocumentationInfo
} = this.app.model
this.DI = DocumentationInfo
}
/** 搜索列表 */
async findAll({
pager = {},
}) {
return await this.DI.findAll({
attributes: ['id', 'doc_title', 'doc_url', 'doc_description']
});
}
/** 新增文档 */
async create(params) {
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'
})
return {
id: p.id
}
}
}
module.exports = DocumentationService
/*
* @Author: huyue
* @Date: 2021-09-02 14:42:42
* @Last Modified by: huyue
* @Last Modified time: 2021-09-10 15:20:35
*/
// app/service/project.js
const Service = require('egg').Service
class ProjectService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
this._reg_models_alias_();
}
/**
* 绑定model 在 this 上的 别名
*/
_reg_models_alias_() {
const {
ProjectInfo
} = this.app.model
this.PI = ProjectInfo
}
async findAll({
pager = {},
}) {
return await this.PI.findAll({
attributes: ['id', 'project_title', 'project_description', 'developer_name', 'config_name', 'test_url', 'product_url', 'technology']
});
}
}
module.exports = ProjectService
/*
* @Author: huyue
* @Date: 2021-09-02 14:15:48
* @Last Modified by: huyue
* @Last Modified time: 2021-09-02 14:43:02
*/
// app/service/user.js
const Service = require('egg').Service
class UserService extends Service {
constructor(ctx) {
super(ctx);
this.helper = ctx.helper;
// this._reg_models_alias_();
}
}
module.exports = UserService
// config/config.default.js
module.exports = appInfo => {
const config = {}
config.sequelize = {
dialect: 'mysql',
host: '192.168.3.222',
port: 3307,
database: 'huyue',
username: 'root',
password: 'Msd^*$@online'
}
config.keys = '123456'
config.security = {
csrf: {
enable: false,
ignoreJSON: true
},
domainWhiteList: ["http://localhost:8080", "http://192.168.2.9:8080"] //允许访问接口的白名单
};
return config
}
\ No newline at end of file
exports.sequelize = {
enable: true,
package: 'egg-sequelize',
};
{
"name": "egg-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "egg-bin dev"
},
"author": "huyue",
"license": "ISC",
"dependencies": {
"egg": "^2.30.0",
"egg-sequelize": "^5.2.1",
"mysql2": "^2.3.0"
},
"devDependencies": {
"egg-bin": "^4.16.4",
"sequelize-cli": "^6.2.0"
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!