source: src/main/java/com/example/skychasemk/services/NotificationService.java@ 8a947b9

Last change on this file since 8a947b9 was 8a947b9, checked in by ste08 <sjovanoska@…>, 3 months ago

Notifications + triggers!

  • Property mode set to 100644
File size: 1.2 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 public List<Notification> getAllNotifications(Integer userId) {
18 return notificationRepository.findByUserId(userId);
19 }
20
21 public Notification saveNotification(Notification notification) {
22 return notificationRepository.save(notification);
23 }
24
25 public Notification updateNotification(Integer notificationID, Notification notification) {
26 if (notificationRepository.existsById(notificationID)) {
27 notification.setNotificationID(notificationID);
28 return notificationRepository.save(notification);
29 } else {
30 throw new RuntimeException("Notification not found with id " + notificationID);
31 }
32 }
33
34 public void deleteNotification(Integer notificationID) {
35 notificationRepository.deleteById(notificationID);
36 }
37}
38
Note: See TracBrowser for help on using the repository browser.