Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/Controllers/fetchProblems.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/Controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { default as fetchSingleProblem } from './fetchSingleProblem';
export { default as fetchProblems } from './fetchProblems';
export { default as fetchUserDetails } from './fetchUserDetails';
export { default as fetchTrendingTopics } from './fetchDiscussion';
export { default as fetchDataRawFormat } from './fetchDataRawFormat';
1 change: 0 additions & 1 deletion src/GQLQueries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
export { default as AcSubmissionQuery } from './recentAcSubmit';
export { default as contestQuery } from './contest';
export { default as dailyProblemQuery } from './dailyProblem';
export { default as problemListQuery } from './problemList';
export { default as userProfileQuery } from './userProfile';
export { default as selectProblemQuery } from './selectProblem';
export { default as submissionQuery } from './recentSubmit';
Expand Down
71 changes: 41 additions & 30 deletions src/GQLQueries/problemList.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
const query = `#graphql
query getProblems($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {
problemsetQuestionList: questionList(
categorySlug: $categorySlug
limit: $limit
skip: $skip
filters: $filters
) {
total: totalNum
questions: data {
acRate
difficulty
freqBar
questionFrontendId
isFavor
isPaidOnly
status
title
titleSlug
topicTags {
name
id
slug
}
hasSolution
hasVideoSolution
}
export const problemList = `
query problemsetQuestionListV2(
$filters: QuestionFilterInput,
$limit: Int,
$searchKeyword: String,
$skip: Int,
$sortBy: QuestionSortByInput,
$categorySlug: String
) {
problemsetQuestionListV2(
filters: $filters
limit: $limit
searchKeyword: $searchKeyword
skip: $skip
sortBy: $sortBy
categorySlug: $categorySlug
) {
questions {
id
titleSlug
title
translatedTitle
questionFrontendId
paidOnly
difficulty
topicTags {
name
slug
nameTranslated
}
}`;

export default query;
status
isInMyFavorites
frequency
acRate
contestPoint
}
totalLength
finishedLength
hasMore
}
}
`;
31 changes: 27 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as leetcode from './leetCode';
import { FetchUserDataRequest } from './types';
import apicache from 'apicache';
import axios from 'axios';
import { problemList } from './GQLQueries/problemList';
import {
userContestRankingInfoQuery,
discussCommentsQuery,
Expand Down Expand Up @@ -38,6 +39,7 @@ app.use((req: express.Request, _res: Response, next: NextFunction) => {
});

async function queryLeetCodeAPI(query: string, variables: any) {
console.log(variables)
try {
const response = await axios.post(API_URL, { query, variables });
if (response.data.errors) {
Expand Down Expand Up @@ -131,6 +133,31 @@ app.get('/officialSolution', async (req, res) => {
return res.status(500).json({ error: error.message });
}
});
app.get('/problemList', async (req, res) => {
const skip = req.query.skip?req.query.skip:0;
const limit=req.query.limit?req.query.limit:20;
const searchKeyword=req.query.searchKeyword?req.query.searchKeyword:"";
const difficulties = typeof req.query.difficulties === "string"
? req.query.difficulties.split(",")
: [];
const tags=req.query.tags?req.query.tags:"all-code-essentials"
const sortBy= {
"sortField": "CUSTOM",
"sortOrder": "ASCENDING"
}
const filters= {
"filterCombineType": "ALL",
"difficultyFilter": {
"difficulties": difficulties,
"operator": "IS"
}};
try {
const data = await queryLeetCodeAPI(problemList, { skip ,limit,searchKeyword,filters,categorySlug:tags,sortBy});
return res.json(data);
} catch (error) {
return res.status(500).json({ error: error.message });
}
});

app.get('/userProfileCalendar', async (req, res) => {
const { username, year } = req.query;
Expand Down Expand Up @@ -242,10 +269,6 @@ app.get('/daily', leetcode.dailyProblem);

//get the selected question
app.get('/select', leetcode.selectProblem);

//get list of problems
app.get('/problems', leetcode.problems);

//get 20 trending Discuss
app.get('/trendingDiscuss', leetcode.trendingCategoryTopics);

Expand Down
16 changes: 0 additions & 16 deletions src/leetCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,6 @@ export const selectProblem = (req: Request, res: Response) => {
}
};

export const problems = (
req: Request<{}, {}, {}, { limit: number; skip: number; tags: string; difficulty: string }>,
res: Response
) => {
const difficulty=req.query.difficulty;
const limit = req.query.limit;
const skip = req.query.skip;
const tags = req.query.tags;

controllers.fetchProblems(
{ limit, skip, tags, difficulty },
res,
formatUtils.formatProblemsData,
gqlQueries.problemListQuery
);
};


export const trendingCategoryTopics = (_req: Request, res: Response) => {
Expand Down