Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarungupta18 committed Jul 14, 2024
1 parent 6bcbcd5 commit 0d47f21
Show file tree
Hide file tree
Showing 85 changed files with 203 additions and 69 deletions.
30 changes: 28 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
api/node_modules/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?


api/node_modules
api/.env
api/uploads/
Client/node_modules
26 changes: 0 additions & 26 deletions Client/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion Client/src/Image.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function Image({src,...rest}) {
src = src && src.includes('https://')
? src
: 'http://localhost:4000/uploads/'+src;
: src;
return (
<img {...rest} src={src} alt={''} />
);
Expand Down
2 changes: 1 addition & 1 deletion Client/src/PhotosUploader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function PhotosUploader({addedPhotos, onChange}) {
<div className="grid gap-2 grid-cols-3 md:grid-cols-4 lg:grid-cols-6 mt-2">
{addedPhotos.length > 0 && addedPhotos.map(link => (
<div className="h-32 flex relative" key={link}>
<img className='rounded-2xl w-full object-cover' src={"http://localhost:4000/uploads/" + link} />
<img className='rounded-2xl w-full object-cover' src={link} />
<button onClick={ev=> removePhoto(ev, link)} className="cursor-pointer absolute bottom-1 right-1 text-white bg-black py-2 px-3 bg-opacity-50 rounded-2xl">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
Expand Down
4 changes: 2 additions & 2 deletions Client/src/PlaceImg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export default function PlaceImg({ place, index = 0, className=null }) {
return '';
}
if (!className) {
className = 'object-cover w-full h-full';
className = 'object-cover w-32 h-32';
}

return (
<img className={className} src={'http://localhost:4000/uploads/'+place.photos[index]} alt=""/>
<img className={className} src={place.photos[index]} alt=""/>
);
}
41 changes: 28 additions & 13 deletions Client/src/pages/BookingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,34 @@ export default function BookingsPage() {
<div>
<AccountNav />
<div>
{bookings?.length > 0 && bookings.map(booking => (
<Link to={`/account/bookings/${booking._id}`} className="flex gap-4 mb-3 bg-gray-200 rounded-2xl overflow-hidden">
<div className="w-48">
<PlaceImg place={booking.place}/>
</div>
<div className="py-3 pr-3 grow">
<h2 className="text-xl font-bold">{booking.place.title }</h2>
<BookingDates booking={booking} />
<TotalPrice booking={booking} />
</div>

</Link>
))}
{bookings?.length > 0 ? (
bookings.map(booking => (
<Link
to={`/account/bookings/${booking._id}`}
className="flex gap-4 mb-3 bg-gray-200 rounded-2xl overflow-hidden"
key={booking._id}
>
<div className="w-48">
{booking.place && <PlaceImg className="w-full h-full" place={booking.place} />}
</div>
<div className="py-3 pr-3 grow">
{booking.place ? (
<>
<h2 className="text-xl font-bold">{booking.place.title}</h2>
<BookingDates booking={booking} />
<TotalPrice booking={booking} />
</>
) : (
<h2 className="text-xl font-bold -mx-20">Enjoy Place</h2>
)}
</div>
</Link>
))
) : (
<div className="text-center text-gray-500 mt-8">
No bookings found
</div>
)}
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion Client/src/pages/IndexPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function IndexPage() {
<Link to={'/place/'+place._id}>
<div className="bg-gray-500 mb-2 rounded-2xl flex">
{place.photos?.[0] && (
<img className="rounded-2xl object-cover aspect-square" src={"http://localhost:4000/uploads/"+ place.photos?.[0]} alt='' />
<img className="rounded-2xl object-cover aspect-square" src={place.photos?.[0]} alt='' />
)}
</div>
<h2 className="font-bold">{place.address}</h2>
Expand Down
2 changes: 1 addition & 1 deletion Client/src/pages/PlacesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function PlacesPage() {
<div className="mt-4">
{places.length > 0 && places.map(place => (
<Link to={'/account/places/'+place._id} className="flex cursor-pointer bg-gray-100 gap-4 p-4 rounded-2xl">
<div className="flex w-32 h-32 bg-gray-300 grow shrink-0">
<div className="flex w-32 h-32 bg-gray-300 shrink-0">
<PlaceImg place={place}/>
</div>
<div className="grow-0 shrink">
Expand Down
5 changes: 4 additions & 1 deletion api/.env
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
MONGO_URL= 'mongodb+srv://booking:tarun12345@cluster0.a31k2pa.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'
MONGO_URL= 'mongodb+srv://booking:tarun12345@cluster0.a31k2pa.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'
CLOUD_NAME=dygmya3an
CLOUD_API_KEY=365397738923551
CLOUD_API_SECRET=E9n2Lix1o7Xy09UmlCubx7pKHug
22 changes: 22 additions & 0 deletions api/cloudConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require('dotenv').config();
const cloudinary = require('cloudinary').v2;
const { CloudinaryStorage } = require('multer-storage-cloudinary');

cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.CLOUD_API_KEY,
api_secret: process.env.CLOUD_API_SECRET
});

const storage = new CloudinaryStorage({
cloudinary: cloudinary,
params: {
folder: 'stayfinder',
allowedFormets: ["png","jpg","jpeg"],
},
});

module.exports = {
cloudinary,
storage,
};
58 changes: 39 additions & 19 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const express = require("express");
require('dotenv').config();
const cors = require("cors");
const bcrypt = require("bcryptjs");
const mongoose = require("mongoose");
const jwt = require("jsonwebtoken");
const User = require("./models/User.js");
const cookieParser = require("cookie-parser");
const imageDownloader = require("image-downloader");
const multer = require('multer');
const { cloudinary } = require('./cloudConfig.js');
const { storage } = require('./cloudConfig.js');
const fs = require('fs');
const path = require('path');
const Place = require('./models/Place.js');
Expand All @@ -20,15 +22,12 @@ app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.use(cookieParser());
app.use('/uploads', express.static(__dirname + '/uploads'));

app.use(cors({
credentials: true,
origin:'http://localhost:5173'
}));

// console.log(process.env.MONGO_URL);
// mongoose.connect(process.env.MONGO_URL);

main().then(() => {
console.log("connected to db");
Expand Down Expand Up @@ -112,25 +111,46 @@ app.post('/logout', (req, res) => {

app.post('/upload-by-link', async (req, res) => {
const { link } = req.body;
const newName = 'phtoto' + Date.now() + '.jpg';
await imageDownloader.image({
url: link,
dest: __dirname + '/uploads/' + newName,
});
res.json(newName);
})
console.log(link);
try {
const result = await cloudinary.uploader.upload(link, {
folder: 'stayfinder'
});
console.log(result.url);
console.log("done");
res.json(result.url);
} catch (e) {
console.error(e);
res.status(500).json({ error: 'Failed to upload image' });
}
});

const photosMiddleware = multer({ dest: 'uploads' });
app.post("/upload", photosMiddleware.array('photos', 100), (req, res) => {
const photosMiddleware = multer({ storage });
app.post('/upload', photosMiddleware.array('photos', 100), async (req, res) => {
const uploadedFiles = [];

for (let i = 0; i < req.files.length; i++) {
const { path: tempPath, originalname } = req.files[i];
const ext = path.extname(originalname);
const newPath = `${tempPath}${ext}`;
fs.renameSync(tempPath, newPath);
const filename = path.basename(newPath);
uploadedFiles.push(filename);
const { path: tempPath } = req.files[i];

try {
// Upload file to Cloudinary
const result = await cloudinary.uploader.upload(tempPath, {
folder: 'stayfinder'
});

// Store secure URL in uploadedFiles array
uploadedFiles.push(result.secure_url);

// Delete temporary file after upload
fs.unlinkSync(tempPath);
} catch (e) {
console.error('Error uploading file:', e);
res.status(500).json({ error: 'Failed to upload image' });
return;
}
}

// Respond with array of uploaded file URLs
res.json(uploadedFiles);
});

Expand Down
35 changes: 35 additions & 0 deletions api/node_modules/.package-lock.json

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

Loading

0 comments on commit 0d47f21

Please sign in to comment.