Skip to content

feat: Add E-Commerce Shopping App - product routes, views, and layouts#3

Merged
ayush-68789 merged 1 commit into
jaikaran109:mainfrom
ayush-68789:feat-ecommerce-shopping-app
Jun 7, 2026
Merged

feat: Add E-Commerce Shopping App - product routes, views, and layouts#3
ayush-68789 merged 1 commit into
jaikaran109:mainfrom
ayush-68789:feat-ecommerce-shopping-app

Conversation

@ayush-68789

@ayush-68789 ayush-68789 commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

Description

Please provide a brief summary of the changes made.


Related Issue

Fixes #


Type of Change

  • Bug Fix
  • New Feature
  • Enhancement
  • Documentation Update
  • UI/UX Improvement

Screenshots

Attach screenshots or screen recordings if applicable.


Checklist

  • My code follows the project guidelines
  • I have tested my changes locally
  • I have updated documentation if needed
  • My changes do not break existing functionality

Additional Notes

Add any additional information here.

Summary by CodeRabbit

  • New Features
    • Added navigation bar with links to browse products and create new items
    • New product form allowing users to submit product details (name, image, price, description)
    • Product detail page displaying individual product information with "Add to Cart" and "Buy" options
    • Improved grid-based product listing layout for better browsing experience

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

👋 Welcome @ayush-68789!

Thank you for contributing to 51 Web Projects 🚀

Please ensure you have:

  • Read CONTRIBUTING.md
  • Followed project guidelines
  • Tested your changes

Happy Coding! 🎉

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR integrates the ejs-mate template engine to establish a reusable layout system, adds product creation and viewing routes, and implements corresponding views. The changes include dependency setup, shared HTML templates, new API endpoints, and product-specific form and display pages.

Changes

Product Management with EJS Layout

Layer / File(s) Summary
EJS engine and server configuration
package.json, server.js
ejs-mate dependency is added and configured in Express via app.engine('ejs', ejsmate) alongside middleware for parsing URL-encoded form bodies.
View layout foundation
views/layouts/boilerPlate.ejs, views/partials/navbar.ejs
Shared boilerplate layout provides HTML structure and Bootstrap assets with a <%- body %> injection point; navbar partial renders responsive navigation with links to /products and /product/new plus a search form.
Product management routes
routes/product.js
Three new routes handle product workflow: GET /product/new renders the form, POST /products creates a product from request body fields, and GET /products/:id fetches and displays a product by ID.
Product creation and detail views
views/products/new.ejs, views/products/show.ejs, views/products/index.ejs
New form view accepts product name, image, price, and description; details view displays product information with action buttons; index view is refactored to use the shared layout, navbar, and Bootstrap grid with a "View" link to product details.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A template foundation laid so neat,
With layouts shared and views complete,
New products form and details show,
From routes that help the data flow,
Bootstrap magic, ejs-mate's art,
E-commerce dreams now have a start!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is a blank template with only the 'Enhancement' checkbox marked; no actual summary of changes, related issues, or implementation details are provided. Fill in the Description section with a summary of the changes made (product routes, views, layouts added). Mark the Related Issue field, complete the checklist items, and provide any relevant screenshots or additional context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main additions: product routes, views, and layout infrastructure for an e-commerce shopping app, matching the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@10-E-Commerce-Shopping-App/routes/product.js`:
- Around line 23-26: The route handler registered with
Router.get('/products/:id') currently awaits Products.findById(id) and always
calls res.render('products/show', {prod}), which will crash on malformed IDs or
render when prod is null; wrap the lookup in a try/catch, validate the id first
(e.g. using mongoose.isValidObjectId or equivalent) and return a 400 for
malformed IDs, and if Products.findById(id) returns null respond with a 404 (or
call next() with a NotFound error) instead of rendering; ensure the handler (the
async function that uses variables id and prod) logs or forwards real errors
from the database query in the catch block.

In `@10-E-Commerce-Shopping-App/views/products/new.ejs`:
- Line 1: The layout path casing in the template is wrong: replace the call
layout('layouts/boilerplate.ejs') with the exact filename casing used in the
project (views/layouts/boilerPlate.ejs) so the view engine can find the layout
on case-sensitive filesystems; update any other product templates that call
layout('layouts/boilerplate.ejs') to use layout('layouts/boilerPlate.ejs') to
keep naming consistent (search for the layout('layouts/boiler') usages and
correct them).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b0c3a126-f8b4-43c0-a126-8b2a60acdca0

📥 Commits

Reviewing files that changed from the base of the PR and between c379519 and e9d06df.

📒 Files selected for processing (8)
  • 10-E-Commerce-Shopping-App/package.json
  • 10-E-Commerce-Shopping-App/routes/product.js
  • 10-E-Commerce-Shopping-App/server.js
  • 10-E-Commerce-Shopping-App/views/layouts/boilerPlate.ejs
  • 10-E-Commerce-Shopping-App/views/partials/navbar.ejs
  • 10-E-Commerce-Shopping-App/views/products/index.ejs
  • 10-E-Commerce-Shopping-App/views/products/new.ejs
  • 10-E-Commerce-Shopping-App/views/products/show.ejs

Comment on lines +23 to +26
Router.get('/products/:id', async (req ,res)=> {
let {id} = req.params ;
let prod = await Products.findById(id) ;
res.render('products/show', {prod}) ;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle invalid/non-existent product IDs before rendering.

Line [25] can fail on malformed IDs, and Line [26] renders even when prod is null. This turns normal “not found” cases into 500s.

Suggested fix
+const mongoose = require('mongoose');

 Router.get('/products/:id', async (req ,res)=> {
     let {id} = req.params ;
+    if (!mongoose.Types.ObjectId.isValid(id)) {
+        return res.status(404).send('Product not found');
+    }
     let prod = await Products.findById(id) ;
+    if (!prod) {
+        return res.status(404).send('Product not found');
+    }
     res.render('products/show', {prod}) ;
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Router.get('/products/:id', async (req ,res)=> {
let {id} = req.params ;
let prod = await Products.findById(id) ;
res.render('products/show', {prod}) ;
const mongoose = require('mongoose');
Router.get('/products/:id', async (req ,res)=> {
let {id} = req.params ;
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(404).send('Product not found');
}
let prod = await Products.findById(id) ;
if (!prod) {
return res.status(404).send('Product not found');
}
res.render('products/show', {prod}) ;
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@10-E-Commerce-Shopping-App/routes/product.js` around lines 23 - 26, The route
handler registered with Router.get('/products/:id') currently awaits
Products.findById(id) and always calls res.render('products/show', {prod}),
which will crash on malformed IDs or render when prod is null; wrap the lookup
in a try/catch, validate the id first (e.g. using mongoose.isValidObjectId or
equivalent) and return a 400 for malformed IDs, and if Products.findById(id)
returns null respond with a 404 (or call next() with a NotFound error) instead
of rendering; ensure the handler (the async function that uses variables id and
prod) logs or forwards real errors from the database query in the catch block.

@@ -0,0 +1,25 @@
<% layout('layouts/boilerplate.ejs') %>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix layout path casing mismatch.

Line [1] references layouts/boilerplate.ejs, but the layout file is views/layouts/boilerPlate.ejs. On case-sensitive systems this breaks rendering.

Suggested fix (apply consistently in product templates)
-<% layout('layouts/boilerplate.ejs') %>
+<% layout('layouts/boilerPlate.ejs') %>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<% layout('layouts/boilerplate.ejs') %>
<% layout('layouts/boilerPlate.ejs') %>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@10-E-Commerce-Shopping-App/views/products/new.ejs` at line 1, The layout path
casing in the template is wrong: replace the call
layout('layouts/boilerplate.ejs') with the exact filename casing used in the
project (views/layouts/boilerPlate.ejs) so the view engine can find the layout
on case-sensitive filesystems; update any other product templates that call
layout('layouts/boilerplate.ejs') to use layout('layouts/boilerPlate.ejs') to
keep naming consistent (search for the layout('layouts/boiler') usages and
correct them).

@ayush-68789 ayush-68789 merged commit 77fefc0 into jaikaran109:main Jun 7, 2026
2 checks passed
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.

1 participant