Ignore:
Timestamp:
02/17/25 21:52:11 (4 months ago)
Author:
ste08 <sjovanoska@…>
Branches:
master
Children:
62bba0c
Parents:
9868304
Message:

Signup,Login,FlightSearch,Booking and Payment working!

Location:
src/main/resources/static
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/main/resources/static/FlightSearch.html

    r9868304 rde83113  
    252252            <h2>Available Flights</h2>
    253253            <div class="flights-list">
    254                 <div class="flight-item" v-for="flight in flights" :key="flight.flightId">
     254                <div class="flight-item" v-for="flight in flights" :key="flight.flightID">
    255255                    <input type="checkbox" v-model="flight.selected" />
    256256                    <span>{{ flight.departureTime }} | {{ flight.arrivalTime }} | ${{ flight.price }} | {{ flight.availableSeats }}</span>
     
    295295            showReturnDate: false,
    296296            showPopup: false,
    297             issueDescription: ""
     297            issueDescription: '',
     298            userId:''
    298299        },
    299300        computed: {
     
    302303            }
    303304        },
     305
    304306        methods: {
    305307            async searchFlights() {
     
    337339
    338340                const flight = this.selectedFlights[0];
     341                console.log(flight);
    339342                const totalCost = flight.price;
     343
    340344                const bookingData = {
    341                     flightId: flight.flightId,
     345                    flightId: flight.flightID,
    342346                    bookingDate: new Date().toISOString().split('T')[0],
    343347                    status: 'PENDING',
    344                     totalCost: totalCost
     348                    totalCost: totalCost,
     349                    userId:this.userId
    345350                };
    346 
    347351                axios.post('/api/bookings', bookingData)
    348352                    .then(response => {
    349                         const bookingID = response.data.bookingID;
     353                        const bookingID = response.data.bookingId;
    350354                        alert("Booked successfully!");
    351                         window.location.href = `/transaction?amount=${encodeURIComponent(totalCost)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flight.flightId)}`;
     355                        window.location.href = `/transaction?amount=${encodeURIComponent(totalCost)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flight.flightID)}&userId=${encodeURIComponent(this.userId)}`;
    352356                    })
    353357                    .catch(error => {
     
    383387                if (this.issueDescription.trim()) {
    384388                    const reviewData = {
    385                         userID: 1,
     389                        userID: this.userId,
    386390                        subject: "Issue Report",
    387391                        description: this.issueDescription
     
    413417        mounted() {
    414418            this.fetchFlights();
     419            const params = new URLSearchParams(window.location.search);
     420            this.userId = params.get("userId");
    415421            axios.get('api/flights')
    416422                .then(response => {
     
    420426                    console.error("Error fetching flights", error);
    421427                });
     428
    422429        }
    423430    });
  • src/main/resources/static/TransactionPage.html

    r9868304 rde83113  
    263263            expiration: '',
    264264            amount: '',
    265             paymentSuccess: false
    266         },
    267         created(){
    268             const urlParams = new URLSearchParams(window.location.search);
    269             this.flightId = urlParams.get('flightId');
    270             this.amount = urlParams.get('amount');
    271             this.bookingId = urlParams.get('bookingId')
    272 
    273             const user = JSON.parse(localStorage.getItem("user"));
    274             if(user){
    275                 this.userId = user.id;
    276             }
     265            paymentSuccess: false,
     266            flightId:'',
     267            userId:''
    277268        },
    278269        methods: {
     
    282273                    transaction_date:paymentDate,
    283274                    payment_status:'SUCCESS',
    284                     amount:this.amount,
    285                     userId:this.userId,
    286                     bookingId:this.bookingId
     275                    amount:Number(this.amount) || null,
     276                    userId:Number(this.userId) || null,
     277                    bookingId:Number(this.bookingId) || null
    287278                };
    288279                console.log(transaction);
     
    291282                        console.log(response.data);
    292283                        this.paymentSuccess = true;
     284                        this.updateBooking();
    293285                        setTimeout(() => window.location.href = '/flights',2000);
    294286                })
    295287                    .catch(error => console.error("Payment failed", error));
    296288            },
     289            updateBooking() {
     290                const booking = {
     291                    bookingDate: new Date().toISOString().split('T')[0],
     292                    flightId:this.flightId,
     293                    payment_status:'SUCCESS',
     294                    total_cost:Number(this.amount) || null,
     295                    userId:Number(this.userId) || null,
     296                    bookingId:Number(this.bookingId) || null
     297                };
     298                console.log(booking);
     299                axios.put(`api/flights/${this.bookingId}`, booking)
     300                    .then(response => {
     301                        console.log(response.data);
     302                    })
     303                    .catch(error => console.error("Booking update failed", error));
     304            },
    297305            cancelPayment() {
    298                 window.location.href = '/flights'; // Redirecting to flight search on cancel
     306                window.location.href = '/flights';
    299307            },
    300308            validateForm() {
     
    305313                );
    306314            }
     315        },
     316        mounted(){
     317            const params = new URLSearchParams(window.location.search);
     318            this.userId = params.get("userId");
     319            this.bookingId = params.get("bookingId");
     320            this.flightId = params.get("flightId");
     321            this.amount=params.get("amount");
    307322        }
    308323    });
Note: See TracChangeset for help on using the changeset viewer.