Skip to content

Commit 097302a

Browse files
committed
feat: add get question by keyword function
1 parent da57941 commit 097302a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getQuestionKeywordJson } from '#resources/headers/questionKeywordJson.js'
2+
import { graphql } from '#common/utils/http/graphql.js'
3+
4+
export async function getQuestionKeyword(keyword) {
5+
const questionData = await graphql(getQuestionKeywordJson(keyword.toString()))
6+
return questionData?.data?.problemsetQuestionList?.questions
7+
}
8+
9+
console.log(getQuestionKeyword('两数'))

common/view/finder.view.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inquirer from 'inquirer'
2+
import { getQuestionKeyword } from '#common/utils/question-getter/getQuestionByKeyword'
23

34
export async function easyFinderView() {
45
const modeQuestion = [{
@@ -8,6 +9,22 @@ export async function easyFinderView() {
89
choices: ['关键词搜索', 'Top 100列表查询', '进入筛选模式'],
910
}]
1011
const { mode } = await inquirer.prompt(modeQuestion, null)
12+
const questionKeyword = [{
13+
type: 'input',
14+
name: 'identity',
15+
message: '请输入关键词:',
16+
}]
17+
18+
switch (mode) {
19+
case '关键词搜索':
20+
const {identity} = getQuestionKeyword(await inquirer.prompt(questionKeyword, null))
21+
console.log(identity)
22+
break
23+
case 'Top 100列表查询':
24+
break
25+
case '进入筛选模式':
26+
break
27+
}
1128
}
1229

1330
await easyFinderView()
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function getQuestionKeywordJson(keyword) {
2+
return {
3+
headers: { "content-type": "application/json" },
4+
body: `{
5+
"query": "\n query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {\n problemsetQuestionList(\n categorySlug: $categorySlug\n limit: $limit\n skip: $skip\n filters: $filters\n ) {\n hasMore\n total\n questions {\n acRate\n difficulty\n freqBar\n frontendQuestionId\n isFavor\n paidOnly\n solutionNum\n status\n title\n titleCn\n titleSlug\n topicTags {\n name\n nameTranslated\n id\n slug\n }\n extra {\n hasVideoSolution\n topCompanyTags {\n imgUrl\n slug\n numSubscribed\n }\n }\n }\n }\n}\n ",
6+
"variables": {
7+
"categorySlug": "all-code-essentials",
8+
"skip": 0,
9+
"limit": 50,
10+
"filters": {
11+
"searchKeywords": "${keyword}"
12+
}
13+
},
14+
"operationName": "problemsetQuestionList"
15+
}`,
16+
method: 'POST'
17+
};
18+
}

0 commit comments

Comments
 (0)