Skip to content

refactor: extract feedback logic into MVC structure - #647

Open
manasvisharma2231 wants to merge 1 commit into
lovelymahor:mainfrom
manasvisharma2231:fix/623-feedback-mvc-refactor
Open

refactor: extract feedback logic into MVC structure#647
manasvisharma2231 wants to merge 1 commit into
lovelymahor:mainfrom
manasvisharma2231:fix/623-feedback-mvc-refactor

Conversation

@manasvisharma2231

Copy link
Copy Markdown

Move inline feedback schema and handlers out of index.js into dedicated model, controller, and route files to remove duplication and align with the auth/reports pattern.

Fixes #623

Description

This PR resolves #623 — Architecture Inconsistency & Code Duplication (Feedback Logic).

Previously, the Feedback Mongoose schema and route handlers (POST /api/feedback, GET /api/feedbacks) were defined inline inside server/index.js, while duplicate logic existed in unused files under server/src/. This caused code duplication and made index.js unnecessarily bloated.

This refactor moves feedback logic into a clean MVC structure, consistent with how auth and reports are organized in the project.

Type of change

  • Bug fix / refactor (non-breaking change which fixes architectural inconsistency)
  • New feature
  • Documentation update
  • UI/UX change

Changes made

server/index.js

  • Removed inline Feedback schema, model, and route handlers
  • Mounted feedback routes cleanly:
    • POST /api/feedback → create feedback
    • GET /api/feedbacks → list all feedbacks

server/src/routes/feedback.js (new)

  • Dedicated route file wiring controllers and validation middleware
  • Exports createRouter and listRouter for clean mounting

server/src/controllers/feedback.controller.js

  • Uses existing controller logic (createFeedback, getFeedbacks)
  • Removed debug console.log statements

server/src/models/feedback.model.js

  • Already existed — now actively used (no changes needed)

server/app.js

  • Fixed broken import from deleted feedback.routes.js
  • Updated route mounting to match index.js

server/src/routes/feedback.routes.js

  • Removed (replaced by feedback.js)

Architecture after refactor

index.js → only mounts routes
routes/feedback.js → URL mapping
controller/ → business logic
model/ → database schema
middleware/ → validation

Testing done

Tested locally on backend as per project contributing guidelines:

  • Server starts without errors (npm run dev)
  • MongoDB connects successfully
  • POST /api/feedback — returns 201 with success message for valid payload
  • POST /api/feedback — returns 400 for invalid/empty fields (validation middleware)
  • GET /api/feedbacks — returns 200 with saved feedback array

Sample test commands used:

curl -X POST http://localhost:5001/api/feedback \
  -H "Content-Type: application/json" \
  -d '{
    "university": "Test University",
    "examName": "Midterm",
    "difficulty": "medium",
    "feedback": "The paper was fair."
  }'

curl http://localhost:5000/api/feedbacks

Move inline feedback schema and handlers out of index.js into dedicated
model, controller, and route files to remove duplication and align with
the auth/reports pattern.

Fixes lovelymahor#623
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

@manasvisharma2231 is attempting to deploy a commit to the Lovely Mahour's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Architecture Inconsistency & Code Duplication (Feedback Logic)

1 participant