1
|
package eu.dnetlib.uoanotificationservice.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
4
|
import eu.dnetlib.uoanotificationservice.entities.Notification;
|
5
|
import eu.dnetlib.uoanotificationservice.entities.User;
|
6
|
import eu.dnetlib.uoanotificationservice.services.NotificationService;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.security.access.prepost.PreAuthorize;
|
9
|
import org.springframework.web.bind.annotation.*;
|
10
|
|
11
|
import java.util.Date;
|
12
|
import java.util.List;
|
13
|
|
14
|
@RestController
|
15
|
@RequestMapping("/notification")
|
16
|
@CrossOrigin(origins = "*")
|
17
|
public class NotificationController {
|
18
|
|
19
|
@Autowired
|
20
|
private NotificationService notificationService;
|
21
|
|
22
|
@Autowired
|
23
|
private AuthorizationService authorizationService;
|
24
|
|
25
|
@PreAuthorize("hasAuthority(@AuthorizationService.REGISTERED_USER)")
|
26
|
@RequestMapping(value = {"/all"}, method = RequestMethod.GET)
|
27
|
public List<Notification> getAllNotifications() {
|
28
|
return notificationService.getAllNotifications();
|
29
|
}
|
30
|
|
31
|
@PreAuthorize("hasAuthority(@AuthorizationService.REGISTERED_USER)")
|
32
|
@RequestMapping(value = {"/{service}"}, method = RequestMethod.GET)
|
33
|
public List<Notification> getMyNotifications(@PathVariable String service) {
|
34
|
return notificationService.getMyNotifications(authorizationService.getAaiId(), service, authorizationService.getRoles());
|
35
|
}
|
36
|
|
37
|
@PreAuthorize("hasAuthority(@AuthorizationService.REGISTERED_USER)")
|
38
|
@RequestMapping(value = {"/save"}, method = RequestMethod.POST)
|
39
|
public Notification save(@RequestBody Notification notification) {
|
40
|
notification.setUser(authorizationService.getAaiId());
|
41
|
notification.setDate(new Date());
|
42
|
notification.setRead(false);
|
43
|
return notificationService.save(notification);
|
44
|
}
|
45
|
|
46
|
@PreAuthorize("hasAuthority(@AuthorizationService.REGISTERED_USER) && @Utils.canRead(#id)")
|
47
|
@RequestMapping(value = {"/{id}"}, method = RequestMethod.PUT)
|
48
|
public User readNotification(@PathVariable String id) {
|
49
|
return notificationService.readNotification(authorizationService.getAaiId(), id);
|
50
|
}
|
51
|
|
52
|
|
53
|
}
|
54
|
|