Changeset 3a74959
- Timestamp:
- 03/26/25 00:25:45 (2 months ago)
- Branches:
- master
- Children:
- ff72ad2
- Parents:
- 8a947b9
- Location:
- src/main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/skychasemk/controller/ReviewController.java
r8a947b9 r3a74959 2 2 3 3 import com.example.skychasemk.dto.ReviewDTO; 4 import com.example.skychasemk.model.Notification; 4 5 import com.example.skychasemk.model.Review; 5 6 import com.example.skychasemk.repository.ReviewRepository; … … 27 28 } 28 29 29 30 @GetMapping("/{flightId}") 31 public List<Review> getReviewsByFlightId(@PathVariable("flightId") Integer flightId) { 32 return reviewRepository.findReviews(flightId); 33 } 34 35 // Get review by ID 36 @GetMapping("/{id}") 37 public Optional<Review> getReviewById(@PathVariable("id") Integer reviewID) { 38 return reviewService.getReviewById(reviewID); 30 @GetMapping("/{userId}") 31 public ResponseEntity<List<Review>> getReviewsByFlightId(@PathVariable Integer userId) { 32 List<Review> reviews = reviewRepository.findByUserId(userId); 33 return ResponseEntity.ok(reviews); 39 34 } 40 35 -
src/main/java/com/example/skychasemk/model/Review.java
r8a947b9 r3a74959 5 5 6 6 @Entity 7 @Table(name=" Review")7 @Table(name="review") 8 8 public class Review { 9 9 10 10 @Id 11 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @Column(name = "review Id")12 @Column(name = "reviewid") 13 13 14 14 private Integer reviewID; 15 @Column(name = "user Id")15 @Column(name = "userid") 16 16 17 17 private Integer userID; 18 @Column(name = "target Id")18 @Column(name = "targetid") 19 19 20 20 private Integer targetID; -
src/main/java/com/example/skychasemk/repository/ReviewRepository.java
r8a947b9 r3a74959 1 1 package com.example.skychasemk.repository; 2 2 3 import com.example.skychasemk.model.Notification; 3 4 import com.example.skychasemk.model.Review; 4 5 import org.springframework.data.jpa.repository.JpaRepository; … … 11 12 @Query("SELECT r from Review r where r.targetID = :flightId") 12 13 List<Review> findReviews(@Param("flightId") Integer flightId); 14 15 @Query("SELECT r FROM Review r WHERE r.userID = :userId") 16 List<Review> findByUserId(@Param("userId") Integer userId); 13 17 } 14 18 -
src/main/resources/static/FlightSearch.html
r8a947b9 r3a74959 277 277 <button @click="goToWishlistPage">🤍</button> 278 278 <button @click="goToReports">Monthly Report</button> 279 <button @click="goToReviews">Reviews</button> 279 280 <button @click="home">Log Out</button> 280 281 … … 375 376 places: [], 376 377 bookings: [], 378 pastBookings: [], 377 379 showReturnDate: false, 378 380 showPopup: false, … … 528 530 console.error("Error fetching Destinations", error); 529 531 } 532 }, 533 goToReviews(){ 534 window.location.href = `/reviews?userId=${encodeURIComponent(this.userId)}`; 530 535 } 531 536 }, -
src/main/resources/static/ReviewPage.html
r8a947b9 r3a74959 7 7 <link rel="stylesheet" href="/css/main.css"> 8 8 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> 9 <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> 10 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> 11 <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css'> 12 <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"> 9 13 </head> 14 <style> 15 .popup-overlay { 16 position: fixed; 17 top: 0; 18 left: 0; 19 width: 100%; 20 height: 100%; 21 background: rgba(0, 0, 0, 0.7); 22 display: flex; 23 align-items: center; 24 justify-content: center; 25 z-index: 1000; 26 overflow:hidden; 27 } 28 29 .popup textarea{ 30 width: 100%; 31 padding: 10px; 32 margin-top: 10px; 33 border: 1px solid #ccc; 34 border-radius: 4px; 35 resize: vertical; 36 box-sizing: border-box; 37 } 38 39 .popup { 40 background-color: white; 41 padding: 20px; 42 width: 300px; 43 border-radius: 10px; 44 } 45 46 .popup button { 47 margin-top: 10px; 48 background-color: rebeccapurple; 49 color: white; 50 border: none; 51 padding: 5px; 52 cursor: pointer; 53 } 54 55 .popup button:hover { 56 background-color: mediumpurple; 57 } 58 59 .popup select { 60 width: 100%; 61 padding: 8px; 62 margin: 10px 0; 63 border-radius: 4px; 64 border: 1px solid #ccc; 65 } 66 67 .popup select:focus { 68 outline: none; 69 border-color: #007bff; 70 } 71 72 </style> 10 73 <body> 11 74 … … 13 76 <header class="app-header"> 14 77 <button class="logout-btn" @click="logout">Log Out</button> 78 <button class="logout-btn" @click="leaveReview">Leave a review</button> 15 79 </header> 16 80 … … 20 84 21 85 <div class="review-list"> 22 <div v-for="review in reviews" :key="review. id" class="review-item">23 <h3>{{ review. subject}}</h3>24 <p>{{ review. description}}</p>25 <span>{{ review. date}}</span>86 <div v-for="review in reviews" :key="review.reviewid" class="review-item"> 87 <h3>{{ review.date }}</h3> 88 <p>{{ review.reviewComment }}</p> 89 <span>{{ review.rating }}</span> 26 90 </div> 27 91 </div> 92 </div> 93 </div> 94 </div> 95 96 <div v-if="showPopup" class="popup-overlay"> 97 <div class="popup"> 98 <h3>Leave a review</h3> 99 100 <select v-model="selectedFlightNumber" id="flights"> 101 <option value="" disabled selected>Select a flight</option> 102 <option v-for="flight in flights" :key="flight.flightNumber" :value="flight.flightNumber"> 103 {{ flight.flightNumber }} 104 </option> 105 </select> 106 107 <textarea v-model="reviewComment" placeholder="Leave a comment here..." rows="5"></textarea> 108 109 <textarea v-model="rating" placeholder="Rate 1-5" rows="1"></textarea> 110 111 <div class="popup-actions"> 112 <button @click="submitReview" class="submit-btn">Submit</button> 113 <button @click="closePopup" class="cancel-btn">Cancel</button> 28 114 </div> 29 115 </div> … … 34 120 el: '#app', 35 121 data: { 36 reviews: [ 37 { 38 id: 1, 39 subject: 'Great experience!', 40 description: 'The flight was amazing, the service was excellent, and the views were breathtaking.', 41 date: '2025-02-01', 42 }, 43 { 44 id: 2, 45 subject: 'Good but delayed', 46 description: 'The flight was comfortable, but it was delayed by two hours, which caused some inconvenience.', 47 date: '2025-02-02', 48 }, 49 { 50 id: 3, 51 subject: 'Okay, but not perfect', 52 description: 'Everything was fine, but the food options could have been better.', 53 date: '2025-02-03', 54 }, 55 ] 122 userId: '', 123 reviews: [], 124 showPopup: false, 125 reviewComment: '', 126 rating: '', 127 flights: [], 128 selectedFlightNumber: '' 56 129 }, 57 130 methods: { 58 131 logout() { 59 132 window.location.href = '/'; 133 }, 134 async fetchReviews() { 135 try { 136 const response = await axios.get("api/reviews"); 137 this.reviews = response.data; 138 } catch (error) { 139 console.error(error); 140 } 141 }, 142 leaveReview() { 143 this.showPopup = true; 144 }, 145 closePopup() { 146 this.showPopup = false; 147 }, 148 submitReview() { 149 if (this.reviewComment.trim() && this.selectedFlightNumber) { 150 const reviewData = { 151 userId: this.userId, 152 flightNumber: this.selectedFlightNumber, 153 reviewComment: this.reviewComment, 154 rating: this.rating 155 }; 156 157 axios.post('/api/reviews', reviewData) 158 .then(response => { 159 alert("Review added successfully!"); 160 this.closePopup(); 161 }) 162 .catch(error => { 163 console.error("Error submitting review:", error); 164 alert("There was an error submitting your review. Please try again."); 165 }); 166 } 167 }, 168 async fetchFlights() { 169 try { 170 const response = await axios.get('/api/flights'); 171 this.flights = response.data; 172 console.log(this.flights); 173 } catch (error) { 174 console.error('Error fetching flights:', error); 175 } 60 176 } 61 177 }, 62 178 mounted() { 63 axios.get('api/reviews') 64 .then(response => { 65 this.review = response.data; 66 }) 67 .catch(error => { 68 console.error("Error fetching reviews", error); 69 }); 179 const params = new URLSearchParams(window.location.search); 180 this.userId = params.get("userId"); 181 this.fetchReviews(); 182 this.fetchFlights(); 70 183 } 71 184 });
Note:
See TracChangeset
for help on using the changeset viewer.