8000 Added filtering based on diffiuclty · alfaarghya/alfa-leetcode-api@f4e010b · GitHub
[go: up one dir, main page]

Skip to content

Commit f4e010b

Browse files
committed
Added filtering based on diffiuclty
1 parent a956180 commit f4e010b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Controllers/fetchProblems.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Response } from 'express';
22
import { ProblemSetQuestionListData } from '../types';
33

44
const fetchProblems = async (
5-
options: { limit?: number; skip?: number; tags?: string }, // Mark parameters as optional
5+ options: { limit?: number; skip?: number; tags?: string; difficulty?: string}, // Mark parameters as optional
66
res: Response,
77
formatData: (data: ProblemSetQuestionListData) => {},
88
query: string
@@ -12,6 +12,7 @@ const fetchProblems = async (
1212
const limit = options.skip !== undefined && options.limit === undefined ? 1 : options.limit || 20;
1313
const skip = options.skip || 0; // Default to 0 if not provided
1414
const tags = options.tags ? options.tags.split(' ') : []; // Split tags or default to empty array
15+
const difficulty = options.difficulty || undefined; // difficulty has to be 'EASY', 'MEDIUM' or 'HARD'
1516

1617
const response = await fetch('https://leetcode.com/graphql', {
1718
method: 'POST',
@@ -25,10 +26,13 @@ const fetchProblems = async (
2526
categorySlug: '',
2627
skip,
2728
limit,
28-
filters: { tags },
29+
filters: { tags,
30+
difficulty
31+
},
2932
},
3033
}),
3134
});
DA73
35+
console.log(response)
3236

3337
const result = await response.json();
3438

src/leetCode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,16 @@ export const selectProblem = (req: Request, res: Response) => {
114114
};
115115

116116
export const problems = (
117-
req: Request<{}, {}, {}, { limit: number; skip: number; tags: string }>,
117+
req: Request<{}, {}, {}, { limit: number; skip: number; tags: string; difficulty: string }>,
118118
res: Response
119119
) => {
120+
const difficulty=req.query.difficulty;
120121
const limit = req.query.limit;
121122
const skip = req.query.skip;
122123
const tags = req.query.tags;
123124

124125
controllers.fetchProblems(
125-
{ limit, skip, tags },
126+
{ limit, skip, tags, difficulty },
126127
res,
127128
formatUtils.formatProblemsData,
128129
gqlQueries.problemListQuery

0 commit comments

Comments
 (0)
0