- Timestamp:
- 02/23/25 22:27:46 (3 months ago)
- Branches:
- master
- Children:
- 07fe0be
- Parents:
- 62bba0c
- Location:
- src/main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/skychasemk/controller/WishlistController.java
r62bba0c rfda671c 3 3 import com.example.skychasemk.dto.WishlistDTO; 4 4 import com.example.skychasemk.model.Wishlist; 5 import com.example.skychasemk.repository.WishlistRepository; 5 6 import com.example.skychasemk.services.WishlistService; 6 7 import org.springframework.beans.factory.annotation.Autowired; … … 18 19 private WishlistService wishlistService; 19 20 21 @Autowired 22 private WishlistRepository wishlistRepository; 23 20 24 @GetMapping 21 25 public List<Wishlist> getAllWishlists() { 22 return wishlist Service.getAllWishlists();26 return wishlistRepository.findAll(); 23 27 } 28 24 29 @PostMapping("/add") 25 30 public Wishlist createWishlist(@RequestBody Wishlist wishlist) { … … 33 38 34 39 @GetMapping("/{userId}") 35 public ResponseEntity<List<Wishlist>> getWishlist(@ RequestParam("userId")Long userId) {40 public ResponseEntity<List<Wishlist>> getWishlist(@PathVariable Long userId) { 36 41 List<Wishlist> wishlist = wishlistService.getAllItems(userId); 37 42 return ResponseEntity.ok(wishlist); -
src/main/java/com/example/skychasemk/model/WebConfig.java
r62bba0c rfda671c 34 34 registry.addViewController("/transaction").setViewName("forward:/TransactionPage.html"); 35 35 registry.addViewController("/login").setViewName("forward:/UserLogin.html"); 36 registry.addViewController("/wishlist ").setViewName("forward:/Wishlist.html");36 registry.addViewController("/wishlists").setViewName("forward:/Wishlist.html"); 37 37 registry.addViewController("/signup").setViewName("forward:/UserSignup.html"); 38 38 registry.addViewController("/views").setViewName("forward:/ViewReport.html"); -
src/main/resources/static/FlightSearch.html
r62bba0c rfda671c 405 405 }, 406 406 async goToWishlistPage() { 407 window.location.href = `/api/wishlists?userId=${encodeURIComponent(this.userId)}`; 408 407 window.location.href = `/wishlists?userId=${encodeURIComponent(this.userId)}`; 409 408 }, 410 409 showReportPopup() { -
src/main/resources/static/Wishlist.html
r62bba0c rfda671c 4 4 <meta charset="UTF-8"> 5 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>SkyChase - Wishlist</title> 6 7 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> 7 8 <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> 8 9 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> 9 10 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css'> 10 11 <title>SkyChase - Wishlist</title> 11 <link rel="stylesheet" href="/css/main.css"> 12 12 <style> 13 13 body { 14 background: url('images/ homepage.jpg') no-repeat center center fixed;14 background: url('images/sky.jpg') no-repeat center center fixed; 15 15 background-size: cover; 16 16 display: flex; … … 46 46 padding-right: 50px; 47 47 } 48 49 .buttons { 50 text-align: center; 48 .header button{ 49 background-color:rebeccapurple; 51 50 } 52 53 .buttons button { 54 padding: 15px 30px; 55 margin: 10px; 56 font-size: 18px; 57 border: none; 58 border-radius: 5px; 51 select { 52 -webkit-appearance: none; 53 -moz-appearance: none; 54 appearance: none; 55 border: 0; 56 outline: 0; 57 font: inherit; 58 width: 20em; 59 height: 3em; 60 padding: 0 4em 0 1em; 61 background: url(https://upload.wikimedia.org/wikipedia/commons/9/9d/Caret_down_font_awesome_whitevariation.svg) no-repeat right 0.8em center/1.4em, linear-gradient(to left, rgba(255, 255, 255, 0.3) 3em, rgba(255, 255, 255, 0.2) 3em); 62 color: white; 63 border-radius: 0.25em; 64 box-shadow: 0 0 1em 0 rgba(0, 0, 0, 0.2); 59 65 cursor: pointer; 60 transition: 0.3s;61 66 } 62 63 .signup { 64 background-color: rebeccapurple; 65 color: white; 67 select option { 68 color: inherit; 69 background-color: #320a28; 66 70 } 67 68 .signup:hover { 69 background-color: mediumpurple; 71 select:focus { 72 outline: none; 70 73 } 71 72 .login { 73 background-color: #007bff; 74 color: white; 74 select::-ms-expand { 75 display: none; 75 76 } 76 77 .login:hover {78 background-color: #0056b3;79 }80 81 .adminlogin {82 top: 0;83 right: 0;84 background-color: rebeccapurple;85 border: 0;86 color: white;87 padding: 0 1200px;88 }89 90 77 .wishlist-content { 91 78 margin-top: 60px; 92 79 color: white; 93 80 } 81 #app { 82 text-align: center; 94 83 84 } 95 85 ul { 96 86 list-style-type: none; 87 border: 2px solid rebeccapurple; 88 width: 80%; /* Adjust the width as needed */ 89 background-color: rebeccapurple; 90 position: relative; 91 display: flex; 92 flex-direction: column; /* Stack items vertically */ 93 align-items: center; /* Center horizontally */ 94 justify-content: center; /* Center vertically */ 95 padding: 20px; 96 border-radius: 15px; 97 margin: 0 auto; /* Center the ul itself */ 98 text-align: center; /* Center text inside the ul */ 97 99 } 98 100 99 101 li { 100 margin: 10px 0; 101 font-size: 18px; 102 font-size: 14px; 103 display: block; /* Make each item block-level */ 104 padding: 10px; 105 width: 100%; /* Make li take full width inside ul */ 102 106 } 107 108 109 .book { 110 background-color: white; 111 color: rebeccapurple; 112 width: 5em; 113 height: 3em; 114 align-content: center; 115 font-size: 14px; 116 } 117 103 118 </style> 104 119 </head> … … 107 122 <img src="/images/home.png" alt="Home Icon"> 108 123 <h1>SkyChase</h1> 109 <button class="adminlogin" onclick="location.href='/admin'">Admin?</button>124 <button @click="home">Log Out</button> 110 125 </div> 111 126 112 <div class="wishlist-content">127 <div id="app" class="wishlist-content"> 113 128 <h1>Your Wishlist</h1> 114 129 <ul> 115 130 <li v-if="wishlist.length === 0">Your wishlist is empty!</li> 116 <li v-else v-for="item in wishlist" :key="item.wishlistID">{{ item.targetId }} || {{item.userId}}</li> 131 <li v-else v-for="item in wishlist" :key="item.wishlistID"> 132 Wishlist ID: {{ item.wishlistID }} | Added on: {{ item.date_added }} 133 <br> 134 <br> 135 <button @click="bookFlights" class="book"> 136 Book 137 </button> 138 </li> 117 139 </ul> 118 140 </div> 119 120 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>121 141 122 142 <script> … … 124 144 el: '#app', 125 145 data: { 126 userId: '' 146 userId: '', 147 wishlist: [] // Array to hold the wishlist items 127 148 }, 128 149 mounted() { … … 131 152 this.fetchWishlist(); 132 153 }, 133 async fetchWishlist() { 134 try { 135 const response = await fetch(`/api/wishlists/${this.userId}`); 136 const wishlist = await response.json(); 154 methods: { 155 async fetchWishlist() { 156 try { 157 const response = await fetch(`/api/wishlists/${this.userId}`); 158 this.wishlist = await response.json(); // Directly assign the result to the wishlist data 159 } catch (error) { 160 console.error('Error fetching wishlist:', error); 161 } 162 }, 163 bookFlights() { 164 if (!this.selectedFlights.length) { 165 alert("Please select at least one flight."); 166 return; 167 } 137 168 138 const wishlistElement = document.getElementById('wishlist'); 139 const emptyMessage = document.getElementById('empty-message'); 169 const flight = this.selectedFlights[0]; 170 console.log(flight); 171 const totalCost = flight.price; 140 172 141 if (wishlist.length === 0) { 142 emptyMessage.style.display = 'block'; 143 } else { 144 emptyMessage.style.display = 'none'; 145 wishlistElement.innerHTML = wishlist.map(item => `<li>${item.name}</li>`).join(''); 146 } 147 } catch (error) { 148 console.error('Error fetching wishlist:', error); 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) 181 .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)}`; 185 }) 186 .catch(error => { 187 console.error("Error booking flight", error); 188 alert("There was an error creating your booking. Please try again."); 189 }); 149 190 } 150 191 } 151 }) 152 //window.onload = fetchWishlist; 192 }); 153 193 </script> 154 194 </body>
Note:
See TracChangeset
for help on using the changeset viewer.