Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
node_modules/
/.pnp
.pnp.js

# testing
/coverage

# production
/frontend/build

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
18 changes: 18 additions & 0 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require("dotenv").config();
const mongoose = require("mongoose");

const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});

console.log("MongoDB connection SUCCESS");
} catch (error) {
console.error("MongoDB connection FAIL");fkf
process.exit(1);
}
};

module.exports = connectDB;
27 changes: 27 additions & 0 deletions backend/controller/productControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Product = require("../models/Product");

const getProducts = async (req, res) => {
try {
const products = await Product.find({});
res.json(products);
} catch (error) {
console.error(error);
res.status(500).json({ message: "Server Error" });
}
};

const getProductById = async (req, res) => {
try {
const product = await Product.findById(req.params.id);

res.json(product);
} catch (error) {
console.error(error);
res.status(500).json({ message: "Server Error" });
}
};

module.exports = {
getProducts,
getProductById,
};
58 changes: 58 additions & 0 deletions backend/data/products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const products = [
{
name: "PlayStation 5",
imageUrl:
"https://images.unsplash.com/photo-1606813907291-d86efa9b94db?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80",
description:
"PlayStation 5 (PS5) is a home video game console developed by Sony Interactive Entertainment. Announced in 2019 as the successor to the PlayStation 4, the PS5 was released on November 12, 2020 in Australia, Japan, New Zealand, North America, Singapore, and South Korea, and November 19, 2020 onwards in other major markets except China and India.",
price: 499,
countInStock: 15,
},
{
name: "Iphone 12",
imageUrl:
"https://images.unsplash.com/photo-1605787020600-b9ebd5df1d07?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1463&q=80",
description:
"Welcome to a new era of iPhone. Beautifully bright 6.1-inch Super Retina XDR display.1 Ceramic Shield with 4x better drop performance.2 Incredible low-light photography with Night mode on all cameras. Cinema-grade Dolby Vision video recording, editing, and playback. Powerful A14 Bionic chip. And new MagSafe accessories for easy attach and faster wireless charging.3 Let the fun begin.",
price: 1099,
countInStock: 10,
},
{
name: "Cannon EOS-1D",
imageUrl:
"https://images.unsplash.com/photo-1519183071298-a2962feb14f4?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80",
description:
"The EOS-1D X combines speed with image quality, to create the next generation camera for professionals. Full frame 18 megapixel sensor with Dual “DIGIC 5+” processors sets the standard, and up to 12 frames per second shooting takes it beyond.",
price: 1300,
countInStock: 5,
},
{
name: "Amazon Alexa",
imageUrl:
"https://images.unsplash.com/photo-1518444065439-e933c06ce9cd?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1267&q=80",
description:
"It is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic, sports, and other real-time information, such as news. Alexa can also control several smart devices using itself as a home automation system.",
price: 50,
countInStock: 25,
},
{
name: "Audio Technica Headphones",
imageUrl:
"https://images.unsplash.com/photo-1558756520-22cfe5d382ca?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80",
description:
"Outfitted with 45mm large-aperture dynamic drivers and an over-ear, closed-back design, the ATH-M50x headphones deliver clarity, deep bass, and extended bandwidth (15 Hz to 28 kHz) while isolating you from outside sounds.",
price: 233,
countInStock: 4,
},
{
name: "JBL FLIP 4",
imageUrl:
"https://images.unsplash.com/photo-1564424224827-cd24b8915874?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1489&q=80",
description:
"JBL Flip 4 is the next generation in the award-winning Flip series; it is a portable Bluetooth speaker that delivers surprisingly powerful stereo sound. This compact speaker is powered by a 3000mAh rechargeable Li-ion battery that offers up to 12 hours of continuous, high-quality audio playtime.",
price: 140,
countInStock: 10,
},
];

module.exports = products;
28 changes: 28 additions & 0 deletions backend/models/Product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const mongoose = require("mongoose");

const productSchema = mongoose.Schema({
name: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
price: {
type: Number,
required: true,
},
countInStock: {
type: Number,
required: true,
},
imageUrl: {
type: String,
required: true,
},
});

const Product = mongoose.model("product", productSchema);

module.exports = Product;
11 changes: 11 additions & 0 deletions backend/routes/productRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require("express");
const router = express.Router();
const {
getProducts,
getProductById,
} = require("../controller/productControllers");

router.get("/", getProducts);
router.get("/:id", getProductById);

module.exports = router;
24 changes: 24 additions & 0 deletions backend/seederScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require("dotenv").config();

const productData = require("./data/products");
const connectDB = require("./config/db");
const Product = require("./models/Product");

connectDB();

const importData = async () => {
try {
await Product.deleteMany({});

await Product.insertMany(productData);

console.log("Data Import Success");

process.exit();
} catch (error) {
console.error("Error with data import", error);
process.exit(1);
}
};

importData();
19 changes: 19 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require("dotenv").config();
const express = require("express");
const productRoutes = require("./routes/productRoutes");
const connectDB = require("./config/db");

connectDB();

const app = express();

app.use(express.json());

app.get("/", (req, res) => {
res.json({ message: "API running..." });
});

app.use("/api/products", productRoutes);

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
5 changes: 5 additions & 0 deletions frontend/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[1220/144115.616:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[1220/172958.186:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[1220/175513.621:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[1220/210011.835:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[1221/082048.711:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
Loading