Ignore:
Timestamp:
02/24/25 22:49:01 (3 months ago)
Author:
ste08 <sjovanoska@…>
Branches:
master
Children:
c064a42
Parents:
fda671c
Message:

Wishlist fully working, can book and pay for the booking.

File:
1 edited

Legend:

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

    rfda671c r07fe0be  
    120120<body>
    121121<div class="header">
    122     <img src="/images/home.png" alt="Home Icon">
     122    <img src="/images/home.png" alt="Home Icon" @click="home">
    123123    <h1>SkyChase</h1>
    124124    <button @click="home">Log Out</button>
     
    133133            <br>
    134134            <br>
    135             <button @click="bookFlights"  class="book">
     135            <button @click="bookFlights(item.wishlistID)"  class="book">
    136136                Book
    137137            </button>
     
    145145        data: {
    146146            userId: '',
    147             wishlist: [] // Array to hold the wishlist items
     147            wishlist: [],
     148            wishlistId:''
    148149        },
    149150        mounted() {
     
    156157                try {
    157158                    const response = await fetch(`/api/wishlists/${this.userId}`);
    158                     this.wishlist = await response.json(); // Directly assign the result to the wishlist data
     159                    this.wishlist = await response.json();
    159160                } catch (error) {
    160161                    console.error('Error fetching wishlist:', error);
    161162                }
    162163            },
    163             bookFlights() {
    164                 if (!this.selectedFlights.length) {
    165                     alert("Please select at least one flight.");
    166                     return;
    167                 }
    168 
    169                 const flight = this.selectedFlights[0];
    170                 console.log(flight);
    171                 const totalCost = flight.price;
    172 
    173                 const bookingData = {
    174                     flightId: flight.flightID,
    175                     bookingDate: new Date().toISOString().split('T')[0],
    176                     status: 'PENDING',
    177                     totalCost: totalCost,
    178                     userId:this.userId
    179                 };
    180                 axios.post('/api/bookings', bookingData)
     164            bookFlights(wishlistID) {
     165                console.log(wishlistID);
     166
     167                axios.get(`/api/wishlists/flight/${encodeURIComponent(wishlistID)}`)
    181168                    .then(response => {
    182                         const bookingID = response.data.bookingId;
    183                         alert("Booked successfully!");
    184                         window.location.href = `/transaction?amount=${encodeURIComponent(totalCost)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flight.flightID)}&userId=${encodeURIComponent(this.userId)}`;
     169                        const flightId = response.data;
     170                        console.log(flightId);
     171                        axios.get(`/api/flights/${encodeURIComponent(flightId)}`)
     172                            .then(response => {
     173                                const flightData = response.data;
     174                                console.log(flightId);
     175                                const bookingData = {
     176                                    flightId: flightData.flightID,
     177                                    bookingDate: new Date().toISOString().split('T')[0],
     178                                    status: 'PENDING',
     179                                    totalCost: flightData.price,
     180                                    userId:this.userId
     181                                };
     182                                axios.post('/api/bookings', bookingData)
     183                                    .then(response => {
     184                                        const bookingID = response.data.bookingId;
     185                                        alert("Booked successfully!");
     186                                        window.location.href = `/transaction?amount=${encodeURIComponent(flightData.price)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flightData.flightID)}&userId=${encodeURIComponent(this.userId)}`;
     187                                    })
     188                                    .catch(error => {
     189                                        console.error("Error booking flight", error);
     190                                        alert("There was an error creating your booking. Please try again.");
     191                                    });
     192                            })
     193                            .catch(error =>{
     194                                console.error(error)
     195                                }
     196                            )
    185197                    })
    186198                    .catch(error => {
    187                         console.error("Error booking flight", error);
    188                         alert("There was an error creating your booking. Please try again.");
     199                        console.error("Error fetching flight", error);
    189200                    });
     201
     202            },
     203            home() {
     204                window.location.href = '/';
    190205            }
    191206        }
Note: See TracChangeset for help on using the changeset viewer.