source: src/main/java/com/example/skychasemk/controller/NotificationController.java@ 57e58a3

Last change on this file since 57e58a3 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.controller;
2
3import com.example.skychasemk.model.Notification;
4import com.example.skychasemk.services.NotificationService;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.web.bind.annotation.*;
7
8import java.util.List;
9import java.util.Optional;
10
11@RestController
12@RequestMapping("/api/notifications")
13public class NotificationController {
14
15 @Autowired
16 private NotificationService notificationService;
17
18 // Get all notifications
19 @GetMapping
20 public List<Notification> getAllNotifications() {
21 return notificationService.getAllNotifications();
22 }
23
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
31 @PostMapping
32 public Notification createNotification(@RequestBody Notification notification) {
33 return notificationService.saveNotification(notification);
34 }
35
36 // Update an existing notification
37 @PutMapping("/{id}")
38 public Notification updateNotification(@PathVariable("id") Integer notificationID, @RequestBody Notification notification) {
39 return notificationService.updateNotification(notificationID, notification);
40 }
41
42 // Delete a notification
43 @DeleteMapping("/{id}")
44 public void deleteNotification(@PathVariable("id") Integer notificationID) {
45 notificationService.deleteNotification(notificationID);
46 }
47}
Note: See TracBrowser for help on using the repository browser.