From e0ca4cabb2fe1597842c98e4e87dce10fa764531 Mon Sep 17 00:00:00 2001 From: sadneya145 Date: Mon, 10 Feb 2025 23:14:16 +0530 Subject: [PATCH] added subscription boxes,product recommendation, mood board and vinatge storie --- Html-files/menu.html | 52 ++++++- Html-files/mood_board.html | 265 ++++++++++++++++++++++++++++++++ Html-files/productRecommend.js | 78 ++++++++++ Html-files/services.html | 2 +- Html-files/subscriptionBox.html | 73 +++++++++ Html-files/thankyou.html | 113 ++++++++++++++ Html-files/vintageStories.html | 163 ++++++++++++++++++++ backend/app.js | 4 + backend/model/productSchema.js | 12 ++ backend/router/productRoute.js | 60 ++++++++ 10 files changed, 818 insertions(+), 4 deletions(-) create mode 100644 Html-files/mood_board.html create mode 100644 Html-files/productRecommend.js create mode 100644 Html-files/subscriptionBox.html create mode 100644 Html-files/thankyou.html create mode 100644 Html-files/vintageStories.html create mode 100644 backend/model/productSchema.js create mode 100644 backend/router/productRoute.js diff --git a/Html-files/menu.html b/Html-files/menu.html index e36a44fc..b546ab99 100644 --- a/Html-files/menu.html +++ b/Html-files/menu.html @@ -6,11 +6,11 @@ Retro - + - + @@ -764,7 +797,14 @@

Palsnkin

- +
+

Recommended for You

+
+
+ +
+ 💬 +
+ +
diff --git a/Html-files/mood_board.html b/Html-files/mood_board.html new file mode 100644 index 00000000..0cc8371b --- /dev/null +++ b/Html-files/mood_board.html @@ -0,0 +1,265 @@ + + + + + + RETRO Mood Board + + + + +
+

RETRO Mood Board Creator

+
+ + + + +
+
+ +
+ + + + diff --git a/Html-files/productRecommend.js b/Html-files/productRecommend.js new file mode 100644 index 00000000..a446225c --- /dev/null +++ b/Html-files/productRecommend.js @@ -0,0 +1,78 @@ +document.addEventListener("DOMContentLoaded", async function () { + const recommendationContainer = document.querySelector(".recommendation-container"); + + if (!recommendationContainer) { + console.error("Recommendation container not found!"); + return; + } + + async function fetchProducts() { + try { + const response = await fetch("http://localhost:5000/productget"); + if (!response.ok) { + throw new Error("Failed to fetch products"); + } + const products = await response.json(); + + if (!Array.isArray(products) || products.length === 0) { + recommendationContainer.innerHTML = "

No products available.

"; + return; + } + + // Shuffle array and pick up to 4 random products + const shuffledProducts = [...products].sort(() => Math.random() - 0.5).slice(0, 4); + + displayProducts(shuffledProducts); + } catch (error) { + console.error("Error fetching products:", error); + recommendationContainer.innerHTML = "

Error loading products. Please try again later.

"; + } + } + + function displayProducts(products) { + recommendationContainer.innerHTML = ""; + + products.forEach(product => { + const productCard = document.createElement("div"); + productCard.classList.add("product-card"); + + productCard.innerHTML = ` + ${product.name} +

${product.name}

+

${product.description}

+

Price: $${parseFloat(product.price).toFixed(2)}

+ + `; + + recommendationContainer.appendChild(productCard); + }); + + attachCartEventListeners(); + } + + function attachCartEventListeners() { + document.querySelectorAll(".add-to-cart").forEach(button => { + button.addEventListener("click", function () { + const productId = this.getAttribute("data-id"); + const productName = this.getAttribute("data-name"); + const productPrice = parseFloat(this.getAttribute("data-price")); + + let cartItems = JSON.parse(localStorage.getItem("cartItems")) || []; + + const existingItem = cartItems.find(item => item.id === productId); + if (existingItem) { + existingItem.quantity += 1; + } else { + cartItems.push({ id: productId, name: productName, price: productPrice, quantity: 1 }); + } + + localStorage.setItem("cartItems", JSON.stringify(cartItems)); + alert(`${productName} added to cart!`); + }); + }); + } + + fetchProducts(); +}); diff --git a/Html-files/services.html b/Html-files/services.html index 5aef4ccf..921f39d6 100644 --- a/Html-files/services.html +++ b/Html-files/services.html @@ -449,7 +449,7 @@

Servic Retro Delivery Subscription

Retro Delivery Subscription

diff --git a/Html-files/subscriptionBox.html b/Html-files/subscriptionBox.html new file mode 100644 index 00000000..41041eb6 --- /dev/null +++ b/Html-files/subscriptionBox.html @@ -0,0 +1,73 @@ + + + + + + RETRO Subscription Boxes + + + +
+

Subscription Boxes

+

Steady Revenue Stream: Subscription boxes provide consistent income through recurring orders, helping RETRO maintain steady cash flow.

+

Enhanced Customer Loyalty: The surprise and excitement of receiving curated items each month will keep users engaged and coming back for more.

+

Brand Differentiation: Offering curated vintage items in a subscription model will set RETRO apart from competitors and foster a sense of exclusivity among subscribers.

+ + +
+ + + + diff --git a/Html-files/thankyou.html b/Html-files/thankyou.html new file mode 100644 index 00000000..c97052ea --- /dev/null +++ b/Html-files/thankyou.html @@ -0,0 +1,113 @@ + + + + + + Thank You for Subscribing + + + + +
🎉 Thank You for Subscribing! 🎉
+

Enjoy exclusive vintage items every month. Check out some of our best products below!

+ +
+ +
+ Vintage Camera +

Vintage Polaroid Camera

+

Classic instant camera with retro vibes.

+ View More +
+ + +
+ Vinyl Record +

Retro Vinyl Record

+

Authentic vintage record for classic music lovers.

+ View More +
+ + +
+ Antique Watch +

Antique Pocket Watch

+

Timeless elegance in a golden pocket watch.

+ View More +
+ + +
+ Vintage Typewriter +

Classic Typewriter

+

Experience the charm of traditional writing.

+ View More +
+
+ + + diff --git a/Html-files/vintageStories.html b/Html-files/vintageStories.html new file mode 100644 index 00000000..6526c678 --- /dev/null +++ b/Html-files/vintageStories.html @@ -0,0 +1,163 @@ + + + + + + + Vintage Storytelling Chatbot + + + +

Vintage Storytelling Chatbot

+ +
+
+

Bot: Ask me about vintage products!

+
+ + +
+ + + + diff --git a/backend/app.js b/backend/app.js index f13cf54f..a50e387d 100644 --- a/backend/app.js +++ b/backend/app.js @@ -8,6 +8,8 @@ const cors = require('cors'); const csrf = require('csurf'); const rateLimit = require('express-rate-limit'); +const productRouter = require("./router/productRoute.js"); + // Initialize CSRF Protection const csrfProtect = csrf({ cookie: true }); @@ -33,6 +35,7 @@ app.get('/csrf-token', csrfProtect, (req, res) => { // Auth routes app.use('/api/auth', csrfProtect, limiter, authRouter); +app.use("/api/products", productRouter); // Global error handler app.use((err, req, res, next) => { @@ -43,4 +46,5 @@ app.use((err, req, res, next) => { } }); + module.exports = app; diff --git a/backend/model/productSchema.js b/backend/model/productSchema.js new file mode 100644 index 00000000..d206391e --- /dev/null +++ b/backend/model/productSchema.js @@ -0,0 +1,12 @@ +const mongoose = require("mongoose"); + +const productSchema = new mongoose.Schema({ + name: { type: String, required: true }, + price: { type: Number, required: true }, + description: { type: String, required: true }, + imageUrl: { type: String, required: true }, +}); + +const Product = mongoose.model("Product", productSchema); + +module.exports = Product; diff --git a/backend/router/productRoute.js b/backend/router/productRoute.js new file mode 100644 index 00000000..2f9340bc --- /dev/null +++ b/backend/router/productRoute.js @@ -0,0 +1,60 @@ +const express = require("express"); +const router = express.Router(); +const Product = require("../model/productSchema"); + +// Middleware to handle CORS +router.use((req, res, next) => { + res.header("Access-Control-Allow-Origin", "*"); // Adjust if needed + res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); + res.header("Access-Control-Allow-Headers", "Content-Type"); + next(); +}); + +// Get all products +router.get("/productget", async (req, res) => { + try { + const products = await Product.find(); + if (products.length === 0) { + return res.status(404).json({ error: "No products found" }); + } + res.json(products); + } catch (error) { + console.error("Error fetching products:", error); + res.status(500).json({ error: "Internal Server Error" }); + } +}); + +// Get a product by ID +router.get("/productget/:id", async (req, res) => { + try { + const product = await Product.findById(req.params.id); + if (!product) { + return res.status(404).json({ error: "Product not found" }); + } + res.json(product); + } catch (error) { + console.error("Error fetching product:", error); + res.status(500).json({ error: "Invalid Product ID or Internal Server Error" }); + } +}); + +// Add a new product +router.post("/productpost", async (req, res) => { + try { + const { name, price, description, imageUrl } = req.body; + + // Check if all required fields are provided + if (!name || !price || !description || !imageUrl) { + return res.status(400).json({ error: "All fields are required" }); + } + + const newProduct = new Product({ name, price, description, imageUrl }); + await newProduct.save(); + res.status(201).json({ message: "Product added successfully", product: newProduct }); + } catch (error) { + console.error("Error adding product:", error); + res.status(400).json({ error: "Invalid product data" }); + } +}); + +module.exports = router;