重构后端,完善获取资源/下载列表、博客列表接口
This commit is contained in:
22
Server/src/APIs/GetBlogList.ts
Normal file
22
Server/src/APIs/GetBlogList.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { API } from "../Plugs/API/API";
|
||||
import ServerStdResponse from "../ServerStdResponse";
|
||||
import MySQLConnection from '../Plugs/MySQLConnection'
|
||||
|
||||
// 获取博客列表
|
||||
class GetBlogList extends API {
|
||||
constructor() {
|
||||
super('GET', '/blogList');
|
||||
}
|
||||
private defaultAccessLevel = 6;
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
let blogListRes = await MySQLConnection.execute('SELECT uuid, title, description, publish_time from blog WHERE access_level > ? ORDER BY publish_time DESC',[this.defaultAccessLevel]);
|
||||
if(!blogListRes){
|
||||
this.logger.error('查询时数据库发生错误');
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({...ServerStdResponse.OK, data: blogListRes});
|
||||
}
|
||||
}
|
||||
|
||||
export default GetBlogList;
|
||||
29
Server/src/APIs/GetResourceList.ts
Normal file
29
Server/src/APIs/GetResourceList.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { API } from "../Plugs/API/API";
|
||||
import ServerStdResponse from "../ServerStdResponse";
|
||||
import MySQLConnection from '../Plugs/MySQLConnection'
|
||||
|
||||
// 获取资源列表
|
||||
class GetResourceList extends API {
|
||||
constructor() {
|
||||
super('GET', '/resourceList');
|
||||
}
|
||||
private typeList = ['resource', 'download']
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
let { type } = data;
|
||||
if(!type){
|
||||
return res.json(ServerStdResponse.PARAMS_MISSING);
|
||||
}
|
||||
if(!this.typeList.includes(type)){
|
||||
return res.json(ServerStdResponse.INVALID_PARAMS);
|
||||
}
|
||||
let resourceListRes = await MySQLConnection.execute('SELECT * from resource WHERE type = ? ORDER BY recommand ASC',[type]);
|
||||
if(!resourceListRes){
|
||||
this.logger.error('查询时数据库发生错误');
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({...ServerStdResponse.OK, data: resourceListRes});
|
||||
}
|
||||
}
|
||||
|
||||
export default GetResourceList;
|
||||
16
Server/src/APIs/GetTest.ts
Normal file
16
Server/src/APIs/GetTest.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { API } from "../Plugs/API/API";
|
||||
import ServerStdResponse from "../ServerStdResponse";
|
||||
import MySQLConnection from '../Plugs/MySQLConnection'
|
||||
|
||||
// 测试接口
|
||||
class GetTest extends API {
|
||||
constructor() {
|
||||
super('GET', '/test');
|
||||
}
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
res.json(ServerStdResponse.OK);
|
||||
}
|
||||
}
|
||||
|
||||
export default GetTest;
|
||||
Reference in New Issue
Block a user