Is your feature request related to a problem? Please describe.
Yes. Currently, the "Request Paper" functionality does not check if a paper already exists in the database before allowing a user to submit a request. This leads to:
- Redundant Data: Duplicate requests for the same paper are stored in the database.
- Poor User Experience: Users might request a paper that is already available on the platform without realizing it.
- Manual Overload: Admins have to manually filter out requests for papers they already have.
Describe the solution you'd like
Implement a validation layer in the paper request workflow:
- Server-side Validation: Update
src/app/api/request/route.ts to check Paper and Admin matching collections (subject, exam, slot, year) before creating a request.
- Duplicate Prevention: Prevent the creation of a new
PaperRequest if an identical one already exists.
- Graceful Error Handling: Return specific status codes (e.g.,
409 Conflict) so the frontend can distinguish between "already exists in library" and "already requested".
- Enhanced UI: Update
RequestModal and the PaperRequest page to show helpful messages and a "View Paper" button if it's already available.
Additional context
- Relevant files:
src/app/api/request/route.ts, src/app/request/page.tsx, src/components/ui/RequestModal.tsx.
- Database Models:
Paper, PaperAdmin, PaperRequest.
- Goals: Help maintain a clean database and improve user journey.