G Mart Review
G Mart Review
Objective:
Modules:
1. Frontend (React.js):
o User-friendly interface for browsing products.
o Categories, search, and filter options for easy navigation.
o Responsive design for enhanced user experience.
2. Backend (Node.js, Express.js):
o RESTful API to handle user requests.
o Middleware for authentication and error handling.
3. Database (MongoDB):
o Schema for users, products, orders, and categories.
o Data storage for efficient retrieval and management.
4. Admin Panel:
o Product management (add/edit/delete).
o Order tracking and management.
o Role-based authentication to secure admin access.
5. Payment Integration:
o PayPal gateway setup using public and private keys.
o Secure transactions for customer purchases.
Implementation Steps:
Features Implemented:
1. User Interface:
o Displays a categorized list of grocery items with images.
o Users can browse products and add them to the cart.
2. Admin Role:
o Added new products with categories and uploaded images.
o Managed orders and tracked customer transactions.
3. Secure Payments:
o Integrated PayPal for payment processing.
o Used public and private keys to ensure transaction security.
Challenges Faced:
bash
npm init -y
npm install express mongoose body-parser cors dotenv
Create server.js:
javascript
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cors = require('cors');
require('dotenv').config();
// Middleware
app.use(cors());
app.use(bodyParser.json());
// MongoDB Connection
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('MongoDB connected'))
.catch(err => console.error('MongoDB connection error:', err));
// Routes
app.get('/products', async (req, res) => {
const products = await Product.find();
res.json(products);
});
env
MONGO_URI=your_mongodb_connection_string
2. Frontend: React
bash
Copy code
npx create-react-app frontend
cd frontend
npm install axios
javascript
import React, { useState, useEffect } from 'react';
import axios from 'axios';
// Add Product
const addProduct = () => {
axios.post('http://localhost:5000/products', newProduct)
.then(res => {
setProducts([...products, res.data]);
setNewProduct({ name: '', price: '' });
})
.catch(err => console.error(err));
};
return (
<div style={{ padding: '20px' }}>
<h1>Product List</h1>
<ul>
{products.map(product => (
<li key={product._id}>{product.name} - $
{product.price}</li>
))}
</ul>
<h2>Add Product</h2>
<input
type="text"
placeholder="Name"
value={newProduct.name}
onChange={e => setNewProduct({ ...newProduct, name:
e.target.value })}
/>
<input
type="number"
placeholder="Price"
value={newProduct.price}
onChange={e => setNewProduct({ ...newProduct, price:
e.target.value })}
/>
<button onClick={addProduct}>Add</button>
</div>
);
};
bash
Copy code
node server.js
bash
Copy code
npm start
4. Folder Structure
project
│
├── backend
│ ├── server.js
│ ├── package.json
│ ├── .env
│
└── frontend
├── src
│ ├── App.js
├── package.json