Implement MongoDB-backed worksheet generation locking - #93
Open
Chirashrikarmakar wants to merge 1 commit into
Open
Implement MongoDB-backed worksheet generation locking#93Chirashrikarmakar wants to merge 1 commit into
Chirashrikarmakar wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implemented MongoDB-backed permanent worksheet generation locking for the FLN Assessment Platform.
The feature prevents duplicate question paper generation for the same assessment and school. When a teacher generates a question paper, a permanent lock is created and stored in MongoDB. Any further generation attempts for the same assessment and school are rejected.
The backend locking mechanism is fully implemented using MongoDB. However, the current application flow still uses the frontend mock backend (
fetchInterceptor.ts) for many API routes. Because of this, the UI generation flow may not always reach the real Express backend and MongoDB layer during testing.Implementation Details
MongoDB Lock Persistence
GenerationLockMongoDB model to store worksheet generation locks.Permanent Generation Locking Flow
The implemented workflow:
Teacher clicks "Generate Question Paper"
↓
Request reaches backend
↓
Backend creates a MongoDB generation lock
↓
Question paper generation starts
↓
Lock remains permanently after successful generation
If the teacher tries to generate the same question paper again:
Generate Request
↓
Backend checks MongoDB lock
↓
Existing lock found
↓
Request rejected with HTTP 423 Locked
This ensures that only one question paper can be generated for the same assessment and school.
Concurrency Protection
GenerationLock.create().assessmentIdschoolId11000).423 Lockedwhen a generation lock already exists.Lock Lifecycle Management
Lock Identification
Locks are uniquely identified using:
assessmentId + schoolIdThis guarantees:
Verification
Verified the backend implementation:
GenerationLockmodel is integrated with the worksheet generation flow.Current Limitation
The project currently uses an in-browser mock backend for many API routes.
Current flow:
React Frontend
↓
fetchInterceptor.ts↓
localStorage Mock Database
instead of:
React Frontend
↓
Express Backend
↓
MongoDB
Because of this existing architecture:
generationlockscollection may remain empty when the mock API handles the request.The MongoDB locking implementation itself is complete and ready for integration with the real backend workflow.
Files Changed
backend/src/models/GenerationLock.tsbackend/src/mongodb.tsbackend/src/index.tsbackend/package.json