Skip to content

Commit

Permalink
Merge pull request #9 from devraushan/productDetailPage_devraushan
Browse files Browse the repository at this point in the history
feat: added product details page for individual products
  • Loading branch information
AdityaKumar5155 authored Apr 6, 2024
2 parents 8d0100b + c78f573 commit 5609404
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 19 deletions.
18 changes: 17 additions & 1 deletion app/controllers/viewControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ const productListView = (req,res)=>{
});
}

const productDetailsView=(req,res)=>{
if(!req.session.isLoggedIn){
res.redirect('/login');
return;
}
const { productId } = req.params
db.query(`SELECT * FROM products WHERE id="${productId}"`,(error,results,fields)=>{
if(error){
console.log('Error executing query: '+error);
res.send(error);
return;
}
res.render("productDetails",{product:results[0],isLoggedIn:req.session.isLoggedIn});
})
}

module.exports = {
loginView,signUpView,forgotPassView,productListView
loginView,signUpView,forgotPassView,productListView,productDetailsView
}
10 changes: 10 additions & 0 deletions app/public/stylesPro.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ header {
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
margin: 10px;
transition: transform 0.25s ease-in-out;
}

.card:hover{
transform: scale(1.03);
}

.product-image {
Expand Down Expand Up @@ -89,3 +94,8 @@ header {
outline: none;
border-color: #007bff;
}

a{
text-decoration: none;
color:inherit;
}
1 change: 1 addition & 0 deletions app/routes/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ router.get('/forgotPass', viewController.forgotPassView)
router.post('/forgotPass', loginController.forgotPass)
router.post('/changePass', loginController.changePass)
router.post('/logout', loginController.logout)
router.get('/product/:productId',viewController.productDetailsView)

module.exports = router;
99 changes: 99 additions & 0 deletions app/views/productDetails.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%=product.name%></title>
</head>
<style>
*{
margin: 0;
}
header{
height: 100px;
display: flex;
align-items: center;
background-color: blue;
color: whitesmoke;
}
header>h1{
text-align: center;
margin: auto;
}
.mainProductContainer{
display: flex;
row-gap: 10px;
}
.subContainer1{
flex: 50%;
margin:20px;
}
.subContainer1>img{
height: 100%;
width: 100%;
}
.subContainer2{
margin: 20px;
flex:50%;
}
.colorVariantContainer{
display: flex;
}
.colorVariant{
margin: 2px;
height: 20px;
width: 20px;
border-radius: 50%;
}
.description{
margin-top: 20px;
width: 50%;
}
p{
margin:10px 0;
font-size: 1.1rem;
}
.productName{
color: rgb(4, 4, 82);
}
@media only screen and (max-width: 1025px) {
.mainProductContainer{
flex-direction: column;
}
}
</style>
<body>
<header>
<h1>InsecureNet</h1>
</header>
<div class="mainProductContainer">
<div class="subContainer1">
<img src=<%=product.image%>/>

</div>
<div class="subContainer2">
<h1 class="productName"><%=product.name%></h1>
<p><strong>Category : </strong><%=product.category%></p>
<p><strong>Company : </strong> <%=product.company %></p>
<p><strong>Price : </strong><%=product.price %> INR</p>
<div>
<h3>Available Colour Variants : </h3>
<div class="colorVariantContainer">
<% product.colors.forEach(color=>{ %>
<div class="colorVariant" style="background-color: <%= color%>;" ></div>
<% }) %>
</div>
</div>
<div class="description">
<p><%=product.description%></p>
</div>
<p style="color:#1877f2;"><strong>Featured: </strong><%=(product.featured==1)?"Yes":"No"%></p>
<p style="color:#1877f2;"><strong>Shipping: </strong><%=(product.shipping==1)?"Yes":"No"%></p>
<a href="/">Back To Home</a>
</div>
</div>
</body>
</html>
38 changes: 20 additions & 18 deletions app/views/products.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@

<div class="container">
<% products.forEach(product => { %>
<div class="card">
<img src="<%= product.image %>" alt="<%= product.name %>" class="product-image">
<div class="product-details">
<h2><%= product.name %></h2>
<p class="company"><strong>Company:</strong> <%= product.company %></p>
<p class="price"><strong>Price:</strong> <%= product.price %></p>
<p class="category"><strong>Category:</strong> <%= product.category %></p>
<% if (product.featured) { %>
<p class="featured"><strong>Featured:</strong> Yes</p>
<% } else { %>
<p class="featured"><strong>Featured:</strong> No</p>
<% } %>
<% if (product.shipping) { %>
<p class="shipping"><strong>Shipping:</strong> Yes</p>
<% } else { %>
<p class="shipping"><strong>Shipping:</strong> No</p>
<% } %>
<a href="/product/<%=product.id%>">
<div class="card">
<img src="<%= product.image %>" alt="<%= product.name %>" class="product-image">
<div class="product-details">
<h2><%= product.name %></h2>
<p class="company"><strong>Company:</strong> <%= product.company %></p>
<p class="price"><strong>Price:</strong> <%= product.price %></p>
<p class="category"><strong>Category:</strong> <%= product.category %></p>
<% if (product.featured) { %>
<p class="featured"><strong>Featured:</strong> Yes</p>
<% } else { %>
<p class="featured"><strong>Featured:</strong> No</p>
<% } %>
<% if (product.shipping) { %>
<p class="shipping"><strong>Shipping:</strong> Yes</p>
<% } else { %>
<p class="shipping"><strong>Shipping:</strong> No</p>
<% } %>
</div>
</div>
</div>
</a>
<% }); %>
</div>
</body>
Expand Down

0 comments on commit 5609404

Please sign in to comment.