source: src/main/java/com/example/skychasemk/services/NotificationService.java@ 07fe0be

Last change on this file since 07fe0be was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package com.example.skychasemk.services;
2
3import com.example.skychasemk.model.Notification;
4import com.example.skychasemk.repository.NotificationRepository;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.stereotype.Service;
7
8import java.util.List;
9import java.util.Optional;
10
11@Service
12public class NotificationService {
13
14 @Autowired
15 private NotificationRepository notificationRepository;
16
17 // Get all notifications
18 public List<Notification> getAllNotifications() {
19 return notificationRepository.findAll();
20 }
21
22 // Get notification by ID
23 public Optional<Notification> getNotificationById(Integer notificationID) {
24 return notificationRepository.findById(notificationID);
25 }
26
27 // Save a new notification
28 public Notification saveNotification(Notification notification) {
29 return notificationRepository.save(notification);
30 }
31
32 // Update an existing notification
33 public Notification updateNotification(Integer notificationID, Notification notification) {
34 if (notificationRepository.existsById(notificationID)) {
35 notification.setNotificationID(notificationID);
36 return notificationRepository.save(notification);
37 } else {
38 throw new RuntimeException("Notification not found with id " + notificationID);
39 }
40 }
41
42 // Delete notification
43 public void deleteNotification(Integer notificationID) {
44 notificationRepository.deleteById(notificationID);
45 }
46}
47
Note: See TracBrowser for help on using the repository browser.