Ignore:
Timestamp:
03/16/25 20:56:44 (3 months ago)
Author:
ste08 <sjovanoska@…>
Branches:
master
Children:
3a74959
Parents:
c064a42
Message:

Notifications + triggers!

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  
    22
    33import com.example.skychasemk.model.Notification;
     4import com.example.skychasemk.model.Wishlist;
     5import com.example.skychasemk.repository.NotificationRepository;
    46import com.example.skychasemk.services.NotificationService;
    57import org.springframework.beans.factory.annotation.Autowired;
     8import org.springframework.http.ResponseEntity;
    69import org.springframework.web.bind.annotation.*;
    710
     
    1619    private NotificationService notificationService;
    1720
    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);
    2228    }
    2329
    24     // Get notification by ID
    25     @GetMapping("/{id}")
    26     public Optional<Notification> getNotificationById(@PathVariable("id") Integer notificationID) {
    27         return notificationService.getNotificationById(notificationID);
    28     }
    29 
    30     // Create a new notification
    3130    @PostMapping
    3231    public Notification createNotification(@RequestBody Notification notification) {
     
    3433    }
    3534
    36     // Update an existing notification
    3735    @PutMapping("/{id}")
    3836    public Notification updateNotification(@PathVariable("id") Integer notificationID, @RequestBody Notification notification) {
     
    4038    }
    4139
    42     // Delete a notification
    4340    @DeleteMapping("/{id}")
    4441    public void deleteNotification(@PathVariable("id") Integer notificationID) {
  • src/main/java/com/example/skychasemk/model/Notification.java

    rc064a42 r8a947b9  
    22
    33import jakarta.persistence.*;
     4import lombok.Getter;
     5
    46import java.time.LocalDate;
    57
     8@Getter
    69@Entity
    710@Table(name="notification")
     
    1518    @Column(name = "userid")
    1619
    17     private Integer userID;
     20    private Integer userId;
    1821    @Column(name = "message")
    1922
     
    3336    }
    3437
    35     // Getters and Setters
    36     public Integer getNotificationID() {
    37         return notificationID;
    38     }
    39 
    4038    public void setNotificationID(Integer notificationID) {
    4139        this.notificationID = notificationID;
    4240    }
    4341
    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;
    5444    }
    5545
     
    5848    }
    5949
    60     public Type getType() {
    61         return type;
    62     }
    63 
    6450    public void setType(Type type) {
    6551        this.type = type;
    66     }
    67 
    68     public LocalDate getDateSent() {
    69         return dateSent;
    7052    }
    7153
  • src/main/java/com/example/skychasemk/repository/NotificationRepository.java

    rc064a42 r8a947b9  
    22
    33import com.example.skychasemk.model.Notification;
     4import com.example.skychasemk.model.Wishlist;
    45import org.springframework.data.jpa.repository.JpaRepository;
     6import org.springframework.data.jpa.repository.Query;
     7import org.springframework.data.repository.query.Param;
     8
     9import java.util.List;
     10
    511
    612public 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);
    815}
  • src/main/java/com/example/skychasemk/services/BookingService.java

    rc064a42 r8a947b9  
    33import com.example.skychasemk.model.Booking;
    44import com.example.skychasemk.repository.BookingRepository;
     5import jakarta.transaction.Transactional;
    56import org.springframework.beans.factory.annotation.Autowired;
    67import org.springframework.stereotype.Service;
  • src/main/java/com/example/skychasemk/services/NotificationService.java

    rc064a42 r8a947b9  
    1515    private NotificationRepository notificationRepository;
    1616
    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);
    2019    }
    2120
    22     // Get notification by ID
    23     public Optional<Notification> getNotificationById(Integer notificationID) {
    24         return notificationRepository.findById(notificationID);
    25     }
    26 
    27     // Save a new notification
    2821    public Notification saveNotification(Notification notification) {
    2922        return notificationRepository.save(notification);
    3023    }
    3124
    32     // Update an existing notification
    3325    public Notification updateNotification(Integer notificationID, Notification notification) {
    3426        if (notificationRepository.existsById(notificationID)) {
     
    4032    }
    4133
    42     // Delete notification
    4334    public void deleteNotification(Integer notificationID) {
    4435        notificationRepository.deleteById(notificationID);
Note: See TracChangeset for help on using the changeset viewer.