Skip to content

fix: Model detail page does not load reviews from API#70

Open
novoice-rana wants to merge 1 commit into
AditthyaSS:mainfrom
novoice-rana:fix/review-persistence
Open

fix: Model detail page does not load reviews from API#70
novoice-rana wants to merge 1 commit into
AditthyaSS:mainfrom
novoice-rana:fix/review-persistence

Conversation

@novoice-rana
Copy link
Copy Markdown

@novoice-rana novoice-rana commented Jun 2, 2026

Fix #34

Problem

The reviews section appeared empty after a page refresh, even though reviews were successfully submitted and stored.

Root Cause

  • POST /api/reviews existed and correctly persisted reviews.
  • GET /api/models/[slug] did not include reviews in its response.
  • ReviewSection only rendered the initialReviews prop.
  • No client-side mechanism existed to fetch reviews after mount.
  • Reviews were present in the database but were never retrieved for display.

Solution

Implemented a complete review retrieval and display workflow.

API Changes

Added GET /api/reviews

Supports fetching reviews by entity.

Query Parameters

  • entityType
  • entityId

Behavior

  • Returns reviews with associated user information.
  • Orders results by creation date (newest first).
  • Provides mock-data fallback when the database is unavailable.

Extended GET /api/models/[slug]

  • Includes reviews in the model response.
  • Fetches review data with related user information via Prisma.
  • Returns mock reviews when running in mock mode.
  • Maintains backward compatibility with existing consumers.

Frontend Changes

Updated ReviewSection

  • Fetches reviews when the component mounts.
  • Reloads reviews whenever the model ID changes.
  • Refetches reviews after a successful submission.
  • Renders reviews directly from the API response.

Mock Data Updates

  • Added a mockReviews dataset.
  • Added getReviewsByEntity() helper for mock-mode support.

Files Changed

  • src/app/api/reviews/route.ts
  • src/app/api/models/[slug]/route.ts
  • src/components/models/ReviewSection.tsx
  • src/lib/mock-data.ts

Validation

  • ✅ TypeScript compilation passes (npx tsc --noEmit)
  • ✅ No type errors in modified files
  • ✅ Reviews persist after page refresh
  • ✅ Reviews display correctly in both database and mock modes
  • ✅ Review list refreshes immediately after submission

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 2, 2026

@novoice-rana is attempting to deploy a commit to the aditthyass' projects Team on Vercel.

A member of the Team first needs to authorize it.

@novoice-rana
Copy link
Copy Markdown
Author

novoice-rana commented Jun 2, 2026

@AditthyaSS please review this pr and merge asap. Fix #34

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.

[Bug] Model detail page does not load reviews from API

1 participant