Skip to content

Commit 8eca533

Browse files
author
CodeJudge
committed
feat: 题目搜索支持ID查询
1 parent 6daf224 commit 8eca533

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

backend/src/controllers/problemController.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ function listProblems(req, res) {
99

1010
if (type) { conditions += ' AND type = ?'; params.push(type); }
1111
if (difficulty) { conditions += ' AND difficulty = ?'; params.push(difficulty); }
12-
if (search) { conditions += ' AND title LIKE ?'; params.push(`%${search}%`); }
12+
if (search) {
13+
conditions += ' AND (title LIKE ?';
14+
params.push(`%${search}%`);
15+
if (/^\d+$/.test(search)) {
16+
conditions += ' OR id = ?';
17+
params.push(Number(search));
18+
}
19+
conditions += ')';
20+
}
1321

1422
const total = queryOne(countSql + conditions, params).count;
1523

0 commit comments

Comments
 (0)