Skip to content
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

feat: user and question history #60

Merged
merged 22 commits into from
Nov 4, 2024
Merged

Conversation

tituschewxj
Copy link

@tituschewxj tituschewxj commented Oct 30, 2024

Summary

This PR implements the following changes:

history-service:

  • Reorganized backend files in history service

frontend:

  • Added the all question submissions tab (added as a separate page)
  • Added the question submissions tab on the question viewing page
  • Modified the templates for the question page and question history page.
    • Removed chat and/or code editor UI on specific pages
    • Removed run/submit buttons on question viewing page
    • Added submission history table and submission code viewer
  • Removed cancel button from matching modal

Note that the attempted status for a question is not added yet.

Screenshots

Question page:

  • Click on a submission or be redirected from the history page to view the code submitted.

image

History page:

  • We can click on the submission record which would route the user to the question page with the specified question. Note that because question ID is not stored, we use a placeholder in the URL, but this should not affect what is displayed.

image

Known issues

  • Some of the histories records in the database seem to have the wrong questionDocRefId, especially for old records.
  • The collaboration times can sometimes it not start from 0:00. May be a browser-related issue, as I have this issue on Firefox

Implementation

User submission

Each user submission sends a request to the POST /histories/. If either user in a collaboration session updates the history, the history would be updated for both of them (although only one entry is stored)

  • Currently, the way it is implemented is such that every submission creates a new history record.

Request format:

{
  "title": "Hello World in Python",
  "code": "print('Hello, World!')",
  "language": "Python",
  "user": "user789",
  "matchedUser": "user123",
  "matchId": "match123",
  "matchedTopics": ["Python", "Programming"],
  "questionDocRefId": "question123",
  "questionDifficulty": "Easy",
  "questionTopics": ["Python", "Programming"]
}

Retrieving user submissions

Retrieving user submission on their profile page, by sending a request to GET /histories/user/{username}.

  • When retrieving the history, it retrieves the history
  • questionDocRefId is sent so that user can be linked to the question
  • Pagination should be added so that long histories would not lead to loading delays.
  • It is sorted by the submission time from the latest

Response format:

{
	"totalCount": 37,
	"totalPages": 4,
	"currentPage": 1,
	"limit": 10,
	"hasNextPage": true,
	"histories": [
		{
			"code": "cat1234567",
			"language": "Javascript",
			"user": "AdminUser",
			"matchedUser": "test-user-3",
			"matchedTopics": [
				"Arrays"
			],
			"title": "12. Rotate Image",
			"questionDocRefId": "PZ0mvV5uRY5P5DMcIKxf",
			"questionDifficulty": "medium",
			"questionTopics": [
				"Arrays",
				"Algorithms"
			],
			"createdAt": "2024-11-03T18:44:58.611Z",
			"updatedAt": "2024-11-03T18:44:58.611Z",
			"historyDocRefId": "Cx75ZonysVYi9DarvHmb"
		}, ...
	]
}

Retrieving question submissions

Retrieving question submissions on the question page, by sending a request to GET /histories/user/{username}/question/{questionDocRefId}/

  • If a question has no submission history for that user, then it is unattempted.
  • There should also be pagination
  • The response is similar to the above response, but it also filters on the question.

Retrieving single history item

There is also a request to get an individual item in history: GET /histories/{historyDocRefId}

Response format:

{
	"code": "cat",
	"language": "Javascript",
	"user": "AdminUser",
	"matchedUser": "test-user-3",
	"matchedTopics": [
		"Arrays"
	],
	"title": "12. Rotate Image",
	"questionDocRefId": "PZ0mvV5uRY5P5DMcIKxf",
	"questionDifficulty": "medium",
	"questionTopics": [
		"Arrays",
		"Algorithms"
	],
	"createdAt": "2024-11-03T18:22:13.706Z",
	"updatedAt": "2024-11-03T18:22:13.706Z",
	"historyDocRefId": "U9k2C1EHPgnAxns8DP2F"
}

Future improvements

  1. Currently, we cannot differentiate between attempted and accepted submissions.
  • There is a dependency on the code execution service to validate the code, before sending the result to the history service.
  • So for now each question can only be marked with attempted or not-attempted.
  1. Can also optimize the queries so that not so much data is sent to the frontend.

  2. Can add the status (attempted/not-attempted) of the question in the question listing page/question page.

  3. Can validate JWT token in the requests in the backend.

  4. Question ID should also be included when creating history, as doc ref id can change upon resetting the db

@tituschewxj tituschewxj self-assigned this Oct 30, 2024
@tituschewxj tituschewxj marked this pull request as draft October 30, 2024 09:38
@tituschewxj tituschewxj changed the title DRAFT: feat: user and question history feat: user and question history Oct 30, 2024
@tituschewxj tituschewxj marked this pull request as ready for review November 3, 2024 21:29
@tituschewxj tituschewxj mentioned this pull request Nov 4, 2024
Copy link

@solomonng2001 solomonng2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Noted that the "histories records in the database seem to have the wrong questionDocRefId". Will take note of the changes in history-service's API when updating execution-service.

Copy link

@solomonng2001 solomonng2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted that merge conflicts resolved. LGTM!

@solomonng2001 solomonng2001 merged commit 48d6745 into staging Nov 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants