- Timestamp:
- 03/16/25 20:56:44 (3 months ago)
- Branches:
- master
- Children:
- 3a74959
- Parents:
- c064a42
- Location:
- src/main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/skychasemk/controller/NotificationController.java
rc064a42 r8a947b9 2 2 3 3 import com.example.skychasemk.model.Notification; 4 import com.example.skychasemk.model.Wishlist; 5 import com.example.skychasemk.repository.NotificationRepository; 4 6 import com.example.skychasemk.services.NotificationService; 5 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.http.ResponseEntity; 6 9 import org.springframework.web.bind.annotation.*; 7 10 … … 16 19 private NotificationService notificationService; 17 20 18 // Get all notifications 19 @GetMapping 20 public List<Notification> getAllNotifications() { 21 return notificationService.getAllNotifications(); 21 @Autowired 22 private NotificationRepository notificationRepository; 23 24 @GetMapping("/{userId}") 25 public ResponseEntity<List<Notification>> getAllNotifications(@PathVariable Integer userId) { 26 List<Notification> notifications = notificationRepository.findByUserId(userId); 27 return ResponseEntity.ok(notifications); 22 28 } 23 29 24 // Get notification by ID25 @GetMapping("/{id}")26 public Optional<Notification> getNotificationById(@PathVariable("id") Integer notificationID) {27 return notificationService.getNotificationById(notificationID);28 }29 30 // Create a new notification31 30 @PostMapping 32 31 public Notification createNotification(@RequestBody Notification notification) { … … 34 33 } 35 34 36 // Update an existing notification37 35 @PutMapping("/{id}") 38 36 public Notification updateNotification(@PathVariable("id") Integer notificationID, @RequestBody Notification notification) { … … 40 38 } 41 39 42 // Delete a notification43 40 @DeleteMapping("/{id}") 44 41 public void deleteNotification(@PathVariable("id") Integer notificationID) { -
src/main/java/com/example/skychasemk/model/Notification.java
rc064a42 r8a947b9 2 2 3 3 import jakarta.persistence.*; 4 import lombok.Getter; 5 4 6 import java.time.LocalDate; 5 7 8 @Getter 6 9 @Entity 7 10 @Table(name="notification") … … 15 18 @Column(name = "userid") 16 19 17 private Integer userI D;20 private Integer userId; 18 21 @Column(name = "message") 19 22 … … 33 36 } 34 37 35 // Getters and Setters36 public Integer getNotificationID() {37 return notificationID;38 }39 40 38 public void setNotificationID(Integer notificationID) { 41 39 this.notificationID = notificationID; 42 40 } 43 41 44 public Integer getUserID() { 45 return userID; 46 } 47 48 public void setUserID(Integer userID) { 49 this.userID = userID; 50 } 51 52 public String getMessage() { 53 return message; 42 public void setUserId(Integer userId) { 43 this.userId = userId; 54 44 } 55 45 … … 58 48 } 59 49 60 public Type getType() {61 return type;62 }63 64 50 public void setType(Type type) { 65 51 this.type = type; 66 }67 68 public LocalDate getDateSent() {69 return dateSent;70 52 } 71 53 -
src/main/java/com/example/skychasemk/repository/NotificationRepository.java
rc064a42 r8a947b9 2 2 3 3 import com.example.skychasemk.model.Notification; 4 import com.example.skychasemk.model.Wishlist; 4 5 import org.springframework.data.jpa.repository.JpaRepository; 6 import org.springframework.data.jpa.repository.Query; 7 import org.springframework.data.repository.query.Param; 8 9 import java.util.List; 10 5 11 6 12 public interface NotificationRepository extends JpaRepository<Notification, Integer> { 7 // You can add custom queries here if needed 13 @Query("SELECT n FROM Notification n WHERE n.userId = :userId") 14 List<Notification> findByUserId(@Param("userId") Integer userId); 8 15 } -
src/main/java/com/example/skychasemk/services/BookingService.java
rc064a42 r8a947b9 3 3 import com.example.skychasemk.model.Booking; 4 4 import com.example.skychasemk.repository.BookingRepository; 5 import jakarta.transaction.Transactional; 5 6 import org.springframework.beans.factory.annotation.Autowired; 6 7 import org.springframework.stereotype.Service; -
src/main/java/com/example/skychasemk/services/NotificationService.java
rc064a42 r8a947b9 15 15 private NotificationRepository notificationRepository; 16 16 17 // Get all notifications 18 public List<Notification> getAllNotifications() { 19 return notificationRepository.findAll(); 17 public List<Notification> getAllNotifications(Integer userId) { 18 return notificationRepository.findByUserId(userId); 20 19 } 21 20 22 // Get notification by ID23 public Optional<Notification> getNotificationById(Integer notificationID) {24 return notificationRepository.findById(notificationID);25 }26 27 // Save a new notification28 21 public Notification saveNotification(Notification notification) { 29 22 return notificationRepository.save(notification); 30 23 } 31 24 32 // Update an existing notification33 25 public Notification updateNotification(Integer notificationID, Notification notification) { 34 26 if (notificationRepository.existsById(notificationID)) { … … 40 32 } 41 33 42 // Delete notification43 34 public void deleteNotification(Integer notificationID) { 44 35 notificationRepository.deleteById(notificationID); -
src/main/resources/static/FlightSearch.html
rc064a42 r8a947b9 10 10 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> 11 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"> 12 13 <style> 13 14 body { … … 212 213 color:white; 213 214 } 215 216 .notification-badge { 217 position: absolute; 218 top: 0; 219 right: 0; 220 background-color: red; 221 color: white; 222 border-radius: 50%; 223 padding: 0.3em; 224 font-size: 0.8em; 225 } 226 227 button i { 228 font-size: 24px; 229 color: #333; 230 position: relative; 231 } 232 233 .notifications-popup { 234 position: absolute; 235 top: 50px; 236 right: 0; 237 background: white; 238 border: 1px solid #ddd; 239 box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); 240 width: 300px; 241 max-height: 400px; 242 overflow-y: auto; 243 padding: 10px; 244 z-index: 9999; 245 } 246 247 .notifications-popup ul { 248 list-style-type: none; 249 padding: 0; 250 } 251 252 .notifications-popup li { 253 padding: 10px; 254 border-bottom: 1px solid #ddd; 255 } 256 257 .notifications-popup button { 258 background-color: #4CAF50; /* Green */ 259 color: white; 260 padding: 10px; 261 border: none; 262 cursor: pointer; 263 margin-top: 10px; 264 } 265 266 .notifications-popup button:hover { 267 background-color: #45a049; 268 } 214 269 </style> 215 270 </head> … … 223 278 <button @click="goToReports">Monthly Report</button> 224 279 <button @click="home">Log Out</button> 280 281 <button @click="toggleNotifications"> 282 <i class="fas fa-bell"></i> 283 <span v-if="unreadNotifications > 0" class="notification-badge">{{ unreadNotifications }}</span> 284 </button> 225 285 </header> 226 286 … … 291 351 </div> 292 352 </div> 353 354 <div v-if="notificationsVisible" class="notifications-popup"> 355 <ul> 356 <li v-for="notification in notifications" :key="notification.message"> 357 {{ notification.message }} 358 </li> 359 </ul> 360 <button @click="markAllAsRead">Mark All as Read</button> 361 </div> 293 362 </div> 294 363 … … 310 379 issueDescription: '', 311 380 userId:'', 312 wishlisted:false 381 wishlisted:false, 382 unreadNotifications: 0, 383 notifications: [], 384 notificationsVisible: false, 313 385 }, 314 386 computed: { … … 319 391 320 392 methods: { 393 toggleNotifications() { 394 this.notificationsVisible = !this.notificationsVisible; 395 }, 396 fetchNotifications() { 397 console.log('Fetching notifications for userId:', this.userId); 398 axios.get(`/api/notifications/${this.userId}`) 399 .then(response => { 400 this.notifications = response.data; 401 this.unreadNotifications = this.notifications.filter(n => !n.read).length; 402 }) 403 .catch(error => { 404 console.error('Error fetching notifications:', error); 405 }); 406 }, 321 407 async searchFlights() { 322 408 this.isContainerVisible = !this.isContainerVisible; … … 455 541 console.error("Error fetching flights", error); 456 542 }); 457 543 this.fetchNotifications(); 458 544 } 459 545 });
Note:
See TracChangeset
for help on using the changeset viewer.