From 74395716903a71c100ba9f0181544fd70db9c1d9 Mon Sep 17 00:00:00 2001 From: ash-k121 Date: Sun, 6 Oct 2024 00:47:52 +0530 Subject: [PATCH] issue51 --- backend/index.js | 22 +++++ backend/models/Ticket.js | 35 ++++++++ backend/models/ticketData.js | 43 +++++++++ backend/package-lock.json | 137 +++++++++++++---------------- backend/package.json | 6 +- frontend/src/App.jsx | 2 + frontend/src/Pages/Herosection.jsx | 7 +- frontend/src/Pages/booking.css | 104 ++++++++++++++++++++++ frontend/src/Pages/booking.jsx | 85 ++++++++++++++++++ package-lock.json | 6 ++ 10 files changed, 367 insertions(+), 80 deletions(-) create mode 100644 backend/models/Ticket.js create mode 100644 backend/models/ticketData.js create mode 100644 frontend/src/Pages/booking.css create mode 100644 package-lock.json diff --git a/backend/index.js b/backend/index.js index 7ab24be..c6a5a04 100644 --- a/backend/index.js +++ b/backend/index.js @@ -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}`); diff --git a/backend/models/Ticket.js b/backend/models/Ticket.js new file mode 100644 index 0000000..73a998b --- /dev/null +++ b/backend/models/Ticket.js @@ -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; diff --git a/backend/models/ticketData.js b/backend/models/ticketData.js new file mode 100644 index 0000000..61b4635 --- /dev/null +++ b/backend/models/ticketData.js @@ -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)); diff --git a/backend/package-lock.json b/backend/package-lock.json index 377a6c7..97d488f 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -25,8 +25,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", @@ -40,7 +40,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", @@ -429,6 +429,17 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "license": "MIT" }, + "node_modules/connect": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/connect/-/connect-1.9.2.tgz", + "integrity": "sha512-6Z9RPjQOHjaI47gK385djHVv7SEkRm1Y9AAvBhiI7gSXpO5sFktTkAD+dkbcaiEo2xaNlS1KIJU3XRxqbPLx6w==", + "deprecated": "connect 1.x series is deprecated", + "dependencies": { + "formidable": "1.0.x", + "mime": ">= 0.0.1", + "qs": ">= 0.4.0" + } + }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -457,34 +468,19 @@ } }, "node_modules/cookie": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", - "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", - "license": "MIT", + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", + "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", "engines": { "node": ">= 0.6" } }, "node_modules/cookie-parser": { - "version": "1.4.6", - "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz", - "integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==", - "license": "MIT", - "dependencies": { - "cookie": "0.4.1", - "cookie-signature": "1.0.6" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/cookie-parser/node_modules/cookie": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", - "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", - "license": "MIT", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.0.0.tgz", + "integrity": "sha512-VLkjN2nBSwpdkYmw+lSAEkdzFgb7IFU20zzXDZkt7+ZCtn3TmmRz9ZtyzKkgl66DhNpjW+jUgfFgZ6cyWG7n8w==", "engines": { - "node": ">= 0.6" + "node": ">= 0.10.0" } }, "node_modules/cookie-signature": { @@ -578,7 +574,6 @@ "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "license": "BSD-2-Clause", "engines": { "node": ">=12" }, @@ -653,61 +648,44 @@ } }, "node_modules/express": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.0.tgz", - "integrity": "sha512-VqcNGcj/Id5ZT1LZ/cfihi3ttTn+NJmkli2eZADigjq29qTlWi/hAQ43t/VLPq8+UX06FCEx3ByOYet6ZFblng==", - "license": "MIT", - "dependencies": { - "accepts": "~1.3.8", - "array-flatten": "1.1.1", - "body-parser": "1.20.3", - "content-disposition": "0.5.4", - "content-type": "~1.0.4", - "cookie": "0.6.0", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "2.0.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "1.3.1", - "fresh": "0.5.2", - "http-errors": "2.0.0", - "merge-descriptors": "1.0.3", - "methods": "~1.1.2", - "on-finished": "2.4.1", - "parseurl": "~1.3.3", - "path-to-regexp": "0.1.10", - "proxy-addr": "~2.0.7", - "qs": "6.13.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.2.1", - "send": "0.19.0", - "serve-static": "1.16.2", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" + "version": "2.5.11", + "resolved": "https://registry.npmjs.org/express/-/express-2.5.11.tgz", + "integrity": "sha512-gc3jJ0P3Bh1Zjkxe0ICSNmjhDvYWKiXfQIdDWuRPr8S4IZAZexzJHjrzNz56LsRKHTL0OiXQq602GfwZjZ8xPQ==", + "deprecated": "express 2.x series is deprecated", + "dependencies": { + "connect": "1.x", + "mime": "1.2.4", + "mkdirp": "0.3.0", + "qs": "0.4.x" }, + "bin": { + "express": "bin/express" + } + }, + "node_modules/express/node_modules/mime": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.2.4.tgz", + "integrity": "sha512-u4y8WFj7SnfbHxyzCMSV2nL/GKbfZ+lidPf1V4/XUKCJ49N6ttQWp/xnqpbMQEx3naBSt93i2qtPLFj/mjPDaA==", "engines": { - "node": ">= 0.10.0" + "node": "*" } }, - "node_modules/express/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "license": "MIT", - "dependencies": { - "ms": "2.0.0" + "node_modules/express/node_modules/mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha512-OHsdUcVAQ6pOtg5JYWpCBo9W/GySVuwvP9hueRMW7UqshC0tbfzLv8wjySTPm3tfUZ/21CE9E1pJagOA91Pxew==", + "deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)", + "engines": { + "node": "*" } }, - "node_modules/express/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" + "node_modules/express/node_modules/qs": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-0.4.2.tgz", + "integrity": "sha512-VAtfWeUtlBOnGiWFok2vOIMmwumiLmpqXDcXQcAEIQmLYgDbjrkHrcFBfth+YVDeRsz7jX44dhJr7IBJR0t/FQ==", + "engines": { + "node": "*" + } }, "node_modules/fill-range": { "version": "7.1.1", @@ -754,6 +732,15 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "license": "MIT" }, + "node_modules/formidable": { + "version": "1.0.17", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.17.tgz", + "integrity": "sha512-95MFT5qipMvUiesmuvGP1BI4hh5XWCzyTapiNJ/k8JBQda7rPy7UCWYItz2uZEdTgGNy1eInjzlL9Wx1O9fedg==", + "deprecated": "Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau", + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", diff --git a/backend/package.json b/backend/package.json index 169ab6d..81cd313 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", @@ -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", diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 0324c2f..2727218 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -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'; @@ -16,6 +17,7 @@ function App() { } /> } /> } /> + }/> diff --git a/frontend/src/Pages/Herosection.jsx b/frontend/src/Pages/Herosection.jsx index 0509f55..65882d6 100644 --- a/frontend/src/Pages/Herosection.jsx +++ b/frontend/src/Pages/Herosection.jsx @@ -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 ( <> @@ -48,7 +51,7 @@ const Herosection = () => {

Navigation

-

Booking

+

Booking

Station

3D Map

diff --git a/frontend/src/Pages/booking.css b/frontend/src/Pages/booking.css new file mode 100644 index 0000000..bd65c1d --- /dev/null +++ b/frontend/src/Pages/booking.css @@ -0,0 +1,104 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f9; + margin: 0; + padding: 20px; +} + +h1 { + text-align: center; + color: #333; + margin-bottom: 20px; +} + +form { + max-width: 400px; + margin: 0 auto; + background: white; + padding: 20px; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); + transition: transform 0.2s ease; +} + +form:hover { + transform: scale(1.02); +} + +label { + display: block; + margin-bottom: 10px; + font-weight: bold; + color: #555; +} + +input { + width: 100%; + padding: 10px; + margin-bottom: 20px; + border: 1px solid #ccc; + border-radius: 4px; + transition: border-color 0.3s; +} + +input:focus { + border-color: #007bff; + outline: none; +} + +button { + width: 100%; + padding: 10px; + background-color: #007bff; + border: none; + border-radius: 4px; + color: white; + font-size: 16px; + cursor: pointer; + transition: background-color 0.3s; +} + +button:hover { + background-color: #0056b3; +} + +h2 { + text-align: center; + color: #f1f1f1; + margin: 20px 0; + font-weight: 500; + font-size: xx-large!important; + font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; +} + +ul { + list-style-type: none; + padding: 0; +} + +li { + background: white; + margin: 10px 0; + padding: 15px; + border-radius: 4px; + box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1); + transition: background-color 0.3s; +} + +li:hover { + background-color: #f1f1f1; +} + +.error { + color: #d9534f; + text-align: center; + margin-top: 20px; +} + +.tickets-list { + margin-top: 30px; +} + +.tickets-list h3 { + margin-bottom: 10px; +} diff --git a/frontend/src/Pages/booking.jsx b/frontend/src/Pages/booking.jsx index e69de29..1f6619a 100644 --- a/frontend/src/Pages/booking.jsx +++ b/frontend/src/Pages/booking.jsx @@ -0,0 +1,85 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import './booking.css'; + +function Booking() { + const [source, setSource] = useState(''); + const [destination, setDestination] = useState(''); + const [tickets, setTickets] = useState([]); + const [error, setError] = useState(''); + + const handleSearch = async (e) => { + e.preventDefault(); + setError(''); // Reset error message + + try { + const response = await axios.post('http://localhost:3000/api/tickets/search', { + source, + destination, + }); + console.log(response.data); // Log the response data + setTickets(response.data); + } catch (err) { + setError('Error fetching tickets. Please try again.'); + } + }; + + return ( +
+

Search for Tickets

+
+
+ + setSource(e.target.value)} + required + /> +
+
+ + setDestination(e.target.value)} + required + /> +
+

+ +
+ + {error &&

{error}

} + + {tickets.length > 0 && ( +
+

Available Tickets:

+
    + {tickets.map((ticket) => ( +
  • {/* Change ticketID to _id */} +

    + Travel Type: {ticket.travelType} +

    +

    + Departure: {new Date(ticket.departureTime).toLocaleString()} +

    +

    + Arrival: {new Date(ticket.arrivalTime).toLocaleString()} +

    +

    + Price: ${ticket.price} +

    +
    +
  • + ))} +
+
+ )} +
+ ); +} + +export default Booking; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a10f51a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "StationGuide", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}