Skip to content

Commit

Permalink
Merge pull request #801 from haseebzaki-07/new_branch_7
Browse files Browse the repository at this point in the history
Add file upload using Multer and Github
  • Loading branch information
manikumarreddyu authored Nov 5, 2024
2 parents 4cb453a + b131b09 commit d12de86
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ EMAIL_PASS=
ENCRYPTION_SECRET_KEY = # For encrypting data in db (must be 32 bits)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_secret
GITHUB_TOKEN=
GITHUB_REPO_OWNER=
GITHUB_REPO_NAME=
GITHUB_IMAGES_PATH=
ENCRYPTION_SECRET_KEY=

175 changes: 175 additions & 0 deletions backend/package-lock.json

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

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.7.7",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
Expand All @@ -19,6 +20,7 @@
"jest": "^29.7.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^6.9.0",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.9.16",
"nodemon": "^2.0.20",
"passport": "^0.7.0",
Expand Down
32 changes: 32 additions & 0 deletions backend/routes/rent/rentProductRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

const express = require('express');
const router = express.Router();
const multer = require('multer');
const { uploadImageToGitHub } = require('../../services/rent/githubService');
const RentProduct = require('../../model/rent/rentProduct');
const productController = require('../../controllers/rent/RentProductController');
const upload = multer({ dest: 'uploads/' });


// Create a new product
router.post('/rent-products', productController.createProduct);
Expand All @@ -20,10 +25,37 @@ router.put('/rent-products/:id', productController.updateProduct);
router.delete('/rent-products/:id', productController.deleteProduct);


router.post('/rent-products-img', upload.single('image'), async (req, res) => {
const { name, description, price, rating, category } = req.body;

try {

const imageUrl = await uploadImageToGitHub(req.file);


const newProduct = new RentProduct({
name,
description,
price,
image: imageUrl,
rating,
category: category ? category.split(',') : [],
});

await newProduct.save();
res.status(201).json(newProduct);
} catch (error) {
console.error("Error creating product:", error);
res.status(500).json({ message: 'Error creating product' });
}
});



router.get('/filtered-rent-products', productController.getFilteredProducts );





module.exports = router;
Loading

0 comments on commit d12de86

Please sign in to comment.