alfaarghya / alfa-leetcode-api

It's a custom leetcode api. This API provides endpoints to retrieve details about a user's profile, badges, solved questions, contest details, contest history, submissions, calendar and and also daily questions, selected problem, list of problems.
https://alfa-leetcode-api.onrender.com/
MIT License
142 stars 58 forks source link

Refactor /trendingDiscuss and /languageStats to follow the code convention #16

Closed changchunlei closed 1 month ago

changchunlei commented 1 month ago

Hi Alfa,

This pull request includes refactoring two endpoints /trendingDiscuss and /languageStats to align with the original code structure.

Refactoring Details:

Aligned the structure of two endpoints with the original code format. Removed a few __typename from all graph queries Removed 7-8 lines of my previous code and added 100+ lines of code across multiple files to maintain consistency with the existing structure. Removed one duplicated daily question API

Suggestions and Rationale:

While I can see the rationale behind the existing code structure, including the separation of queries and controllers and the formatting approach, I would like to propose an alternative based on my recent frontend dev exerpeince. The primary purpose of this API is to simplify GraphQL queries into REST API endpoints. As such, I believe the GraphQL queries should be the main source for formatting data rather than relying on a middleware formatter. Using a middleware formatter introduces additional complexity. Without sepeific frontend requirement to tailor backend for the frontend, I don't think it makes sense to format the data returned from LeetCode in this manner.

Proposal: Moving forward, I suggest that we consider using GraphQL queries directly for data formatting. This approach could streamline the API development process and reduce the amount of code needed for formatting. It would also make it easier for frontend developers to work with the API.

I look forward to discussing this further and hearing your thoughts.

alfaarghya commented 1 month ago

Hii @changchunlei 👋

It seems you forgot to remove 'questionOfTodayQuery' from the app.ts file in the import section. This may cause issues when running build and start commands. image

I recommend changing this specific part of the code before I merge the code.

alfaarghya commented 1 month ago

Your Proposal is absolutely good 😀 and I also thought about it a while ago but never implemented it 😅.

alfaarghya commented 1 month ago

I would like to ask you one little question 🙃.

Why did your routes look like this?

Why not this?

It's not a change request. I am just curious to know because it will look cleaner to me.

changchunlei commented 1 month ago

Agree. We should spend some time to make the API queries in a consistent format. That's a to do item.