Changeset 8a947b9 for src/main/java/com/example/skychasemk
- Timestamp:
- 03/16/25 20:56:44 (3 months ago)
- Branches:
- master
- Children:
- 3a74959
- Parents:
- c064a42
- Location:
- src/main/java/com/example/skychasemk
- Files:
-
- 5 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);
Note:
See TracChangeset
for help on using the changeset viewer.