Skip to content

Commit

Permalink
new features added
Browse files Browse the repository at this point in the history
  • Loading branch information
Amarjha01 committed Sep 17, 2024
1 parent ee00333 commit 8e5f64e
Show file tree
Hide file tree
Showing 27 changed files with 753 additions and 175 deletions.
10 changes: 10 additions & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MONGODB_URI = mongodb+srv://amarjha880:[email protected]/E-commerce?retryWrites=true&w=majority&appName=E-commerce


TOKEN_SECRET_KEY = "Sjhhhhhhgyuuyfdstgfvuyuy6876yuggbfdtrde56essGFHTFJGUYF4"






2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.env
# .env
node_modules
14 changes: 0 additions & 14 deletions backend/common/index.js

This file was deleted.

32 changes: 32 additions & 0 deletions backend/controller/product/searchProduct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ProductModel from "../../models/productModel.js";

const searchProduct = async (req, res) => {
try {

const query = req.query.q;
const regex = RegExp(query,'i','g');
const searchedProduct = await ProductModel.find({
'$or':[
{
brandName: regex
},
{
category: regex
},
{
productName: regex
},
]
})

res.status(200).json({
message: "searchedProduct list",
data: searchedProduct,
});
} catch (error) {
res.status(400).json({
err: error.message,
});
}
};
export default searchProduct;
27 changes: 27 additions & 0 deletions backend/controller/user/deleteAddToCartProduct.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import addToCartModel from "../../models/cartProductModel.js";

const deleteAddToCartProduct = async (req, res) => {
try {

const AddToCartProductId = req.body._id;

const deleteProduct = await addToCartModel.deleteOne({_id : AddToCartProductId});
res.status(201).json({
message : 'Product deleted successfully',
success : true,
error : false,
data : deleteProduct
})


} catch (error) {
res.status(404).json({
message : error.message || error,
success : false,
error : true
})
}

}

export default deleteAddToCartProduct;
13 changes: 0 additions & 13 deletions backend/controller/user/deleteAddToCartProduct.jsx

This file was deleted.

31 changes: 31 additions & 0 deletions backend/controller/user/displayUserAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import userAddressModel from "../../models/userAddressModel.js";


const displayUserAddress = async (req, res) => {
try {
const currentUserId = req.userID;


const userAddress = await userAddressModel.find({userId: currentUserId});

res.status(200).json({
message: "User Address fetched successfully",
success: true,
error: false,
data: userAddress

});
console.log('userAddress: ',userAddress)
} catch (error) {
console.log(error);
res.status(400).json({
message: error.message,
error: true,
success: false

});

}
}

export default displayUserAddress;
Empty file.
32 changes: 32 additions & 0 deletions backend/controller/user/userAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import userAddressModel from '../../models/userAddressModel.js';

const userAddress = async (req, res) => {

try {
const userShippingAddress = req.body;

const userId = req.userID;
console.log('userId: ',userId)
const payload = {
...userShippingAddress,
userId: userId,

};
const userAddress = new userAddressModel(payload);
const savedUserAddress = await userAddress.save();
res.status(200).json({
message: "User Address Saved Successfully",
data: savedUserAddress,
error: false,
success: true
});

console.log('userShippingAddress: ',userShippingAddress)
} catch (error) {
console.log(error);
res.status(500).json({message: "Internal Server Error"});

}
}

export default userAddress;
2 changes: 1 addition & 1 deletion backend/controller/user/viewAddToCart.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const viewAddToCart = async (req, res) => {
error: false,
data: cartDetails,
});
console.log("cartDetails:", cartDetails);
// console.log("cartDetails:", cartDetails);
} catch (error) {
res.status(500).json({
message: error?.message || error,
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/usersignup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function usersignupcontroller(req, res) {
const hashpassword = await bcrypt.hash(password, salt);

if (!hashpassword) {
console.log("Something is wrong");
console.log("Password not hashed");
}

const payload = {
Expand Down
54 changes: 2 additions & 52 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
// import express from "express";
// import cors from "cors";
// import cookieParser from 'cookie-parser'
// import "dotenv/config";
// import dbconnect from "./config/database/dbconnect.js";
// import router from "./routes/routes.js";

// const app = express();
// const PORT = process.env.PORT || 5000;

// // Middleware
// const allowedOrigins = [
// // process.env.FRONTEND_URL,
// // process.env.FRONTEND_URL2,
// // 'http://localhost:5173',
// 'https://www.electramart.ninja',
// 'https://electramart.ninja'
// ];

// app.use(cors({
// origin: function (origin, callback) {
// if (!origin || allowedOrigins.indexOf(origin) !== -1) {
// callback(null, true);
// } else {
// callback(new Error('Not allowed by CORS'));
// }
// },
// credentials: true,
// methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
// allowedHeaders: ['Content-Type', 'Authorization'],
// preflightContinue: false,
// optionsSuccessStatus: 204
// }));
// app.options('*', cors({
// origin: allowedOrigins,
// credentials: true,
// methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
// allowedHeaders: ['Content-Type', 'Authorization']
// }));

// app.use(express.json());
// app.use(cookieParser())

// app.use("/api", router);

// dbconnect().then(() => {
// app.listen(PORT, '0.0.0.0',() => {
// console.log(`Server is running on port: ${PORT}`);
// });
// });

import express from "express";
import cors from "cors";
import cookieParser from 'cookie-parser';
Expand All @@ -64,7 +13,8 @@ const allowedOrigins = [
'http://localhost:3000',
'http://localhost:5173',
'https://www.electramart.ninja',
'https://electramart.ninja'
'https://electramart.ninja',

];

app.use(cors({
Expand Down
16 changes: 16 additions & 0 deletions backend/models/userAddressModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import mongoose from "mongoose";

const userAddressSchema = mongoose.Schema({
userId: String,
fullName: String,
landMark: String,
address: String,
state: String,
postalCode: String,
contactNumber: String,
} ,{
timestamps: true
});

const userAddress = mongoose.model('UserAddress', userAddressSchema);
export default userAddress;
8 changes: 8 additions & 0 deletions backend/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import addToCartController from '../controller/user/addToCart.js';
import countAddToCartProduct from '../controller/user/countAddToCartProduct.js';
import viewAddToCart from '../controller/user/viewAddToCart.js'
import updateAddToCartProduct from '../controller/user/updateAddToCartProduct.js'
import deleteAddToCartProduct from '../controller/user/deleteAddToCartProduct.js';
import searchProduct from '../controller/product/searchProduct.js'
import userAddress from '../controller/user/userAddress.js';
import displayUserAddress from '../controller/user/displayUserAddress.js';
// Set up routes
router.post('/signup', usersignupcontroller);
router.post('/signin', userSignInController);
Expand All @@ -35,5 +39,9 @@ router.post('/addtocart',authtoken, addToCartController);
router.get('/countaddtocartproduct',authtoken, countAddToCartProduct);
router.get('/cartDetail',authtoken, viewAddToCart);
router.post('/updateCartProductQuantity',authtoken, updateAddToCartProduct);
router.delete('/deleteCartProduct',authtoken, deleteAddToCartProduct);
router.get('/search', searchProduct)
router.post('/shippingAddress',authtoken, userAddress);
router.get('/displayuseraddress',authtoken, displayUserAddress);

export default router;
17 changes: 17 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"postcss-cli": "^11.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-icons": "^5.2.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.24.0",
Expand Down
15 changes: 14 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Outlet } from "react-router-dom";
import "./App.css";
import Header from "./components/Header";
import Footer from "./components/Footer";
import paymentGetway from './pages/PaymentGetway'
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import summaryApi from "./common/index";
Expand All @@ -11,6 +12,7 @@ import { useDispatch } from "react-redux";
import { setUserDetails } from "./store/userSlice";
function App() {
const dispatch = useDispatch();
const [subTotal, setSubTotal] = useState(0);
const [cartProductCount, setCartProductCount] = useState(0);

const fetchUserDetails = async () => {
Expand Down Expand Up @@ -43,6 +45,15 @@ const fetchUserAddToCart = async () => {
fetchUserDetails();
// user cart count
fetchUserAddToCart()


// Function to receive subtotal price from Cart component
const handleSetSubtotalPrice = (price) => {
setSubTotal(price); // Update subtotal price in the parent
};



}, []);


Expand All @@ -53,10 +64,12 @@ const fetchUserAddToCart = async () => {
<ToastContainer position= 'top-center' />

<Header />

<main className="min-h-[calc(100vh-118px)] pt-14">
<Outlet />
<Outlet />
</main>
<Footer />


</context.Provider>
</>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/asset/randum/blob.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8e5f64e

Please sign in to comment.