Changeset 07fe0be for src/main/resources/static/Wishlist.html
- Timestamp:
- 02/24/25 22:49:01 (3 months ago)
- Branches:
- master
- Children:
- c064a42
- Parents:
- fda671c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/Wishlist.html
rfda671c r07fe0be 120 120 <body> 121 121 <div class="header"> 122 <img src="/images/home.png" alt="Home Icon" >122 <img src="/images/home.png" alt="Home Icon" @click="home"> 123 123 <h1>SkyChase</h1> 124 124 <button @click="home">Log Out</button> … … 133 133 <br> 134 134 <br> 135 <button @click="bookFlights " class="book">135 <button @click="bookFlights(item.wishlistID)" class="book"> 136 136 Book 137 137 </button> … … 145 145 data: { 146 146 userId: '', 147 wishlist: [] // Array to hold the wishlist items 147 wishlist: [], 148 wishlistId:'' 148 149 }, 149 150 mounted() { … … 156 157 try { 157 158 const response = await fetch(`/api/wishlists/${this.userId}`); 158 this.wishlist = await response.json(); // Directly assign the result to the wishlist data159 this.wishlist = await response.json(); 159 160 } catch (error) { 160 161 console.error('Error fetching wishlist:', error); 161 162 } 162 163 }, 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)}`) 181 168 .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 ) 185 197 }) 186 198 .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); 189 200 }); 201 202 }, 203 home() { 204 window.location.href = '/'; 190 205 } 191 206 }
Note:
See TracChangeset
for help on using the changeset viewer.