-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/automatic status #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
248be9b
upated router to match recently solved problems
aguajardoc ec36728
Automatically update the progress in each problem using leetcode API
aguajardoc cf1eb5d
refactor: update query to check new completions for user 'pyoro'
aguajardoc 3eb162c
fix: correct property name from 'username' to 'name' in solvedBy check
aguajardoc 16503ba
refactor: replace 'username' with 'leetcodeUser' in checkNewCompletio…
aguajardoc b3a7299
fix: add optional leetcodeUser property to session user type
aguajardoc 94a2114
fix: ensure backend call for new completions only occurs if session e…
aguajardoc 237a9e8
refactor: streamline/optimize problem update logic in checkNewComplet…
aguajardoc 8b0f157
fix: update training start date for problem completion tracking
aguajardoc 44bef11
fix: ensure backend call for new completions uses defined userId and …
aguajardoc e7a3d17
Merge branch 'main' into feat/automaticStatus
Rodrogamby b3cb700
fix types old->new and remove unused input from procedure
Rodrogamby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,16 +17,46 @@ export const leetcodeRouter = createTRPCRouter({ | |
| return await getProblemsSolved({ username: input.username }); | ||
| }), | ||
|
|
||
| hasCompletedProblemRecently: publicProcedure | ||
| .input(z.object({ username: z.string(), problemSlug: z.string() })) | ||
| .query(async ({ input }) => { | ||
| const recentAccepted = await getAcceptedProblems({ | ||
| username: input.username, | ||
| }); | ||
| checkNewCompletions: publicProcedure | ||
| .input(z.object({ week: z.number(), userId: z.string(), leetcodeUser: z.string() })) | ||
|
||
| .query(async ({ input, ctx }) => { | ||
| const recentAccepted = await getAcceptedProblems({ username: input.leetcodeUser }); | ||
| if (!recentAccepted) { | ||
| throw new Error("Failed to fetch recent accepted problems"); | ||
| } | ||
|
|
||
| const data = recentAccepted.map((problem) => ({ | ||
| name: problem.title, | ||
| timestamp: problem.timestamp, | ||
| })); | ||
|
|
||
| const db = await ctx.db.problem.findMany({ include: { week: true, solvedBy: true } }); | ||
GilMM27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // For every problem, check if it exists in the database | ||
| // If it exists, check if the user has solved it | ||
| // If the user has not solved it, update the problem in the database | ||
| for (const problem of data) { | ||
| // Make sure time is at least the beginning of the training period | ||
| const trainingStartDate = new Date(`2025-06-28T00:00:00Z`).getTime(); | ||
| if (new Date(problem.timestamp * 1000).getTime() < trainingStartDate) { | ||
| continue; | ||
| } | ||
|
|
||
| return recentAccepted.some( | ||
| (submission) => submission.titleSlug === input.problemSlug, | ||
| ); | ||
| // Perform match | ||
| const matchedProblem = db.find((p => p.name === problem.name)); | ||
| if (matchedProblem) { | ||
| if (!matchedProblem.solvedBy.some(user => user.name === input.leetcodeUser)) { | ||
| await ctx.db.problem.update({ | ||
| where: { id: matchedProblem.id }, | ||
| data: { | ||
| solvedBy: { | ||
| connect: { id: input.userId }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }), | ||
|
|
||
| getProblemById: publicProcedure | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we avoid making the call to the backend if we know that there is no user session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed, please check. is checking "if (session)" enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check something like
But adding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to throw an error (which I think is what happens in weekly-problems?), or should it stay as a simple message?
I was thinking something like
but I'd like some feedback before pushing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say the 'Unauthorized' message is a better choice, as this is not an error but adequate behavior. Perhaps we could add standard 404 or 401 pages later