Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 285dfd8

Browse files
committed
feat: simplify user profile response and question list structure
1 parent cfb8df7 commit 285dfd8

File tree

2 files changed

+89
-10
lines changed

2 files changed

+89
-10
lines changed

‎src/leetcode/leetcode-cn-service.ts‎

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,44 @@ export class LeetCodeCNService implements LeetCodeBaseService {
121121
}
122122

123123
async fetchUserProfile(username: string): Promise<any> {
124-
return await this.leetCodeApi.user(username);
124+
const originalProfile = await this.leetCodeApi.user(username);
125+
126+
if (!originalProfile || !originalProfile.userProfilePublicProfile) {
127+
return originalProfile;
128+
}
129+
130+
const publicProfile = originalProfile.userProfilePublicProfile || {};
131+
const userProfile = publicProfile.profile || {};
132+
const skillSet = userProfile.skillSet || {};
133+
134+
const simplifiedProfile = {
135+
username: userProfile.userSlug,
136+
questionProgress: originalProfile.userProfileUserQuestionProgress,
137+
siteRanking: publicProfile.siteRanking,
138+
profile: {
139+
userSlug: userProfile.userSlug,
140+
realName: userProfile.realName,
141+
userAvatar: userProfile.userAvatar,
142+
globalLocation: userProfile.globalLocation,
143+
school: userProfile.school?.name,
144+
socialAccounts: (userProfile.socialAccounts || []).filter(
145+
(account: any) => !!account.profileUrl
146+
),
147+
skillSet: {
148+
topics: (skillSet.topics || []).map(
149+
(topic: any) => topic.slug
150+
),
151+
topicAreaScores: (skillSet.topicAreaScores || []).map(
152+
(item: any) => ({
153+
slug: item.topicArea?.slug,
154+
score: item.score
155+
})
156+
)
157+
}
158+
}
159+
};
160+
161+
return simplifiedProfile;
125162
}
126163

127164
async fetchUserContestRanking(
@@ -210,17 +247,28 @@ export class LeetCodeCNService implements LeetCodeBaseService {
210247
filters.searchKeywords = searchKeywords;
211248
}
212249

213-
const response = await this.leetCodeApi.graphql({
250+
const { data } = await this.leetCodeApi.graphql({
214251
query: SEARCH_PROBLEMS_QUERY,
215-
variables: {
216-
categorySlug: category,
217-
limit,
218-
skip: offset,
219-
filters
220-
}
252+
variables: { categorySlug: category, limit, skip: offset, filters }
221253
});
222254

223-
return response.data?.problemsetQuestionList;
255+
const questionList = data?.problemsetQuestionList;
256+
if (!questionList) {
257+
return { hasMore: false, total: 0, questions: [] };
258+
}
259+
260+
return {
261+
hasMore: questionList.hasMore,
262+
total: questionList.total,
263+
questions: questionList.questions.map((q: any) => ({
264+
title: q.title,
265+
titleCn: q.titleCn,
266+
titleSlug: q.titleSlug,
267+
difficulty: q.difficulty,
268+
acRate: q.acRate,
269+
topicTags: q.topicTags.map((tag: any) => tag.slug)
270+
}))
271+
};
224272
}
225273

226274
async fetchUserProgressQuestionList(options?: {

‎src/leetcode/leetcode-global-service.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ export class LeetCodeGlobalService implements LeetCodeBaseService {
110110

111111
async fetchUserProfile(username: string): Promise<any> {
112112
const profile = await this.leetCodeApi.user(username);
113+
if (profile && profile.matchedUser) {
114+
const { matchedUser } = profile;
115+
116+
return {
117+
username: matchedUser.username,
118+
realName: matchedUser.profile.realName,
119+
userAvatar: matchedUser.profile.userAvatar,
120+
countryName: matchedUser.profile.countryName,
121+
githubUrl: matchedUser.githubUrl,
122+
company: matchedUser.profile.company,
123+
school: matchedUser.profile.school,
124+
ranking: matchedUser.profile.ranking,
125+
totalSubmissionNum: matchedUser.submitStats?.totalSubmissionNum
126+
};
127+
}
113128
return profile;
114129
}
115130

@@ -211,7 +226,23 @@ export class LeetCodeGlobalService implements LeetCodeBaseService {
211226
}
212227
});
213228

214-
return response.data?.problemsetQuestionList;
229+
const questionList = response.data?.problemsetQuestionList;
230+
if (!questionList) {
231+
return {
232+
total: 0,
233+
questions: []
234+
};
235+
}
236+
return {
237+
total: questionList.total,
238+
questions: questionList.questions.map((question: any) => ({
239+
title: question.title,
240+
titleSlug: question.titleSlug,
241+
difficulty: question.difficulty,
242+
acRate: question.acRate,
243+
topicTags: question.topicTags.map((tag: any) => tag.slug)
244+
}))
245+
};
215246
}
216247

217248
async fetchUserProgressQuestionList(options?: {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /