Changeset 8a947b9 for src


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
Files:
6 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);
  • src/main/resources/static/FlightSearch.html

    rc064a42 r8a947b9  
    1010    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
    1111    <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">
    1213    <style>
    1314        body {
     
    212213            color:white;
    213214        }
     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        }
    214269    </style>
    215270</head>
     
    223278        <button @click="goToReports">Monthly Report</button>
    224279        <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>
    225285    </header>
    226286
     
    291351        </div>
    292352    </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>
    293362</div>
    294363
     
    310379            issueDescription: '',
    311380            userId:'',
    312             wishlisted:false
     381            wishlisted:false,
     382            unreadNotifications: 0,
     383            notifications: [],
     384            notificationsVisible: false,
    313385        },
    314386        computed: {
     
    319391
    320392        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            },
    321407            async searchFlights() {
    322408                this.isContainerVisible = !this.isContainerVisible;
     
    455541                    console.error("Error fetching flights", error);
    456542                });
    457 
     543            this.fetchNotifications();
    458544        }
    459545    });
Note: See TracChangeset for help on using the changeset viewer.