Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #528 from langningchen/langningchen/issue462
Browse files Browse the repository at this point in the history
增加讨论板块功能
  • Loading branch information
Chen LangNing authored Sep 29, 2023
2 parents e137414 + 000db62 commit 3fe253d
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 26 deletions.
10 changes: 9 additions & 1 deletion Server/Source/Initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ CREATE TABLE bbs_post (
user_id TEXT NOT NULL,
problem_id INT NOT NULL,
title TEXT NOT NULL,
post_time INTEGER NOT NULL
post_time INTEGER NOT NULL,
board_id INTEGER NOT NULL
);

DROP TABLE IF EXISTS bbs_reply;
Expand All @@ -46,6 +47,13 @@ CREATE TABLE bbs_reply (
edit_person TEXT
);

DROP TABLE IF EXISTS board_id;

CREATE TABLE board_id (
board_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
board_name TEXT NOT NULL
);

DROP TABLE IF EXISTS phpsessid;

CREATE TABLE phpsessid (
Expand Down
56 changes: 52 additions & 4 deletions Server/Source/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,30 @@ export class Process {
"ProblemID": "number",
"Title": "string",
"Content": "string",
"CaptchaSecretKey": "string"
"CaptchaSecretKey": "string",
"BoardID": "number"
}));
ThrowErrorIfFailed(await this.VerifyCaptcha(Data["CaptchaSecretKey"]));
if (Data["Title"].trim() === "") {
return new Result(false, "标题不能为空");
}
if (Data["Content"].trim() === "") {
return new Result(false, "内容不能为空");
}
if (!this.IsAdmin && Data["BoardID"] === 0) {
return new Result(false, "没有权限发表公告");
}
if (Data["BoardID"] !== 0 && ThrowErrorIfFailed(await this.XMOJDatabase.GetTableSize("bbs_board", {
board_id: Data["BoardID"]
}))["TableSize"] === 0) {
return new Result(false, "未找到板块");
}
let PostID = ThrowErrorIfFailed(await this.XMOJDatabase.Insert("bbs_post", {
user_id: this.Username,
problem_id: Data["ProblemID"],
title: Data["Title"],
post_time: new Date().getTime()
post_time: new Date().getTime(),
board_id: Data["BoardID"]
}))["InsertID"];
let ReplyID = ThrowErrorIfFailed(await this.XMOJDatabase.Insert("bbs_reply", {
user_id: this.Username,
Expand Down Expand Up @@ -322,7 +338,8 @@ export class Process {
GetPosts: async (Data: object): Promise<Result> => {
ThrowErrorIfFailed(this.CheckParams(Data, {
"ProblemID": "number",
"Page": "number"
"Page": "number",
"BoardID": "number"
}));
let ResponseData = {
Posts: new Array<Object>,
Expand All @@ -334,14 +351,22 @@ export class Process {
if (Data["Page"] < 1 || Data["Page"] > ResponseData.PageCount) {
return new Result(false, "参数页数不在范围1~" + ResponseData.PageCount + "内");
}
let Posts = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_post", [], (Data["ProblemID"] === 0 ? undefined : { problem_id: Data["ProblemID"] }), {
let SearchCondition = {};
if (Data["ProblemID"] !== 0) {
SearchCondition["problem_id"] = Data["ProblemID"];
}
if (Data["BoardID"] !== -1) {
SearchCondition["board_id"] = Data["BoardID"];
}
let Posts = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_post", [], SearchCondition, {
Order: "post_id",
OrderIncreasing: false,
Limit: 10,
Offset: (Data["Page"] - 1) * 10
}));
for (let i in Posts) {
let Post = Posts[i];

let ReplyCount: number = ThrowErrorIfFailed(await this.XMOJDatabase.GetTableSize("bbs_reply", { post_id: Post["post_id"] }))["TableSize"];
let LastReply = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_reply", ["user_id", "reply_time"], { post_id: Post["post_id"] }, {
Order: "reply_time",
Expand Down Expand Up @@ -375,6 +400,10 @@ export class Process {
ProblemID: Post["problem_id"],
Title: Post["title"],
PostTime: Post["post_time"],
BoardID: Post["board_id"],
BoardName: ThrowErrorIfFailed(await this.XMOJDatabase.Select("board_id", ["board_name"], {
board_id: Post["board_id"]
}))[0]["board_name"],
ReplyCount: ReplyCount,
LastReplyUserID: LastReply[0]["user_id"],
LastReplyTime: LastReply[0]["reply_time"],
Expand All @@ -392,6 +421,8 @@ export class Process {
UserID: "",
ProblemID: 0,
Title: "",
BoardID: 0,
BoardName: "",
PostTime: 0,
Reply: new Array<Object>(),
PageCount: 0,
Expand All @@ -418,6 +449,8 @@ export class Process {
ResponseData.ProblemID = Post[0]["problem_id"];
ResponseData.Title = Post[0]["title"];
ResponseData.PostTime = Post[0]["post_time"];
ResponseData.BoardID = Post[0]["board_id"];
ResponseData.BoardName = ThrowErrorIfFailed(await this.XMOJDatabase.Select("board_id", ["board_name"], { board_id: Post[0]["board_id"] }))[0]["board_name"];

let Locked = ThrowErrorIfFailed(await this.XMOJDatabase.Select("bbs_lock", [], {
post_id: Data["PostID"]
Expand Down Expand Up @@ -969,6 +1002,21 @@ export class Process {
user_id: Data["UserID"]
}));
return new Result(true, "删除标签成功");
},
GetBoards: async (Data: object): Promise<Result> => {
ThrowErrorIfFailed(this.CheckParams(Data, {}));
let Boards: Array<Object> = new Array<Object>();
let BoardsData = ThrowErrorIfFailed(await this.XMOJDatabase.Select("board_id", []));
for (let i in BoardsData) {
let Board = BoardsData[i];
Boards.push({
BoardID: Board["board_id"],
BoardName: Board["board_name"]
});
}
return new Result(true, "获得板块列表成功", {
"Boards": Boards
});
}
};
constructor(RequestData: Request, Environment) {
Expand Down
10 changes: 10 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@
"Description": "增加预览版标签"
}
]
},
"0.3.181": {
"UpdateDate": 1695991181322,
"Prerelease": true,
"UpdateContents": [
{
"PR": 528,
"Description": "增加讨论板块功能"
}
]
}
}
}
Loading

0 comments on commit 3fe253d

Please sign in to comment.