后端实现Resources修改接口
This commit is contained in:
26
Server/src/APIs/Console/DelResource.ts
Normal file
26
Server/src/APIs/Console/DelResource.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { API } from "../../Plugs/API/API";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import MySQLConnection from '../../Plugs/MySQLConnection'
|
||||
import Auth from "../../Plugs/Middleware/Auth";
|
||||
|
||||
// 删除资源
|
||||
class DelResource extends API {
|
||||
constructor() {
|
||||
super('DELETE', '/console/resource', Auth);
|
||||
}
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
let { id } = data;
|
||||
if (!id) {
|
||||
return res.json(ServerStdResponse.PARAMS_MISSING);
|
||||
}
|
||||
let execRes = await MySQLConnection.execute('DELETE FROM resource WHERE `id` = ?', [id]);
|
||||
|
||||
if (!execRes || execRes.affectedRows != 1) {
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({ ...ServerStdResponse.OK });
|
||||
}
|
||||
}
|
||||
|
||||
export default DelResource;
|
||||
22
Server/src/APIs/Console/GetBlogs.ts
Normal file
22
Server/src/APIs/Console/GetBlogs.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { API } from "../../Plugs/API/API";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import MySQLConnection from '../../Plugs/MySQLConnection'
|
||||
import Auth from "../../Plugs/Middleware/Auth";
|
||||
|
||||
// 获取博客列表
|
||||
class GetBlogs extends API {
|
||||
constructor() {
|
||||
super('GET', '/console/blogs', Auth);
|
||||
}
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
// const { uuid } = data._jwt;
|
||||
let resourcesRes = await MySQLConnection.execute("SELECT * FROM blog");
|
||||
if (!resourcesRes) {
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({ ...ServerStdResponse.OK, data: resourcesRes });
|
||||
}
|
||||
}
|
||||
|
||||
export default GetBlogs;
|
||||
22
Server/src/APIs/Console/GetResources.ts
Normal file
22
Server/src/APIs/Console/GetResources.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { API } from "../../Plugs/API/API";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import MySQLConnection from '../../Plugs/MySQLConnection'
|
||||
import Auth from "../../Plugs/Middleware/Auth";
|
||||
|
||||
// 获取资源列表
|
||||
class GetResources extends API {
|
||||
constructor() {
|
||||
super('GET', '/console/resources', Auth);
|
||||
}
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
// const { uuid } = data._jwt;
|
||||
let resourcesRes = await MySQLConnection.execute("SELECT * FROM resource");
|
||||
if (!resourcesRes) {
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({ ...ServerStdResponse.OK, data: resourcesRes });
|
||||
}
|
||||
}
|
||||
|
||||
export default GetResources;
|
||||
33
Server/src/APIs/Console/SaveResource.ts
Normal file
33
Server/src/APIs/Console/SaveResource.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { API } from "../../Plugs/API/API";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import MySQLConnection from '../../Plugs/MySQLConnection'
|
||||
import Auth from "../../Plugs/Middleware/Auth";
|
||||
|
||||
// 保存资源
|
||||
class SaveResource extends API {
|
||||
constructor() {
|
||||
super('POST', '/console/saveResource', Auth);
|
||||
}
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
let { id, type, recommand, title, describe, icon_src, addition, src } = data;
|
||||
if (!type || !recommand || !title || !describe || !icon_src || !addition || !src) {
|
||||
return res.json(ServerStdResponse.PARAMS_MISSING);
|
||||
}
|
||||
let execRes: any;
|
||||
if (id) {
|
||||
// 保存
|
||||
execRes = await MySQLConnection.execute('UPDATE resource SET `type` = ?, `recommand` = ?, `title` = ?, `describe` = ?, `addition` = ?, `icon_src` = ?, `src` = ? WHERE `id` = ?', [type, recommand, title, describe, addition, icon_src, src, id]);
|
||||
} else {
|
||||
// 新建
|
||||
execRes = await MySQLConnection.execute('INSERT INTO resource (`type`, `recommand`, `title`, `describe`, `addition`, `icon_src`, `src`) VALUES (?,?,?,?,?,?,?)', [type, recommand, title, describe, addition, icon_src, src]);
|
||||
}
|
||||
|
||||
if (!execRes || execRes.affectedRows != 1) {
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({ ...ServerStdResponse.OK });
|
||||
}
|
||||
}
|
||||
|
||||
export default SaveResource;
|
||||
Reference in New Issue
Block a user