Skip to content

Commit

Permalink
issue51
Browse files Browse the repository at this point in the history
  • Loading branch information
ash-k121 committed Oct 5, 2024
1 parent c484e45 commit 7439571
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 80 deletions.
22 changes: 22 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ app.use('/auth', authRoutes);
app.get('/', (req, res) => {
res.send('Working...');
});
const Ticket = mongoose.model('Ticket', ticketSchema);

// Routes
app.post('/api/tickets/search', async (req, res) => {
const { source, destination } = req.body;

if (!source || !destination) {
return res.status(400).json({ message: 'Source and destination are required.' });
}

try {
const tickets = await Ticket.find({
source: { $regex: source, $options: 'i' },
destination: { $regex: destination, $options: 'i' },
});
res.json(tickets);
} catch (error) {
console.error('Error fetching tickets:', error);
res.status(500).json({ message: 'Internal server error' });
}
});

// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
Expand Down
35 changes: 35 additions & 0 deletions backend/models/Ticket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import mongoose from 'mongoose';

const ticketSchema = new mongoose.Schema({
ticketID: {
type: String,
required: true
},
source: {
type: String,
required: true
},
destination: {
type: String,
required: true
},
travelType: {
type: String,
required: true
},
departureTime: {
type: Date,
required: true
},
arrivalTime: {
type: Date,
required: true
},
price: {
type: Number,
required: true
}
});

const Ticket = mongoose.model('Ticket', ticketSchema);
export default Ticket;
43 changes: 43 additions & 0 deletions backend/models/ticketData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const mongoose = require('mongoose');
const Ticket = require('./models/Ticket'); // Adjust the path as necessary

mongoose.connect('mongodb://localhost:27017/tickets', {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(async () => {
const tickets = [
{
ticketID: 'TICKET001',
source: 'New York',
destination: 'Los Angeles',
travelType: 'Flight',
departureTime: new Date('2024-10-05T10:00:00Z'),
arrivalTime: new Date('2024-10-05T13:00:00Z'),
price: 300,
},
{
ticketID: 'TICKET002',
source: 'New York',
destination: 'Chicago',
travelType: 'Train',
departureTime: new Date('2024-10-06T08:00:00Z'),
arrivalTime: new Date('2024-10-06T12:00:00Z'),
price: 150,
},
{
ticketID: 'TICKET003',
source: 'Chicago',
destination: 'Los Angeles',
travelType: 'Bus',
departureTime: new Date('2024-10-07T09:00:00Z'),
arrivalTime: new Date('2024-10-07T20:00:00Z'),
price: 100,
},
];

await Ticket.insertMany(tickets);
console.log('Sample tickets added to the database');
mongoose.connection.close();
})
.catch(err => console.error(err));
137 changes: 62 additions & 75 deletions backend/package-lock.json

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

6 changes: 3 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"concat-map": "^0.0.1",
"content-disposition": "^0.5.4",
"content-type": "^1.0.5",
"cookie": "^0.6.0",
"cookie-parser": "^1.4.6",
"cookie": "^0.7.1",
"cookie-parser": "^1.0.0",
"cookie-signature": "^1.0.6",
"cors": "^2.8.5",
"debug": "^4.3.7",
Expand All @@ -35,7 +35,7 @@
"es-errors": "^1.3.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"express": "^4.21.0",
"express": "^2.5.11",
"fill-range": "^7.1.1",
"finalhandler": "^1.3.1",
"forwarded": "^0.2.0",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Herosection from './Pages/Herosection'
import LoginPage from './Pages/LoginPage';
import Register from './Pages/Register';
import Booking from './Pages/booking';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import chatbotsvg from './assets/svg/chatbot.svg';

Expand All @@ -16,6 +17,7 @@ function App() {
<Route path="/" element={<Herosection />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/register" element={<Register />} />
<Route path="/booking" element={<Booking/>}/>
</Routes>
</Router>

Expand Down
7 changes: 5 additions & 2 deletions frontend/src/Pages/Herosection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ const Herosection = () => {
navigate('/login'); // Navigates to the login page
};
const RegisterClick = () => {
navigate('/Register'); // Navigates to the login page
navigate('/register'); // Navigates to the login page
};
const BookingClick =() => {
navigate('/booking')
}
return (
<>

Expand All @@ -48,7 +51,7 @@ const Herosection = () => {

<div className='grid grid-cols-3 gap-4 mt-32 md:flex md:flex-row md:justify-evenly justify-items-center'>
<div className='flex flex-col items-center justify-center w-16 h-16 bg-blue-200 border-2 border-blue-200 rounded-full cursor-pointer'><img src={navigationsvg} alt="" srcset="" /> <h1 className='font-bold text-black'>Navigation</h1></div>
<div className='flex flex-col items-center justify-center w-16 h-16 bg-blue-200 border-2 border-blue-200 rounded-full cursor-pointer'><img src={bookingsvg} alt="" srcset="" /> <h1 className='font-bold text-black'>Booking</h1></div>
<div className='flex flex-col items-center justify-center w-16 h-16 bg-blue-200 border-2 border-blue-200 rounded-full cursor-pointer'><img src={bookingsvg} alt="" srcset="" onClick={BookingClick}/> <h1 className='font-bold text-black'>Booking</h1></div>
<div className='flex flex-col items-center justify-center w-16 h-16 bg-blue-200 border-2 border-blue-200 rounded-full cursor-pointer'><img src={stationsvg} alt="" srcset="" /> <h1 className='font-bold text-black'>Station</h1></div>

<div className='flex flex-col items-center justify-center w-16 h-16 bg-blue-200 border-2 border-blue-200 rounded-full cursor-pointer'><img src={mapsvg} alt="" srcset="" /> <h1 className='font-bold text-black'>3D Map</h1></div>
Expand Down
Loading

0 comments on commit 7439571

Please sign in to comment.