CS3219-AY2324S1 / ay2324s1-course-assessment-g11

ay2324s1-course-assessment-g11 created by GitHub Classroom
MIT License
3 stars 2 forks source link

Assignment 6: Serverless fetching of leetcode questions #182

Closed chunweii closed 10 months ago

chunweii commented 11 months ago

Idea: Serverless function on Google Cloud Functions

  1. Serverless function periodically (maybe once a week) calls https://leetcode.com/api/problems/algorithms/ to get all algorithms problems on leetcode, filter to make sure that the problems are not paid-only, then split them into their difficulties.
  2. Store all of their question-slug and difficulty in a database.
  3. When user chooses to attempt a new random leetcode question, another serverless function can be called,
  4. Serverless function picks a random leetcode question-slug from the database and makes the graphql api query
  5. Serverless function creates a new question using question-service, with the new leetcode question. The author of the question would be a special user "leetcode"
  6. Serverless function returns the newly created question object to the user.

We can get all algorithm problems (including their title slugs and difficulty) using https://leetcode.com/api/problems/algorithms/. Make sure that the problem is not paid-only!

We can use the following graphql query on https://leetcode.com/graphql

query ($titleSlug: String!) {
    question(titleSlug: $titleSlug) {
        questionId
        title
        titleSlug
        content
        difficulty
        exampleTestcases
        topicTags {
            name
            slug
        }
        codeSnippets {
            lang
            langSlug
            code
        }
    }
}
chunweii commented 11 months ago

To be honest, the fetching of the question from leetcode can be done directly in question-service backend. And it makes more sense to do it that way rather than go through another layer of serverless functions

Alternatively, the only serverless function that we implement is the weekly update based on https://leetcode.com/api/problems/algorithms/.

yhtMinceraft1010X commented 10 months ago

Done in our A6 repo